Esempio n. 1
0
        private static Tileset ReadTileset(XmlReader reader, Tileset result)
        {
            result.Name       = reader.GetAttribute("name");
            result.TileWidth  = int.Parse(reader.GetAttribute("tilewidth"));
            result.TileHeight = int.Parse(reader.GetAttribute("tileheight"));

            int currentTileId = -1;

            while (reader.Read())
            {
                var name = reader.Name;

                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    switch (name)
                    {
                    case "image":
                        result.Image = reader.GetAttribute("source");
                        break;

                    case "tile":
                        currentTileId = int.Parse(reader.GetAttribute("id"));
                        break;

                    case "property": {
                        TilePropertyList props;
                        if (!result.TileProperties.TryGetValue(currentTileId, out props))
                        {
                            props = new TilePropertyList();
                            result.TileProperties[currentTileId] = props;
                        }

                        props[reader.GetAttribute("name")] = reader.GetAttribute("value");
                    } break;
                    }

                    break;

                case XmlNodeType.EndElement:
                    break;
                }
            }

            return(result);
        }