From 38ae3047255d7050427e1d0e91f14cd338016490 Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Mon, 9 Oct 2023 14:24:30 -0400 Subject: [PATCH] Move Lua undo API into experimental --- data/lua/core/game_events.lua | 15 +++++++++++++++ data/lua/diversion.lua | 4 ++-- data/lua/wml-tags.lua | 8 ++++---- 3 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 data/lua/core/game_events.lua diff --git a/data/lua/core/game_events.lua b/data/lua/core/game_events.lua new file mode 100644 index 00000000000..055000ead5e --- /dev/null +++ b/data/lua/core/game_events.lua @@ -0,0 +1,15 @@ +--[========[Game Event Functions]========] + +if wesnoth.kernel_type() == "Game Lua Kernel" then + -- The undo API is still experimental, so move those functions + + -- Make sure wesnoth.experimental.game_events actually exists + -- It's done this way so it doesn't break if we later need to add things here from C++ + wesnoth.experimental = wesnoth.experimental or {} + wesnoth.experimental.game_events = wesnoth.experimental.game_events or {} + + wesnoth.experimental.game_events.set_undoable = wesnoth.game_events.set_undoable + wesnoth.experimental.game_events.add_undo_actions = wesnoth.game_events.add_undo_actions + wesnoth.game_events.set_undoable = nil + wesnoth.game_events.add_undo_actions = nil +end diff --git a/data/lua/diversion.lua b/data/lua/diversion.lua index f6bb465f9cc..c7ab6ced504 100644 --- a/data/lua/diversion.lua +++ b/data/lua/diversion.lua @@ -87,9 +87,9 @@ local function status_anim_update(is_undo) end end if not is_undo then - wesnoth.game_events.set_undoable(true) + wesnoth.experimental.game_events.set_undoable(true) if changed_something then - wesnoth.game_events.add_undo_actions(function(_) + wesnoth.experimental.game_events.add_undo_actions(function(_) status_anim_update(true) end) end diff --git a/data/lua/wml-tags.lua b/data/lua/wml-tags.lua index 29b089f27d5..9be94779941 100644 --- a/data/lua/wml-tags.lua +++ b/data/lua/wml-tags.lua @@ -645,11 +645,11 @@ function wml_actions.put_to_recall_list(cfg) end function wml_actions.allow_undo(cfg) - wesnoth.game_events.set_undoable(true) + wesnoth.experimental.game_events.set_undoable(true) end function wml_actions.disallow_undo(cfg) - wesnoth.game_events.set_undoable(false) + wesnoth.experimental.game_events.set_undoable(false) end function wml_actions.allow_end_turn(cfg) @@ -1032,8 +1032,8 @@ end function wml_actions.on_undo(cfg) if cfg.delayed_variable_substitution then - wesnoth.game_events.add_undo_actions(wml.literal(cfg)); + wesnoth.experimental.game_events.add_undo_actions(wml.literal(cfg)); else - wesnoth.game_events.add_undo_actions(wml.parsed(cfg)); + wesnoth.experimental.game_events.add_undo_actions(wml.parsed(cfg)); end end