[lua] Fix undo/redo of tileset properties changes (name/baseIndex)

This commit is contained in:
David Capello 2023-01-13 19:16:15 -03:00
parent 11a3e634b1
commit faabacdd39
2 changed files with 34 additions and 4 deletions

View File

@ -8,6 +8,8 @@
#include "config.h"
#endif
#include "app/cmd/set_tileset_base_index.h"
#include "app/cmd/set_tileset_name.h"
#include "app/script/docobj.h"
#include "app/script/engine.h"
#include "app/script/luacpp.h"
@ -69,8 +71,11 @@ int Tileset_get_name(lua_State* L)
int Tileset_set_name(lua_State* L)
{
auto tileset = get_docobj<Tileset>(L, 1);
if (const char* newName = lua_tostring(L, 2))
tileset->setName(newName);
if (const char* newName = lua_tostring(L, 2)) {
Tx tx;
tx(new cmd::SetTilesetName(tileset, newName));
tx.commit();
}
return 0;
}
@ -92,7 +97,9 @@ int Tileset_set_baseIndex(lua_State* L)
{
auto tileset = get_docobj<Tileset>(L, 1);
int i = lua_tointeger(L, 2);
tileset->setBaseIndex(i);
Tx tx;
tx(new cmd::SetTilesetBaseIndex(tileset, i));
tx.commit();
return 0;
}

View File

@ -13,7 +13,7 @@ do
local tilemap = spr.layers[2]
local tileset = tilemap.tileset
assert(#tileset == 1);
assert(#tileset == 1)
app.useTool{
tool='pencil',
@ -51,6 +51,29 @@ do
end
end
-- Check undo/redo of name and baseIndex changes
do
local spr = Sprite(4, 4, ColorMode.INDEXED)
app.command.NewLayer{ tilemap=true }
local tilemap = spr.layers[2]
local tileset = tilemap.tileset
assert(#tileset == 1)
-- Check undo/redo of name change
assert(tileset.name == "")
tileset.name = "Terrain"
assert(tileset.name == "Terrain")
app.undo() assert(tileset.name == "")
app.redo() assert(tileset.name == "Terrain")
-- Check undo/redo of baseIndex
assert(tileset.baseIndex == 1)
tileset.baseIndex = 2
assert(tileset.baseIndex == 2)
app.undo() assert(tileset.baseIndex == 1)
app.redo() assert(tileset.baseIndex == 2)
end
-- Create and delete Tilesets
do
local spr = Sprite(4, 4, ColorMode.INDEXED)