Example #1
0
        private static TileSetNode ParseTileSetNode(XmlReader reader)
        {
            TileSetNode tileSet = new TileSetNode();

            if (reader.HasAttributes)
            {
                while (reader.MoveToNextAttribute())
                {
                    switch (reader.Name)
                    {
                    case "firstguid": tileSet.FirstGuid = reader.Value; break;

                    case "source": tileSet.Source = reader.Value; break;

                    case "name": tileSet.Name = reader.Value; break;

                    case "tilewidth": tileSet.TileWidth = reader.ReadContentAsInt(); break;

                    case "tileheight": tileSet.TileHeight = reader.ReadContentAsInt(); break;

                    case "spacing": tileSet.Spacing = reader.ReadContentAsInt(); break;

                    case "margin": tileSet.Margin = reader.ReadContentAsInt(); break;

                    case "tilecount": tileSet.TileCount = reader.ReadContentAsInt(); break;

                    case "columns": tileSet.Columns = reader.ReadContentAsInt(); break;
                    }
                }

                reader.MoveToElement();
            }

            XmlReader inner = reader.ReadSubtree();

            tileSet.Tiles = new List <TileNode>();

            while (inner.Read())
            {
                switch (inner.Name)
                {
                case "tileoffset": tileSet.TileOffset = ParseNode(inner) as TileOffsetNode; break;

                case "properties": tileSet.Properties = ParseNode(inner) as PropertiesNode; break;

                case "image": tileSet.Image = ParseNode(inner) as ImageNode; break;

                case "terraintypes": tileSet.TerrainTypes = ParseNode(inner) as TerrainTypesNode; break;

                case "tile": tileSet.Tiles.Add(ParseNode(inner) as TileNode); break;
                }
            }

            inner.Close();

            return(tileSet);
        }
Example #2
0
        public static TileSetNode ParseTileset(string filePath)
        {
            TileSetNode result = null;

            using (XmlReader reader = XmlReader.Create(filePath))
            {
                result = ParseTileSet(reader);
            }

            return(result);
        }
Example #3
0
        public static TileSetNode ParseTileSet(XmlReader reader)
        {
            TileSetNode result = null;

            if (reader.ReadToFollowing("tileset"))
            {
                result = ParseNode(reader) as TileSetNode;
            }

            return(result);
        }