public void ParseTileset(XmlNode tilesetNode) { XmlAttributeCollection attributes = tilesetNode.Attributes; string firstGid = attributes.GetNamedItem("firstgid").Value; string tileCount = attributes.GetNamedItem("tilecount").Value; bool isCollection = tilesetNode.FirstChild.Name == "tile"; TileSet newTileSet = new TileSet(attributes.GetNamedItem("name").Value, Convert.ToInt32(firstGid), Convert.ToInt32(tileCount), isCollection); if (!isCollection) { String imageFilename = tilesetNode.FirstChild.Attributes["source"].Value; imageFilename = imageFilename.Substring(3, imageFilename.Length - 7); Texture2D image = _content.Load <Texture2D>(imageFilename); newTileSet.SetImage(image); foreach (XmlNode tileNode in tilesetNode.ChildNodes) { if (tileNode.Name == "tile") { int tileTypeId = Convert.ToInt32(tileNode.Attributes["id"].Value); TileType newTileType = new TileType(tileTypeId, TileTerrain.Passable); foreach (XmlNode tileChildNode in tileNode.ChildNodes) { if (tileChildNode.Name == "properties") { foreach (XmlNode propertyNode in tileChildNode.ChildNodes) { if (propertyNode.Attributes["name"].Value == "Collision") { TileTerrain newTerrain = TileTerrain.Passable; if (propertyNode.Attributes["value"].Value == "Blocked") { newTerrain = TileTerrain.Blocked; } else if (propertyNode.Attributes["value"].Value == "Water") { newTerrain = TileTerrain.Water; } newTileType.Terrain = newTerrain; } } } } newTileSet.AddTileType(newTileType); } } } else { foreach (XmlNode tileNode in tilesetNode.ChildNodes) { int tileTypeId = Convert.ToInt32(tileNode.Attributes["id"].Value); TileType newTileType = new TileType(tileTypeId, TileTerrain.Passable); foreach (XmlNode tileChildNode in tileNode.ChildNodes) { if (tileChildNode.Name == "image") { String imageFilename = tileChildNode.Attributes["source"].Value; imageFilename = imageFilename.Substring(3, imageFilename.Length - 7); newTileType.SetTexture(_content.Load <Texture2D>(imageFilename)); } else if (tileChildNode.Name == "properties") { foreach (XmlNode propertyNode in tileChildNode.ChildNodes) { if (propertyNode.Attributes["name"].Value == "Collision") { TileTerrain newTerrain = TileTerrain.Passable; if (propertyNode.Attributes["value"].Value == "Blocked") { newTerrain = TileTerrain.Blocked; } else if (propertyNode.Attributes["value"].Value == "Water") { newTerrain = TileTerrain.Water; } newTileType.Terrain = newTerrain; } } } } newTileSet.AddTileType(newTileType); } } _map.TileSetMgr.AddTileSet(newTileSet); }
public void AddTileSet(TileSet tileSet) { _tileSets.Add(tileSet); }