Example #1
0
        public MapXml(XmlDocument document)
        {
            tilesets = new List<Tileset>();
            properties = new Dictionary<String, String>();

            XmlNode mapNode = document ["map"];

            width = int.Parse(mapNode.Attributes ["width"].Value);
            height = int.Parse(mapNode.Attributes ["height"].Value);
            tileWidth = int.Parse(mapNode.Attributes ["tilewidth"].Value);
            tileHeight = int.Parse(mapNode.Attributes ["tileheight"].Value);

            Debug.Log(title);

            layers = new List<Layer>();
            objectGroups = new List<ObjectGroup>();

            XmlNode propertiesNode = mapNode.SelectSingleNode("properties");
            if (propertiesNode != null) {
                XmlNodeList propertyNodes = propertiesNode.SelectNodes("property");
                if (propertyNodes != null) {
                    foreach (XmlNode node in propertyNodes) {
                        String name = node.Attributes["name"].Value;
                        String value = node.Attributes["value"].Value;

                        properties.Add(name, value);
                    }
                }
            }

            XmlNodeList tilesetNodes = mapNode.SelectNodes("tileset");

            foreach (XmlNode tilesetNode in tilesetNodes) {
                Tileset tileset = new Tileset(tilesetNode);
                tilesets.Add(tileset);
            }

            XmlNodeList layerNodes = mapNode.SelectNodes("layer");
            foreach (XmlNode layerNode in layerNodes) {
                Layer layer = new Layer(layerNode);
                layers.Add (layer);
            }

            XmlNodeList objectGroupNodes = mapNode.SelectNodes ("objectgroup");
            foreach (XmlNode objectGroupNode in objectGroupNodes) {
                ObjectGroup objectGroup = new ObjectGroup(objectGroupNode);
                objectGroups.Add(objectGroup);
            }
        }