Skip to content

Commit

Permalink
Tweak WML and lua screen_fade interface
Browse files Browse the repository at this point in the history
  • Loading branch information
mesilliac committed Jul 14, 2022
1 parent 6aac1a5 commit aae56fe
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
3 changes: 2 additions & 1 deletion data/lua/wml-tags.lua
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,8 @@ function wml_actions.color_adjust(cfg)
end

function wml_actions.screen_fade(cfg)
wesnoth.interface.screen_fade(cfg.red, cfg.green, cfg.blue, cfg.alpha, cfg.duration)
color = {cfg.red or 0, cfg.green or 0, cfg.blue or 0, cfg.alpha}
wesnoth.interface.screen_fade(color, cfg.duration)
end

function wml_actions.end_turn(cfg)
Expand Down
6 changes: 2 additions & 4 deletions data/schema/core/actionwml.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -868,10 +868,8 @@
[tag]
name="screen_fade"
max=infinite
{REQUIRED_KEY red s_int}
{REQUIRED_KEY green s_int}
{REQUIRED_KEY blue s_int}
{REQUIRED_KEY alpha s_int}
{COLOR_KEYS s_unsigned}
{REQUIRED_KEY alpha s_unsigned}
{REQUIRED_KEY duration s_unsigned}
[/tag]
[tag]
Expand Down
12 changes: 6 additions & 6 deletions src/scripting/game_lua_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3727,12 +3727,12 @@ int game_lua_kernel::intf_get_color_adjust(lua_State *L)
int game_lua_kernel::intf_screen_fade(lua_State *L)
{
if(game_display_) {
color_t fade;
fade.r = luaL_checkinteger(L, 1);
fade.g = luaL_checkinteger(L, 2);
fade.b = luaL_checkinteger(L, 3);
fade.a = luaL_checkinteger(L, 4);
game_display_->fade_to(fade, luaL_checkinteger(L, 5));
auto vec = lua_check<std::vector<uint8_t>>(L, 1);
if(vec.size() != 4) {
return luaL_error(L, "screen fade colour must be an array of 4 integers");
}
color_t fade{vec[0], vec[1], vec[2], vec[3]};
game_display_->fade_to(fade, luaL_checkinteger(L, 2));
}
return 0;
}
Expand Down
5 changes: 5 additions & 0 deletions utils/emmylua/wesnoth/interface.lua
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,10 @@ function wesnoth.interface.allow_end_turn(reason) end
---@param blue integer
function wesnoth.interface.color_adjust(red, green, blue) end

---Fade the screen to the given colour
---@param color integer[] RGBA colour value to fade to; A=0 removes fade
---@param duration integer How long the fade takes to apply, in milliseconds
function wesnoth.interface.screen_fade(color, duration) end

---@type table<string, fun()>
wesnoth.game_display = {}

0 comments on commit aae56fe

Please sign in to comment.