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> _animatedTilesByTileset; public TiledMapModel(TiledMap map, Dictionary layersOfLayerModels) { _map = map; LayersOfLayerModels = layersOfLayerModels; _animatedTilesByTileset = _map.Tilesets .ToDictionary(i => i, i => i.Tiles.OfType() .ToList()); } public void Dispose() { foreach (var layerModel in LayersOfLayerModels) foreach (var model in layerModel.Value) model.Dispose(); } public ReadOnlyCollection Tilesets => _map.Tilesets; public ReadOnlyCollection Layers => _map.Layers; // each layer has many models public Dictionary LayersOfLayerModels { get; } public IEnumerable GetAnimatedTiles(int tilesetIndex) { var tileset = _map.Tilesets[tilesetIndex]; return _animatedTilesByTileset[tileset]; } } }