Esempio n. 1
0
 /// <summary>
 /// Clones this instance.
 /// </summary>
 /// <returns></returns>
 public Layer Clone()
 {
     Layer newLayer = new Layer();
     newLayer.SetTileGrid(Tiles);
     newLayer.ParentMap = parentMap;
     return newLayer;
 }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Tile"/> class.
 /// </summary>
 /// <param name="X">The X tile-coordinate of this tile.</param>
 /// <param name="Y">The Y tile-coordinate of this tile.</param>
 /// <param name="ParentLayer">The parent layer this tile belongs to.</param>
 public Tile(int X, int Y, Layer ParentLayer)
 {
     this.x = X;
     this.y = Y;
     this.parentLayer = ParentLayer;
 }
Esempio n. 3
0
        private void LoadLayer(XmlReader reader)
        {
            // We are now at the <layer> node.
            // Read the attribute(s) 'name'.
            // TODO: Should we make the name a #? Like the layer name is '1', and that indicates the draw order.
            string layerName = reader["name"];
            XmlReader layerDataReader = reader.ReadSubtree();
            layerDataReader.ReadToFollowing("data");
            // We are now at the <data> node.
            #region TODO: Handle XML, Base64, GZIP, and ZLib Compression
            /*
            var encoding = layerDataReader.GetAttribute("encoding");
            var compressor = reader.GetAttribute("compression");
            switch (encoding)
            {
                case "base64":
                    {
                        int dataSize = (TileDimensions * TileDimensions * 4) + 1024;
                        var buffer = new byte[dataSize];
                        reader.ReadElementContentAsBase64(buffer, 0, dataSize);

                        Stream stream = new MemoryStream(buffer, false);
                        if (compressor == "gzip")
                            stream = new GZipStream(stream, CompressionMode.Decompress, false);

                        using (stream)
                        using (var br = new BinaryReader(stream))
                        {
                            for (int i = 0; i < tileArray.Length; i++)
                                tileArray[i] = br.ReadInt32();
                        }

                        continue;
                    };

                default:
                    throw new Exception("Your map layer, called '" + name + "' is encoded with an unrecognized compression algorithm. The accepted values are XML, Base64, and GZIP. Don't use ZLib!");
            }*/
            #endregion
            XmlReader layerDataTileReader = layerDataReader.ReadSubtree();
            // We are now at the <tile> node. There are a lot of these...

            TileGrid layerTiles = new TileGrid(Width, Height, true);
            Layer layer = new Layer();
            layer.Name = layerName;

            int lineReadIndex = 0; // the # of lines read by the parser

            while (layerDataTileReader.ReadToFollowing("tile"))
            {
                int tilegid = int.Parse(layerDataTileReader["gid"]);

                layerTiles[lineReadIndex % Width, lineReadIndex / Width].Id = tilegid;
                layerTiles[lineReadIndex % Width, lineReadIndex / Width].ParentLayer = layer;

                lineReadIndex++;
            }

            layer.Tiles = layerTiles;
            layer.ParentMap = (Map)this;

            Layers.Add(layer);
        }