From 557b22a7198e474db6824c953d1e3e79f51d2a4e Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 30 Oct 2023 13:45:11 -0300 Subject: [PATCH] [lua] Sprite:newTileset() uses sprite grid size by default (fix #4116) --- src/app/script/sprite_class.cpp | 2 +- tests/scripts/tileset.lua | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/app/script/sprite_class.cpp b/src/app/script/sprite_class.cpp index 580a67719..eab906a54 100644 --- a/src/app/script/sprite_class.cpp +++ b/src/app/script/sprite_class.cpp @@ -625,7 +625,7 @@ int Sprite_newTileset(lua_State* L) tileset = Tileset::MakeCopyCopyingImages(reference); } else { - Grid grid; + Grid grid(sprite->gridBounds().size()); // Use sprite grid bounds by default int ntiles = 1; if (!lua_isnone(L, 2)) { if (auto g = may_get_obj(L, 2)) { diff --git a/tests/scripts/tileset.lua b/tests/scripts/tileset.lua index f75414326..8952df4ae 100644 --- a/tests/scripts/tileset.lua +++ b/tests/scripts/tileset.lua @@ -310,3 +310,14 @@ do 0, 0 }) end + +-- Test that we use the sprite grid size by default to create new tilesets +do + local spr = Sprite(32, 32, ColorMode.INDEXED) + local ts = spr:newTileset() + assert(ts.grid.tileSize == Size(16, 16)) + + spr.gridBounds = Rectangle(1, 2, 3, 4) + ts = spr:newTileset() + assert(ts.grid.tileSize == Size(3, 4)) +end