From 906d85d5c17232cf7b2281cf98033bba506ff749 Mon Sep 17 00:00:00 2001 From: James Date: Tue, 3 Nov 2026 15:23:25 -0700 Subject: [PATCH] Fix tileset tile ID remapping after resize ## What was wrong Resizing a tileset could cause existing tile IDs to be remapped incorrectly. The remapping logic derived the previous column count from the old pixel width instead of using the tileset's stored grid width, and height-only expansion could trigger unnecessary remapping. ## What changed - Preserve the previous tile-grid width when remapping tile IDs. - Skip remapping when the tileset only grows vertically and its grid width is unchanged. - Continue remapping when the tile layout genuinely changes. ## Testing Built the project locally and imported assets using the updated build. Tileset resizing and tile IDs behaved as expected. --- src/electron.renderer/data/def/TilesetDef.hx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/electron.renderer/data/def/TilesetDef.hx b/src/electron.renderer/data/def/TilesetDef.hx index f62bdbaef..2a47272a0 100644 --- a/src/electron.renderer/data/def/TilesetDef.hx +++ b/src/electron.renderer/data/def/TilesetDef.hx @@ -250,6 +250,7 @@ class TilesetDef { var oldRelPath = relPath; var oldPxWid = pxWid; var oldPxHei = pxHei; + var oldCWid = cWid; // Init if( relFilePath!=null ) { @@ -284,7 +285,7 @@ class TilesetDef { if( oldRelPath!=null || isUsingEmbedAtlas() && oldPxWid>0 ) { // Try to update previous image - return remapAllTileIdsAfterResize(oldPxWid, oldPxHei); + return remapAllTileIdsAfterResize(oldPxWid, oldPxHei, oldCWid); } else return Ok; @@ -292,7 +293,7 @@ class TilesetDef { } - function remapAllTileIdsAfterResize(oldPxWid:Int, oldPxHei:Int) : EditorTypes.ImageLoadingResult { + function remapAllTileIdsAfterResize(oldPxWid:Int, oldPxHei:Int, oldCWid:Int) : EditorTypes.ImageLoadingResult { App.LOG.warning('Tileset $identifier remapping (image size changed)...'); if( oldPxWid==pxWid && oldPxHei==pxHei ) return Ok; @@ -304,7 +305,11 @@ class TilesetDef { return TrimmedPadding; } - return remapAllTileIds( dn.M.ceil( oldPxWid/tileGridSize ) ); + // Height-only expansion with unchanged grid width: existing tile IDs are still valid + if( oldPxWid==pxWid && oldCWid==cWid && oldPxHei