diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-flippingflags/map-with-flippingflags.cs b/src/DotTiled.Tests/TestData/Maps/map-with-flippingflags/map-with-flippingflags.cs index 0777e3f..aef25d3 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-with-flippingflags/map-with-flippingflags.cs +++ b/src/DotTiled.Tests/TestData/Maps/map-with-flippingflags/map-with-flippingflags.cs @@ -20,8 +20,8 @@ public partial class TestData BackgroundColor = Color.Parse("#00000000", CultureInfo.InvariantCulture), Version = "1.10", TiledVersion = "1.11.0", - NextLayerID = 2, - NextObjectID = 1, + NextLayerID = 3, + NextObjectID = 3, Tilesets = [ new Tileset { @@ -68,6 +68,33 @@ public partial class TestData FlippingFlags.FlippedHorizontally, FlippingFlags.FlippedHorizontally, FlippingFlags.FlippedHorizontally, FlippingFlags.FlippedHorizontally, FlippingFlags.None ]) } + }, + new ObjectLayer + { + ID = 2, + Name = "Object Layer 1", + Objects = [ + new TileObject + { + ID = 1, + GID = 21, + X = 80.0555f, + Y = 48.3887f, + Width = 32, + Height = 32, + FlippingFlags = FlippingFlags.FlippedHorizontally + }, + new TileObject + { + ID = 2, + GID = 21, + X = 15.833f, + Y = 112.056f, + Width = 32, + Height = 32, + FlippingFlags = FlippingFlags.FlippedHorizontally | FlippingFlags.FlippedVertically + } + ] } ] }; diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-flippingflags/map-with-flippingflags.tmj b/src/DotTiled.Tests/TestData/Maps/map-with-flippingflags/map-with-flippingflags.tmj index 3b74128..43a18fe 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-with-flippingflags/map-with-flippingflags.tmj +++ b/src/DotTiled.Tests/TestData/Maps/map-with-flippingflags/map-with-flippingflags.tmj @@ -17,9 +17,44 @@ "width":5, "x":0, "y":0 + }, + { + "draworder":"topdown", + "id":2, + "name":"Object Layer 1", + "objects":[ + { + "gid":2147483669, + "height":32, + "id":1, + "name":"", + "rotation":0, + "type":"", + "visible":true, + "width":32, + "x":80.0555234239445, + "y":48.3886639676113 + }, + { + "gid":1073741845, + "height":32, + "id":2, + "name":"", + "rotation":0, + "type":"", + "visible":true, + "width":32, + "x":15.8334297281666, + "y":112.055523423944 + }], + "opacity":1, + "type":"objectgroup", + "visible":true, + "x":0, + "y":0 }], - "nextlayerid":2, - "nextobjectid":1, + "nextlayerid":3, + "nextobjectid":3, "orientation":"orthogonal", "renderorder":"right-down", "tiledversion":"1.11.0", diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-flippingflags/map-with-flippingflags.tmx b/src/DotTiled.Tests/TestData/Maps/map-with-flippingflags/map-with-flippingflags.tmx index a72cd1a..ca0130d 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-with-flippingflags/map-with-flippingflags.tmx +++ b/src/DotTiled.Tests/TestData/Maps/map-with-flippingflags/map-with-flippingflags.tmx @@ -1,5 +1,5 @@ - + @@ -10,4 +10,8 @@ 2147483669,2147483669,2147483669,2147483669,1 + + + + diff --git a/src/DotTiled/Layers/Objects/TileObject.cs b/src/DotTiled/Layers/Objects/TileObject.cs index ab00628..ea23d70 100644 --- a/src/DotTiled/Layers/Objects/TileObject.cs +++ b/src/DotTiled/Layers/Objects/TileObject.cs @@ -9,4 +9,9 @@ public class TileObject : Object /// A reference to a tile. /// public uint GID { get; set; } + + /// + /// The flipping flags for the tile. + /// + public FlippingFlags FlippingFlags { get; set; } } diff --git a/src/DotTiled/Serialization/Tmj/TmjReaderBase.ObjectLayer.cs b/src/DotTiled/Serialization/Tmj/TmjReaderBase.ObjectLayer.cs index f90d986..ced3f64 100644 --- a/src/DotTiled/Serialization/Tmj/TmjReaderBase.ObjectLayer.cs +++ b/src/DotTiled/Serialization/Tmj/TmjReaderBase.ObjectLayer.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Globalization; +using System.Linq; using System.Numerics; using System.Text.Json; @@ -117,6 +118,8 @@ internal DotTiled.Object ReadObject(JsonElement element) if (gid.HasValue) { + var (clearedGIDs, flippingFlags) = Helpers.ReadAndClearFlippingFlagsFromGIDs([gid.Value]); + return new TileObject { ID = id, @@ -130,7 +133,8 @@ internal DotTiled.Object ReadObject(JsonElement element) Visible = visible, Template = template, Properties = properties, - GID = gid.Value + GID = clearedGIDs.Single(), + FlippingFlags = flippingFlags.Single() }; } diff --git a/src/DotTiled/Serialization/Tmx/TmxReaderBase.ObjectLayer.cs b/src/DotTiled/Serialization/Tmx/TmxReaderBase.ObjectLayer.cs index 46626e6..7553d21 100644 --- a/src/DotTiled/Serialization/Tmx/TmxReaderBase.ObjectLayer.cs +++ b/src/DotTiled/Serialization/Tmx/TmxReaderBase.ObjectLayer.cs @@ -118,9 +118,14 @@ internal DotTiled.Object ReadObject() if (foundObject is null) { if (gid.HasValue) - foundObject = new TileObject { ID = id, GID = gid.Value }; + { + var (clearedGIDs, flippingFlags) = Helpers.ReadAndClearFlippingFlagsFromGIDs([gid.Value]); + foundObject = new TileObject { ID = id, GID = clearedGIDs.Single(), FlippingFlags = flippingFlags.Single() }; + } else + { foundObject = new RectangleObject { ID = id }; + } } foundObject.ID = id;