From 58bb446e2ba7ef3ef1d81dd1da08ac1e2c428f6f Mon Sep 17 00:00:00 2001 From: Daniel Cronqvist Date: Thu, 24 Apr 2025 22:44:17 +0200 Subject: [PATCH] Read new image size properties in tmj from Tiled 1.11.1 --- .../Maps/map-with-many-layers/map-with-many-layers.cs | 6 +++--- .../Maps/map-with-many-layers/map-with-many-layers.tmj | 4 +++- .../Maps/map-with-many-layers/map-with-many-layers.tmx | 2 +- src/DotTiled/Serialization/Tmj/TmjReaderBase.ImageLayer.cs | 6 ++++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/map-with-many-layers.cs b/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/map-with-many-layers.cs index 35c4cbd..593eec7 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/map-with-many-layers.cs +++ b/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/map-with-many-layers.cs @@ -19,7 +19,7 @@ public partial class TestData CompressionLevel = -1, BackgroundColor = new TiledColor { R = 0, G = 0, B = 0, A = 0 }, Version = "1.10", - TiledVersion = "1.11.0", + TiledVersion = "1.11.2", NextLayerID = 8, NextObjectID = 7, Tilesets = [ @@ -172,8 +172,8 @@ public partial class TestData { Format = ImageFormat.Png, Source = "tileset.png", - Width = fileExt == "tmx" ? 256 : 0, // Currently, json format does not - Height = fileExt == "tmx" ? 96 : 0 // include image dimensions in image layer https://github.com/mapeditor/tiled/issues/4028 + Width = 256, + Height = 96 }, RepeatX = true }, diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/map-with-many-layers.tmj b/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/map-with-many-layers.tmj index 9e9f669..427f404 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/map-with-many-layers.tmj +++ b/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/map-with-many-layers.tmj @@ -114,6 +114,8 @@ { "id":4, "image":"tileset.png", + "imageheight":96, + "imagewidth":256, "name":"ImageLayer", "opacity":1, "repeatx":true, @@ -149,7 +151,7 @@ "nextobjectid":7, "orientation":"orthogonal", "renderorder":"right-down", - "tiledversion":"1.11.0", + "tiledversion":"1.11.2", "tileheight":32, "tilesets":[ { diff --git a/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/map-with-many-layers.tmx b/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/map-with-many-layers.tmx index 5888069..512a7a4 100644 --- a/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/map-with-many-layers.tmx +++ b/src/DotTiled.Tests/TestData/Maps/map-with-many-layers/map-with-many-layers.tmx @@ -1,5 +1,5 @@ - + diff --git a/src/DotTiled/Serialization/Tmj/TmjReaderBase.ImageLayer.cs b/src/DotTiled/Serialization/Tmj/TmjReaderBase.ImageLayer.cs index 0da963d..c0c2c5b 100644 --- a/src/DotTiled/Serialization/Tmj/TmjReaderBase.ImageLayer.cs +++ b/src/DotTiled/Serialization/Tmj/TmjReaderBase.ImageLayer.cs @@ -19,6 +19,8 @@ public abstract partial class TmjReaderBase var properties = ResolveAndMergeProperties(@class, element.GetOptionalPropertyCustom("properties", ReadProperties).GetValueOr([])); var image = element.GetRequiredProperty("image"); + var imageWidth = element.GetOptionalProperty("imagewidth").GetValueOr(0); + var imageHeight = element.GetOptionalProperty("imageheight").GetValueOr(0); var repeatX = element.GetOptionalProperty("repeatx").GetValueOr(false); var repeatY = element.GetOptionalProperty("repeaty").GetValueOr(false); var transparentColor = element.GetOptionalPropertyParseable("transparentcolor"); @@ -28,8 +30,8 @@ public abstract partial class TmjReaderBase var imgModel = new Image { Format = Helpers.ParseImageFormatFromSource(image), - Height = 0, - Width = 0, + Height = imageHeight, + Width = imageWidth, Source = image, TransparentColor = transparentColor };