Files
MonoGame.Extended/Source/MonoGame.Extended.Tiled/Renderers/TiledMapModel.cs
T
stefanrbkandDylan Wilson 433e458af0 Real Tiled Group Support (#522)
* Change from storing layers by index to Dictionary key

Models are now stored with the `TiledMapLayer` they are part of.

* Allow render calls via TiledMapLayer

* Add TiledMapGroupLayer and model build recursion for groups

* Add rendering support for TiledMapGroupLayer

* Update TiledMapReader to read TiledMapGroupLayers

* Update Features Demo to Include a Map with a Layer Group

* Update TiledMapWriter and TiledMapProcessor to Support Groups

* Update TiledMap to Report Layers Correctly
2018-07-08 21:34:07 +10:00

41 lines
1.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
namespace MonoGame.Extended.Tiled.Renderers
{
public class TiledMapModel : IDisposable
{
private readonly TiledMap _map;
private readonly Dictionary<TiledMapTileset, List<TiledMapTilesetAnimatedTile>> _animatedTilesByTileset;
public TiledMapModel(TiledMap map, Dictionary<TiledMapLayer, TiledMapLayerModel[]> layersOfLayerModels)
{
_map = map;
LayersOfLayerModels = layersOfLayerModels;
_animatedTilesByTileset = _map.Tilesets
.ToDictionary(i => i, i => i.Tiles.OfType<TiledMapTilesetAnimatedTile>()
.ToList());
}
public void Dispose()
{
foreach (var layerModel in LayersOfLayerModels)
foreach (var model in layerModel.Value)
model.Dispose();
}
public ReadOnlyCollection<TiledMapTileset> Tilesets => _map.Tilesets;
public ReadOnlyCollection<TiledMapLayer> Layers => _map.Layers;
// each layer has many models
public Dictionary<TiledMapLayer, TiledMapLayerModel[]> LayersOfLayerModels { get; }
public IEnumerable<TiledMapTilesetAnimatedTile> GetAnimatedTiles(int tilesetIndex)
{
var tileset = _map.Tilesets[tilesetIndex];
return _animatedTilesByTileset[tileset];
}
}
}