[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 4a91d150af
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.).
This commit is contained in:
David Capello 2024-09-03 19:25:19 -03:00
parent 240d481645
commit 9429d915ae

View File

@ -348,24 +348,37 @@ int App_useTool(lua_State* L)
params.inkType = get_value_from_lua<tools::InkType>(L, -1); params.inkType = get_value_from_lua<tools::InkType>(L, -1);
lua_pop(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 // Color
type = lua_getfield(L, 1, "color"); type = lua_getfield(L, 1, "color");
if (type != LUA_TNIL) if (type != LUA_TNIL)
params.fg = convert_args_into_color(L, -1); params.fg = convert_args_into_color(L, -1);
else { else if (site.tilemapMode() == TilemapMode::Tiles)
// Default color is the active fgColor params.fg = Color::fromTile(Preferences::instance().colorBar.fgTile());
else // Default color is the active fgColor
params.fg = Preferences::instance().colorBar.fgColor(); params.fg = Preferences::instance().colorBar.fgColor();
}
lua_pop(L, 1); lua_pop(L, 1);
type = lua_getfield(L, 1, "bgColor"); type = lua_getfield(L, 1, "bgColor");
if (type != LUA_TNIL) if (type != LUA_TNIL)
params.bg = convert_args_into_color(L, -1); params.bg = convert_args_into_color(L, -1);
else if (params.fg.getType() == else if (site.tilemapMode() == TilemapMode::Tiles)
Preferences::instance().colorBar.bgColor().getType()) params.bg = Color::fromTile(Preferences::instance().colorBar.bgTile());
params.bg = Preferences::instance().colorBar.bgColor();
else else
params.bg = params.fg; params.bg = Preferences::instance().colorBar.bgColor();
lua_pop(L, 1); lua_pop(L, 1);
// Adjust ink depending on "inkType" and "color" // 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 // Do the tool loop
type = lua_getfield(L, 1, "points"); type = lua_getfield(L, 1, "points");
if (type == LUA_TTABLE) { if (type == LUA_TTABLE) {