Пример #1
0
 private static void WriteMetaData(ContentWriter writer, TiledMapContent map)
 {
     writer.Write(map.Width);
     writer.Write(map.Height);
     writer.Write(map.TileWidth);
     writer.Write(map.TileHeight);
     writer.Write(ColorHelper.FromHex(map.BackgroundColor));
     writer.Write((byte)map.RenderOrder);
     writer.Write((byte)map.Orientation);
     writer.WriteTiledMapProperties(map.Properties);
 }
        private static void ProcessLayers(TiledMapContentItem contentItem, TiledMapContent map, ContentProcessorContext context, List <TiledMapLayerContent> layers)
        {
            foreach (var layer in layers)
            {
                switch (layer)
                {
                case TiledMapImageLayerContent imageLayer:
                    ContentLogger.Log($"Processing image layer '{imageLayer.Name}'");
                    //var externalReference = new ExternalReference<Texture2DContent>(imageLayer.Image.Source);
                    var parameters = new OpaqueDataDictionary
                    {
                        { "ColorKeyColor", imageLayer.Image.TransparentColor },
                        { "ColorKeyEnabled", true }
                    };
                    //imageLayer.Image.ContentRef = context.BuildAsset<Texture2DContent, Texture2DContent>(externalReference, "", parameters, "", "");
                    contentItem.BuildExternalReference <Texture2DContent>(context, imageLayer.Image.Source, parameters);
                    ContentLogger.Log($"Processed image layer '{imageLayer.Name}'");
                    break;

                case TiledMapTileLayerContent tileLayer when tileLayer.Data.Chunks.Count > 0:
                    throw new NotSupportedException($"{map.FilePath} contains data chunks. These are currently not supported.");

                case TiledMapTileLayerContent tileLayer:
                    var data            = tileLayer.Data;
                    var encodingType    = data.Encoding ?? "xml";
                    var compressionType = data.Compression ?? "xml";

                    ContentLogger.Log($"Processing tile layer '{tileLayer.Name}': Encoding: '{encodingType}', Compression: '{compressionType}'");
                    var tileData = DecodeTileLayerData(encodingType, tileLayer);
                    var tiles    = CreateTiles(map.RenderOrder, map.Width, map.Height, tileData);
                    tileLayer.Tiles = tiles;
                    ContentLogger.Log($"Processed tile layer '{tileLayer}': {tiles.Length} tiles");
                    break;

                case TiledMapObjectLayerContent objectLayer:
                    ContentLogger.Log($"Processing object layer '{objectLayer.Name}'");

                    foreach (var obj in objectLayer.Objects)
                    {
                        TiledMapContentHelper.Process(obj, context);
                    }

                    ContentLogger.Log($"Processed object layer '{objectLayer.Name}'");
                    break;

                case TiledMapGroupLayerContent groupLayer:
                    ProcessLayers(contentItem, map, context, groupLayer.Layers);
                    break;
                }
            }
        }