/// <summary>
        /// Add a new tile to the section
        /// </summary>
        /// <param name="tile"></param>
        public void AddTile(MapTile tile)
        {
            // compute coordinates of tile within the section
            CoordXZ localTileCoord = tile.TileCoord - tileCoord;

            if (tiles[localTileCoord.x, localTileCoord.z] == null)
            {
                tiles[localTileCoord.x, localTileCoord.z] = tile;
            }
            else
            {
                throw new ArgumentException("AddTile: tile already exists at given coordinate");
            }

            if (tile.Dirty)
            {
                dirtyChildren = true;
            }
        }
Exemple #2
0
 public void AddTile(MapTile tile)
 {
     tiles.Add(tile.TileCoord);
     //tile.Zone = this;
 }
 protected void OnNewTile(MapTile tile)
 {
     NewTileHandler handler = NewTile;
     if (handler != null)
     {
         handler(tile);
     }
 }
        protected void ParseTile(XmlReader r, string zoneName)
        {
            int x = 0;
            int z = 0;

            // parse attributes
            for (int i = 0; i < r.AttributeCount; i++)
            {
                r.MoveToAttribute(i);

                // set the field in this object based on the element we just read
                switch (r.Name)
                {
                    case "X":
                        x = int.Parse(r.Value);
                        break;
                    case "Z":
                        z = int.Parse(r.Value);
                        break;
                }
            }

            // create the tile
            MapTile tile = new MapTile(map, new CoordXZ(x, z, WorldMap.tileSize));

            // add the zone to the tile
            tile.Zone = map.GetZone(zoneName);

            // add the tile to the section
            AddTile(tile);

            r.MoveToElement(); //Moves the reader back to the element node.

            if (!r.IsEmptyElement)
            {
                // now parse the sub-elements
                while (r.Read())
                {
                    // look for the start of an element
                    if (r.NodeType == XmlNodeType.Element)
                    {
                        // parse that element
                        // save the name of the element
                        string elementName = r.Name;
                        switch (elementName)
                        {
                            case "Property":
                                tile.Properties.ParseProperty(r);
                                break;
                        }
                    }
                    else if (r.NodeType == XmlNodeType.EndElement)
                    {
                        break;
                    }
                }
            }
        }
        public MapTile CreateTile(CoordXZ tileCoord)
        {
            MapTile tile = new MapTile(this, tileCoord);

            MapSection section = GetSection(tileCoord);

            section.AddTile(tile);

            OnNewTile(tile);

            return tile;
        }