Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using MonoGame.Extended.Graphics;
- using MonoGame.Extended.Tiled;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace MonoGame.Extended
- {
- public class TiledMapCombiner
- {
- private TiledMap _mapOne;
- private TiledMap _mapTwo;
- public TiledMapCombiner(TiledMap mapOne, TiledMap mapTwo)
- {
- _mapOne = mapOne;
- _mapTwo = mapTwo;
- }
- public TiledMap Combine()
- {
- var reference = _mapOne;
- var currentMap = ReadMetaData(reference);
- ReadTilesets(reference, currentMap);
- ReadLayers(reference, currentMap);
- return currentMap;
- }
- private TiledMap ReadMetaData(TiledMap reference)
- {
- var name = reference.Name;
- var width = _mapOne.Width + _mapTwo.Width;
- var height = _mapOne.Height + _mapTwo.Height;
- var tileWidth = reference.TileWidth;
- var tileHeight = reference.TileHeight;
- var backgroundColor = reference.BackgroundColor;
- var renderOrder = reference.RenderOrder;
- var orientation = reference.Orientation;
- var map = new TiledMap(name, width, height, tileWidth, tileHeight, renderOrder, orientation)
- {
- BackgroundColor = backgroundColor
- };
- return map;
- }
- private void ReadTilesets(TiledMap reference, TiledMap map)
- {
- for (var i = 0; i < reference.Tilesets.Count; i++)
- {
- map.AddTileset(reference.Tilesets[i]);
- }
- }
- private void ReadLayers(TiledMap reference, TiledMap map)
- {
- for (var i = 0; i < _mapOne.Layers.Count; i++)
- {
- var lone = (TiledMapTileLayer)_mapOne.Layers[i];
- var ltwo = (TiledMapTileLayer)_mapTwo.Layers[i];
- var tilesOne = lone.Tiles;
- var tilesTwo = ltwo.Tiles;
- var tiles = new List<TiledMapTile>(tilesOne);
- foreach (var tile in tilesTwo)
- {
- var x = (ushort)(tile.X + _mapOne.Width);
- var y = tile.Y;
- var newTile = new TiledMapTile(tile.GlobalTileIdentifierWithFlags, x, y);
- tiles.Add(newTile);
- }
- var width = lone.Width + ltwo.Width;
- var height = lone.Height + ltwo.Height;
- var layer = new TiledMapTileLayer(map, lone.Name, lone.IsVisible, lone.Opacity, 0, 0, width, height, tiles);
- ReadModels(lone, ltwo, layer, map);
- map.AddLayer(layer);
- }
- }
- private void ReadModels(TiledMapLayer layerOne, TiledMapLayer layerTwo, TiledMapLayer layer, TiledMap map)
- {
- /*
- * Stuck here
- *
- var modelCount = layerOne.Models.Count() + layerTwo.Models.Count();
- var animatedModelCount = layerOne.AnimatedModels.Count() + layerTwo.AnimatedModels.Count();
- var models = layer.Models = new TiledMapLayerModel[modelCount];
- var animatedModels = layer.AnimatedModels = new TiledMapLayerAnimatedModel[animatedModelCount];
- var animatedModelIndex = 0;
- for (var modelIndex = 0; modelIndex < modelCount; modelIndex++)
- {
- var isAnimated = input.ReadBoolean();
- var model = isAnimated ? new TiledMapLayerAnimatedModel(input, map) : new TiledMapLayerModel(input);
- models[modelIndex] = model;
- if (isAnimated)
- animatedModels[animatedModelIndex++] = (TiledMapLayerAnimatedModel)model;
- }
- */
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement