public CellInformation(Tile tile, LevelCell cell) { this.Tile = tile; this.Cell = cell; }
/// <summary> /// Loads the tileset from the game resources. /// </summary> /// <param name="contentManager">The content manager to use.</param> /// <param name="name">The relative filename of the XML file describing the tileset.</param> public void Load(ContentManager contentManager, String name) { if (contentManager == null) throw new ArgumentNullException("contentManager"); if (String.IsNullOrEmpty(name)) throw new ArgumentNullException("name"); String path = Path.Combine(contentManager.RootDirectory, name); if (!File.Exists(path)) throw new FileNotFoundException(null, path); this.tiles = new TileCollection(); XmlDocument doc = new XmlDocument(); doc.Load(path); XmlElement rootElement = doc.DocumentElement; this.name = rootElement.GetAttribute("Name"); this.resource = rootElement.GetAttribute("Resource"); foreach (XmlNode childNode in rootElement.ChildNodes) { if (childNode.NodeType != XmlNodeType.Element) continue; XmlElement childElement = (XmlElement)childNode; if(childElement.Name.Equals("Tile")) { Tile t = new Tile( childElement.InnerText, Convert.ToBoolean(childElement.GetAttribute("Passable"))); t.Frames.Enqueue(Convert.ToUInt32(childElement.GetAttribute("ID"))); // :: Add the tile to the index. this.tiles.Add(t.Name, t); } else if (childElement.Name.Equals("AnimatedTile")) { Tile t = new Tile( childElement.GetAttribute("Name"), Convert.ToBoolean(childElement.GetAttribute("Passable")), true); t.Speed = Convert.ToSingle(childElement.GetAttribute("Speed")); foreach (XmlNode frameNode in childElement.ChildNodes) { if (frameNode.NodeType != XmlNodeType.Element) continue; XmlElement frameElement = (XmlElement)frameNode; if (frameElement.Name.Equals("Frame")) { t.Frames.Enqueue( Convert.ToUInt32(frameElement.GetAttribute("ID"))); } } // :: Add the animated tile to the index. this.tiles.Add(t.Name, t); } } // :: We can only initialise the tileset once. if (this.initialised) throw new InvalidOperationException("Tileset is already initialised."); // :: Load the texture tileset texture. this.texture = contentManager.Load<Texture2D>(this.resource); this.initialised = true; }