mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-15 15:09:29 +00:00
Merge pull request #818 from KatDevsGames/pipeline-update-map-layer-tilemap-class
support type/class field in maps, layers, & tilemaps
This commit is contained in:
@@ -32,7 +32,7 @@ namespace MonoGame.Extended.Content.Pipeline.Tiled
|
||||
{
|
||||
var externalReference = externalReferenceRepository.GetExternalReference<Texture2DContent>(tileset.Image?.Source);
|
||||
writer.WriteExternalReference(externalReference);
|
||||
|
||||
writer.Write(tileset.Class ?? tileset.Type ?? string.Empty);
|
||||
writer.Write(tileset.TileWidth);
|
||||
writer.Write(tileset.TileHeight);
|
||||
writer.Write(tileset.TileCount);
|
||||
|
||||
@@ -36,6 +36,7 @@ namespace MonoGame.Extended.Content.Pipeline.Tiled
|
||||
|
||||
private static void WriteMetaData(ContentWriter writer, TiledMapContent map)
|
||||
{
|
||||
writer.Write(map.Class ?? map.Type ?? string.Empty);
|
||||
writer.Write(map.Width);
|
||||
writer.Write(map.Height);
|
||||
writer.Write(map.TileWidth);
|
||||
@@ -80,9 +81,10 @@ namespace MonoGame.Extended.Content.Pipeline.Tiled
|
||||
|
||||
private void WriteLayer(ContentWriter writer, TiledMapLayerContent layer)
|
||||
{
|
||||
writer.Write((byte)layer.Type);
|
||||
writer.Write((byte)layer.LayerType);
|
||||
|
||||
writer.Write(layer.Name ?? string.Empty);
|
||||
writer.Write(layer.Class ?? layer.Type ?? string.Empty);
|
||||
writer.Write(layer.Visible);
|
||||
writer.Write(layer.Opacity);
|
||||
writer.Write(layer.OffsetX);
|
||||
@@ -92,7 +94,7 @@ namespace MonoGame.Extended.Content.Pipeline.Tiled
|
||||
|
||||
writer.WriteTiledMapProperties(layer.Properties);
|
||||
|
||||
switch (layer.Type)
|
||||
switch (layer.LayerType)
|
||||
{
|
||||
case TiledMapLayerType.ImageLayer:
|
||||
WriteImageLayer(writer, (TiledMapImageLayerContent)layer);
|
||||
@@ -107,7 +109,7 @@ namespace MonoGame.Extended.Content.Pipeline.Tiled
|
||||
WriteLayers(writer, ((TiledMapGroupLayerContent)layer).Layers);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(layer.Type));
|
||||
throw new ArgumentOutOfRangeException(nameof(layer.LayerType));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,13 @@ namespace MonoGame.Extended.Tiled.Serialization
|
||||
[XmlIgnore]
|
||||
public string FilePath { get; set; }
|
||||
|
||||
// Deprecated as of Tiled 1.9.0 (replaced by "class" attribute)
|
||||
[XmlAttribute(DataType = "string", AttributeName = "type")]
|
||||
public string Type { get; set; }
|
||||
|
||||
[XmlAttribute(DataType = "string", AttributeName = "class")]
|
||||
public string Class { get; set; }
|
||||
|
||||
[XmlAttribute(AttributeName = "version")]
|
||||
public string Version { get; set; }
|
||||
|
||||
@@ -65,4 +72,4 @@ namespace MonoGame.Extended.Tiled.Serialization
|
||||
[XmlArrayItem("property")]
|
||||
public List<TiledMapPropertyContent> Properties { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@ namespace MonoGame.Extended.Tiled.Serialization
|
||||
[XmlInclude(typeof(TiledMapObjectLayerContent))]
|
||||
public abstract class TiledMapLayerContent
|
||||
{
|
||||
protected TiledMapLayerContent(TiledMapLayerType type)
|
||||
protected TiledMapLayerContent(TiledMapLayerType layerType)
|
||||
{
|
||||
Type = type;
|
||||
LayerType = layerType;
|
||||
Opacity = 1.0f;
|
||||
ParallaxX = 1.0f;
|
||||
ParallaxY = 1.0f;
|
||||
@@ -21,6 +21,13 @@ namespace MonoGame.Extended.Tiled.Serialization
|
||||
[XmlAttribute(AttributeName = "name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
// Deprecated as of Tiled 1.9.0 (replaced by "class" attribute)
|
||||
[XmlAttribute(DataType = "string", AttributeName = "type")]
|
||||
public string Type { get; set; }
|
||||
|
||||
[XmlAttribute(DataType = "string", AttributeName = "class")]
|
||||
public string Class { get; set; }
|
||||
|
||||
[XmlAttribute(AttributeName = "opacity")]
|
||||
public float Opacity { get; set; }
|
||||
|
||||
@@ -44,7 +51,7 @@ namespace MonoGame.Extended.Tiled.Serialization
|
||||
public List<TiledMapPropertyContent> Properties { get; set; }
|
||||
|
||||
[XmlIgnore]
|
||||
public TiledMapLayerType Type { get; }
|
||||
public TiledMapLayerType LayerType { get; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
|
||||
@@ -22,6 +22,13 @@ namespace MonoGame.Extended.Tiled.Serialization
|
||||
[XmlAttribute(AttributeName = "name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
// Deprecated as of Tiled 1.9.0 (replaced by "class" attribute)
|
||||
[XmlAttribute(DataType = "string", AttributeName = "type")]
|
||||
public string Type { get; set; }
|
||||
|
||||
[XmlAttribute(DataType = "string", AttributeName = "class")]
|
||||
public string Class { get; set; }
|
||||
|
||||
[XmlAttribute(AttributeName = "tilewidth")]
|
||||
public int TileWidth { get; set; }
|
||||
|
||||
@@ -66,4 +73,4 @@ namespace MonoGame.Extended.Tiled.Serialization
|
||||
return $"{Name}: {Image}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace MonoGame.Extended.Tiled
|
||||
private readonly List<Tuple<TiledMapTileset, int>> _firstGlobalIdentifiers = new List<Tuple<TiledMapTileset, int>>();
|
||||
|
||||
public string Name { get; }
|
||||
public string Type { get; }
|
||||
public int Width { get; }
|
||||
public int Height { get; }
|
||||
public int TileWidth { get; }
|
||||
@@ -44,10 +45,11 @@ namespace MonoGame.Extended.Tiled
|
||||
Properties = new TiledMapProperties();
|
||||
}
|
||||
|
||||
public TiledMap(string name, int width, int height, int tileWidth, int tileHeight, TiledMapTileDrawOrder renderOrder, TiledMapOrientation orientation, Color? backgroundColor = null)
|
||||
public TiledMap(string name, string type, int width, int height, int tileWidth, int tileHeight, TiledMapTileDrawOrder renderOrder, TiledMapOrientation orientation, Color? backgroundColor = null)
|
||||
: this()
|
||||
{
|
||||
Name = name;
|
||||
Type = type;
|
||||
Width = width;
|
||||
Height = height;
|
||||
TileWidth = tileWidth;
|
||||
|
||||
@@ -8,8 +8,8 @@ namespace MonoGame.Extended.Tiled
|
||||
public class TiledMapGroupLayer : TiledMapLayer
|
||||
{
|
||||
public List<TiledMapLayer> Layers { get; }
|
||||
public TiledMapGroupLayer(string name, List<TiledMapLayer> layers, Vector2? offset = null, Vector2? parallaxFactor = null, float opacity = 1, bool isVisible = true)
|
||||
: base(name, offset, parallaxFactor, opacity, isVisible)
|
||||
public TiledMapGroupLayer(string name, string type, List<TiledMapLayer> layers, Vector2? offset = null, Vector2? parallaxFactor = null, float opacity = 1, bool isVisible = true)
|
||||
: base(name, type, offset, parallaxFactor, opacity, isVisible)
|
||||
{
|
||||
Layers = layers;
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ namespace MonoGame.Extended.Tiled
|
||||
{
|
||||
public class TiledMapImageLayer : TiledMapLayer, IMovable
|
||||
{
|
||||
public TiledMapImageLayer(string name, Texture2D image, Vector2? position = null, Vector2? offset = null, Vector2? parallaxFactor = null, float opacity = 1.0f, bool isVisible = true)
|
||||
: base(name, offset, parallaxFactor, opacity, isVisible)
|
||||
public TiledMapImageLayer(string name, string type, Texture2D image, Vector2? position = null, Vector2? offset = null, Vector2? parallaxFactor = null, float opacity = 1.0f, bool isVisible = true)
|
||||
: base(name, type, offset, parallaxFactor, opacity, isVisible)
|
||||
{
|
||||
Image = image;
|
||||
Position = position ?? Vector2.Zero;
|
||||
|
||||
@@ -5,15 +5,17 @@ namespace MonoGame.Extended.Tiled
|
||||
public abstract class TiledMapLayer
|
||||
{
|
||||
public string Name { get; }
|
||||
public string Type { get; }
|
||||
public bool IsVisible { get; set; }
|
||||
public float Opacity { get; set; }
|
||||
public Vector2 Offset { get; set; }
|
||||
public Vector2 ParallaxFactor { get; set; }
|
||||
public TiledMapProperties Properties { get; }
|
||||
|
||||
protected TiledMapLayer(string name, Vector2? offset = null, Vector2? parallaxFactor = null, float opacity = 1.0f, bool isVisible = true)
|
||||
protected TiledMapLayer(string name, string type, Vector2? offset = null, Vector2? parallaxFactor = null, float opacity = 1.0f, bool isVisible = true)
|
||||
{
|
||||
Name = name;
|
||||
Type = type;
|
||||
Offset = offset ?? Vector2.Zero;
|
||||
ParallaxFactor = parallaxFactor ?? Vector2.One;
|
||||
Opacity = opacity;
|
||||
|
||||
@@ -4,9 +4,9 @@ namespace MonoGame.Extended.Tiled
|
||||
{
|
||||
public class TiledMapObjectLayer : TiledMapLayer
|
||||
{
|
||||
public TiledMapObjectLayer(string name, TiledMapObject[] objects, Color? color = null, TiledMapObjectDrawOrder drawOrder = TiledMapObjectDrawOrder.TopDown,
|
||||
public TiledMapObjectLayer(string name, string type, TiledMapObject[] objects, Color? color = null, TiledMapObjectDrawOrder drawOrder = TiledMapObjectDrawOrder.TopDown,
|
||||
Vector2? offset = null, Vector2? parallaxFactor = null, float opacity = 1.0f, bool isVisible = true)
|
||||
: base(name, offset, parallaxFactor, opacity, isVisible)
|
||||
: base(name, type, offset, parallaxFactor, opacity, isVisible)
|
||||
{
|
||||
Color = color;
|
||||
DrawOrder = drawOrder;
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace MonoGame.Extended.Tiled
|
||||
private static TiledMap ReadTiledMap(ContentReader reader)
|
||||
{
|
||||
var name = reader.AssetName;
|
||||
var type = reader.ReadString();
|
||||
var width = reader.ReadInt32();
|
||||
var height = reader.ReadInt32();
|
||||
var tileWidth = reader.ReadInt32();
|
||||
@@ -33,7 +34,7 @@ namespace MonoGame.Extended.Tiled
|
||||
var renderOrder = (TiledMapTileDrawOrder)reader.ReadByte();
|
||||
var orientation = (TiledMapOrientation)reader.ReadByte();
|
||||
|
||||
return new TiledMap(name, width, height, tileWidth, tileHeight, renderOrder, orientation, backgroundColor);
|
||||
return new TiledMap(name, type, width, height, tileWidth, tileHeight, renderOrder, orientation, backgroundColor);
|
||||
}
|
||||
|
||||
private static void ReadTilesets(ContentReader reader, TiledMap map)
|
||||
@@ -76,6 +77,7 @@ namespace MonoGame.Extended.Tiled
|
||||
{
|
||||
var layerType = (TiledMapLayerType)reader.ReadByte();
|
||||
var name = reader.ReadString();
|
||||
var type = reader.ReadString();
|
||||
var isVisible = reader.ReadBoolean();
|
||||
var opacity = reader.ReadSingle();
|
||||
var offsetX = reader.ReadSingle();
|
||||
@@ -93,16 +95,16 @@ namespace MonoGame.Extended.Tiled
|
||||
switch (layerType)
|
||||
{
|
||||
case TiledMapLayerType.ImageLayer:
|
||||
layer = ReadImageLayer(reader, name, offset, parallaxFactor, opacity, isVisible);
|
||||
layer = ReadImageLayer(reader, name, type, offset, parallaxFactor, opacity, isVisible);
|
||||
break;
|
||||
case TiledMapLayerType.TileLayer:
|
||||
layer = ReadTileLayer(reader, name, offset, parallaxFactor, opacity, isVisible, map);
|
||||
layer = ReadTileLayer(reader, name, type, offset, parallaxFactor, opacity, isVisible, map);
|
||||
break;
|
||||
case TiledMapLayerType.ObjectLayer:
|
||||
layer = ReadObjectLayer(reader, name, offset, parallaxFactor, opacity, isVisible, map);
|
||||
layer = ReadObjectLayer(reader, name, type, offset, parallaxFactor, opacity, isVisible, map);
|
||||
break;
|
||||
case TiledMapLayerType.GroupLayer:
|
||||
layer = new TiledMapGroupLayer(name, ReadGroup(reader, map), offset, parallaxFactor, opacity, isVisible);
|
||||
layer = new TiledMapGroupLayer(name, type, ReadGroup(reader, map), offset, parallaxFactor, opacity, isVisible);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
@@ -114,7 +116,7 @@ namespace MonoGame.Extended.Tiled
|
||||
return layer;
|
||||
}
|
||||
|
||||
private static TiledMapLayer ReadObjectLayer(ContentReader reader, string name, Vector2 offset, Vector2 parallaxFactor, float opacity, bool isVisible, TiledMap map)
|
||||
private static TiledMapLayer ReadObjectLayer(ContentReader reader, string name, string type, Vector2 offset, Vector2 parallaxFactor, float opacity, bool isVisible, TiledMap map)
|
||||
{
|
||||
var color = reader.ReadColor();
|
||||
var drawOrder = (TiledMapObjectDrawOrder)reader.ReadByte();
|
||||
@@ -124,7 +126,7 @@ namespace MonoGame.Extended.Tiled
|
||||
for (var i = 0; i < objectCount; i++)
|
||||
objects[i] = ReadTiledMapObject(reader, map);
|
||||
|
||||
return new TiledMapObjectLayer(name, objects, color, drawOrder, offset, parallaxFactor, opacity, isVisible);
|
||||
return new TiledMapObjectLayer(name, type, objects, color, drawOrder, offset, parallaxFactor, opacity, isVisible);
|
||||
}
|
||||
|
||||
private static TiledMapObject ReadTiledMapObject(ContentReader reader, TiledMap map)
|
||||
@@ -193,16 +195,16 @@ namespace MonoGame.Extended.Tiled
|
||||
return points;
|
||||
}
|
||||
|
||||
private static TiledMapImageLayer ReadImageLayer(ContentReader reader, string name, Vector2 offset, Vector2 parallaxFactor, float opacity, bool isVisible)
|
||||
private static TiledMapImageLayer ReadImageLayer(ContentReader reader, string name, string type, Vector2 offset, Vector2 parallaxFactor, float opacity, bool isVisible)
|
||||
{
|
||||
var texture = reader.ReadExternalReference<Texture2D>();
|
||||
var x = reader.ReadSingle();
|
||||
var y = reader.ReadSingle();
|
||||
var position = new Vector2(x, y);
|
||||
return new TiledMapImageLayer(name, texture, position, offset, parallaxFactor, opacity, isVisible);
|
||||
return new TiledMapImageLayer(name, type, texture, position, offset, parallaxFactor, opacity, isVisible);
|
||||
}
|
||||
|
||||
private static TiledMapTileLayer ReadTileLayer(ContentReader reader, string name, Vector2 offset, Vector2 parallaxFactor, float opacity, bool isVisible, TiledMap map)
|
||||
private static TiledMapTileLayer ReadTileLayer(ContentReader reader, string name, string type, Vector2 offset, Vector2 parallaxFactor, float opacity, bool isVisible, TiledMap map)
|
||||
{
|
||||
var width = reader.ReadInt32();
|
||||
var height = reader.ReadInt32();
|
||||
@@ -210,7 +212,7 @@ namespace MonoGame.Extended.Tiled
|
||||
var tileHeight = map.TileHeight;
|
||||
|
||||
var tileCount = reader.ReadInt32();
|
||||
var layer = new TiledMapTileLayer(name, width, height, tileWidth, tileHeight, offset, parallaxFactor, opacity, isVisible);
|
||||
var layer = new TiledMapTileLayer(name, type, width, height, tileWidth, tileHeight, offset, parallaxFactor, opacity, isVisible);
|
||||
|
||||
for (var i = 0; i < tileCount; i++)
|
||||
{
|
||||
|
||||
@@ -5,9 +5,9 @@ namespace MonoGame.Extended.Tiled
|
||||
{
|
||||
public class TiledMapTileLayer : TiledMapLayer
|
||||
{
|
||||
public TiledMapTileLayer(string name, int width, int height, int tileWidth, int tileHeight, Vector2? offset = null,
|
||||
public TiledMapTileLayer(string name, string type, int width, int height, int tileWidth, int tileHeight, Vector2? offset = null,
|
||||
Vector2? parallaxFactor = null, float opacity = 1, bool isVisible = true)
|
||||
: base(name, offset, parallaxFactor, opacity, isVisible)
|
||||
: base(name, type, offset, parallaxFactor, opacity, isVisible)
|
||||
{
|
||||
Width = width;
|
||||
Height = height;
|
||||
|
||||
@@ -21,9 +21,10 @@ namespace MonoGame.Extended.Tiled
|
||||
|
||||
public class TiledMapTileset : ITileset
|
||||
{
|
||||
public TiledMapTileset(Texture2D texture, int tileWidth, int tileHeight, int tileCount, int spacing, int margin, int columns)
|
||||
public TiledMapTileset(Texture2D texture, string type, int tileWidth, int tileHeight, int tileCount, int spacing, int margin, int columns)
|
||||
{
|
||||
Texture = texture;
|
||||
Type = type;
|
||||
TileWidth = tileWidth;
|
||||
TileHeight = tileHeight;
|
||||
TileCount = tileCount;
|
||||
@@ -44,6 +45,7 @@ namespace MonoGame.Extended.Tiled
|
||||
return new TextureRegion2D(Texture, x, y, TileWidth, TileHeight);
|
||||
}
|
||||
|
||||
public string Type { get; }
|
||||
public int TileWidth { get; }
|
||||
public int TileHeight { get; }
|
||||
public int Spacing { get; }
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace MonoGame.Extended.Tiled
|
||||
public static TiledMapTileset ReadTileset(ContentReader reader)
|
||||
{
|
||||
var texture = reader.ReadExternalReference<Texture2D>();
|
||||
var @class = reader.ReadString();
|
||||
var tileWidth = reader.ReadInt32();
|
||||
var tileHeight = reader.ReadInt32();
|
||||
var tileCount = reader.ReadInt32();
|
||||
@@ -26,7 +27,7 @@ namespace MonoGame.Extended.Tiled
|
||||
var columns = reader.ReadInt32();
|
||||
var explicitTileCount = reader.ReadInt32();
|
||||
|
||||
var tileset = new TiledMapTileset(texture, tileWidth, tileHeight, tileCount, spacing, margin, columns);
|
||||
var tileset = new TiledMapTileset(texture, @class, tileWidth, tileHeight, tileCount, spacing, margin, columns);
|
||||
|
||||
for (var tileIndex = 0; tileIndex < explicitTileCount; tileIndex++)
|
||||
ReadTile(reader, tileset);
|
||||
|
||||
Reference in New Issue
Block a user