Exemple #1
0
        public Tileset(ContentManager content, string tilesetFilePath)
        {
            var tilesetData = TilesetData.ReadFromXml(tilesetFilePath);

            Templates          = new Dictionary <BlockType, BlockTemplate>();
            TileSetTextureName = tilesetData.Texture;
            TileSetTexture     = content.Load <Texture2D>(TileSetTextureName);

            foreach (TemplateData templateData in tilesetData.Templates)
            {
                Templates[templateData.BlockType] = CreateTemplateFromDataObject(templateData);
            }
        }
Exemple #2
0
        public static TilesetData ReadFromXml(string filePath)
        {
            var tilesetData = new TilesetData();
            var xmlDocument = new XmlDocument();

            xmlDocument.Load(filePath);

// ReSharper disable PossibleNullReferenceException
            tilesetData.Texture = xmlDocument.DocumentElement.SelectSingleNode("Texture").InnerXml;

            tilesetData.Templates = new List <TemplateData>();

            foreach (XmlElement itemElement in xmlDocument.DocumentElement.SelectNodes("Templates/Item"))
            {
                tilesetData.Templates.Add(new TemplateData
                {
                    BlockType       = (BlockType)Enum.Parse(typeof(BlockType), itemElement.SelectSingleNode("BlockType").InnerXml),
                    SourceRectangle = ParseRectangle(itemElement.SelectSingleNode("SourceRectangle").InnerXml)
                });
            }
// ReSharper restore PossibleNullReferenceException

            return(tilesetData);
        }