From 9429d915ae3cee9c0d21a9ea54bac39e544be932 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 3 Sep 2024 19:25:19 -0300 Subject: [PATCH] [lua] Fix default color/bgColor params in app.useTool() We can select the default color or tile from preferences depending if we're going to paint pixels or tiles Fixes a confusing logic from 4a91d150af97e70e588e82d698dc8c5e0db8e6fe where the bg color was obtained from preferences only when the fg color type (rgb/gray/index/hsv/tile/etc.) was equal to the bg color type from the preferences (rgb/gray/index/hsv/tile/etc.). --- src/app/script/app_object.cpp | 41 +++++++++++++++++------------------ 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/app/script/app_object.cpp b/src/app/script/app_object.cpp index 20c01b56d..73b63cb32 100644 --- a/src/app/script/app_object.cpp +++ b/src/app/script/app_object.cpp @@ -348,24 +348,37 @@ int App_useTool(lua_State* L) params.inkType = get_value_from_lua(L, -1); lua_pop(L, 1); + // Are we going to modify pixels or tiles? + type = lua_getfield(L, 1, "tilemapMode"); + if (type != LUA_TNIL) { + site.tilemapMode(TilemapMode(lua_tointeger(L, -1))); + } + lua_pop(L, 1); + + // How the tileset must be modified depending on this tool usage + type = lua_getfield(L, 1, "tilesetMode"); + if (type != LUA_TNIL) { + site.tilesetMode(TilesetMode(lua_tointeger(L, -1))); + } + lua_pop(L, 1); + // Color type = lua_getfield(L, 1, "color"); if (type != LUA_TNIL) params.fg = convert_args_into_color(L, -1); - else { - // Default color is the active fgColor + else if (site.tilemapMode() == TilemapMode::Tiles) + params.fg = Color::fromTile(Preferences::instance().colorBar.fgTile()); + else // Default color is the active fgColor params.fg = Preferences::instance().colorBar.fgColor(); - } lua_pop(L, 1); type = lua_getfield(L, 1, "bgColor"); if (type != LUA_TNIL) params.bg = convert_args_into_color(L, -1); - else if (params.fg.getType() == - Preferences::instance().colorBar.bgColor().getType()) - params.bg = Preferences::instance().colorBar.bgColor(); + else if (site.tilemapMode() == TilemapMode::Tiles) + params.bg = Color::fromTile(Preferences::instance().colorBar.bgTile()); else - params.bg = params.fg; + params.bg = Preferences::instance().colorBar.bgColor(); lua_pop(L, 1); // Adjust ink depending on "inkType" and "color" @@ -444,20 +457,6 @@ int App_useTool(lua_State* L) } } - // Are we going to modify pixels or tiles? - type = lua_getfield(L, 1, "tilemapMode"); - if (type != LUA_TNIL) { - site.tilemapMode(TilemapMode(lua_tointeger(L, -1))); - } - lua_pop(L, 1); - - // How the tileset must be modified depending on this tool usage - type = lua_getfield(L, 1, "tilesetMode"); - if (type != LUA_TNIL) { - site.tilesetMode(TilesetMode(lua_tointeger(L, -1))); - } - lua_pop(L, 1); - // Do the tool loop type = lua_getfield(L, 1, "points"); if (type == LUA_TTABLE) {