public Tiled.Layer Map(LayerTilemap src, Tiled.Layer dst = null) { if (dst == null) { dst = new Tiled.Layer(); } dst.Name = src.Name; dst.Visible = src.Visible; dst.Properties[nameof(LayerTilemap.DefinitionId)] = src.DefinitionId; dst.Opacity = src.Opacity; dst.Properties[nameof(LayerTilemap.ProcessingMode)] = src.ProcessingMode; dst.Width = src.Width; dst.Height = src.Height; dst.Data = new uint[src.Width, src.Height]; for (int y = 0; y < src.Height; y++) { for (int x = 0; x < src.Width; x++) { var data = src.Tiles[x, y]; dst.Data[x, y] = (uint)( (data.Index & Tiled.Layer.INDEX_FLAG) | (data.IsFlippedX ? Tiled.Layer.FLIPPED_HORIZONTALLY_FLAG : 0) | (data.IsFlippedY ? Tiled.Layer.FLIPPED_VERTICALLY_FLAG : 0) ); } } dst.Encoding = "base64"; dst.Compression = "gzip"; return(dst); }
public LayerTilemap Map(Tiled.Layer src, LayerTilemap dst = null) { if (dst == null) { dst = new LayerTilemap(); } dst.Name = src.Name; dst.Visible = src.Visible; dst.Opacity = src.Opacity; dst.DefinitionId = GetPropertyValue(src.Properties, default(Guid), nameof(LayerTilemap.DefinitionId)); dst.ProcessingMode = GetPropertyValue(src.Properties, LayerProcessingMode.Tilemap, nameof(LayerTilemap.ProcessingMode)); dst.Tiles = new Tile[src.Data.GetLength(0), src.Data.GetLength(1)]; for (int y = 0; y < src.Height; y++) { for (int x = 0; x < src.Width; x++) { var data = src.Data[x, y]; dst.Tiles[x, y] = new Tile() { Tileset = 0, Index = (int)(data & Tiled.Layer.INDEX_FLAG), IsFlippedX = (data & Tiled.Layer.FLIPPED_HORIZONTALLY_FLAG) != 0, IsFlippedY = (data & Tiled.Layer.FLIPPED_VERTICALLY_FLAG) != 0 }; } } return(dst); }