Skip to content

Commit

Permalink
Merge pull request #58 from dcronqvist/tileobject-flippingflags
Browse files Browse the repository at this point in the history
Add flipping flags parsing/clearing to tile objects
  • Loading branch information
dcronqvist authored Nov 17, 2024
2 parents 67876c6 + 54bc132 commit 52f148f
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
}
]
}
]
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.11.0" orientation="orthogonal" renderorder="right-down" width="5" height="5" tilewidth="32" tileheight="32" infinite="0" nextlayerid="2" nextobjectid="1">
<map version="1.10" tiledversion="1.11.0" orientation="orthogonal" renderorder="right-down" width="5" height="5" tilewidth="32" tileheight="32" infinite="0" nextlayerid="3" nextobjectid="3">
<tileset firstgid="1" source="tileset.tsx"/>
<layer id="1" name="Tile Layer 1" width="5" height="5">
<data encoding="csv">
Expand All @@ -10,4 +10,8 @@
2147483669,2147483669,2147483669,2147483669,1
</data>
</layer>
<objectgroup id="2" name="Object Layer 1">
<object id="1" gid="2147483669" x="80.0555" y="48.3887" width="32" height="32"/>
<object id="2" gid="1073741845" x="15.8334" y="112.056" width="32" height="32"/>
</objectgroup>
</map>
5 changes: 5 additions & 0 deletions src/DotTiled/Layers/Objects/TileObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ public class TileObject : Object
/// A reference to a tile.
/// </summary>
public uint GID { get; set; }

/// <summary>
/// The flipping flags for the tile.
/// </summary>
public FlippingFlags FlippingFlags { get; set; }
}
6 changes: 5 additions & 1 deletion src/DotTiled/Serialization/Tmj/TmjReaderBase.ObjectLayer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text.Json;

Expand Down Expand Up @@ -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,
Expand All @@ -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()
};
}

Expand Down
7 changes: 6 additions & 1 deletion src/DotTiled/Serialization/Tmx/TmxReaderBase.ObjectLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 52f148f

Please sign in to comment.