From b42c5ba3d3e620b9c64a789745bd3989e36b6873 Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Sun, 11 Mar 2018 12:42:47 -0400 Subject: [PATCH] Lua API reorganization: interface module --- data/lua/core.lua | 48 ++++++++++++++++++++++++++++++++++++++++++ data/lua/helper.lua | 25 +--------------------- data/lua/wml/items.lua | 4 ++++ 3 files changed, 53 insertions(+), 24 deletions(-) diff --git a/data/lua/core.lua b/data/lua/core.lua index 2df1ac0604fba..34bd22bf24e81 100644 --- a/data/lua/core.lua +++ b/data/lua/core.lua @@ -438,6 +438,54 @@ if wesnoth.kernel_type() == "Game Lua Kernel" then end end return data_to_save + + --[========[Game Interface Control]========] + + wesnoth.intf = { + delay = wesnoth.delay, + float_label = wesnoth.float_label, + select_unit = wesnoth.select_unit, + highlight_hex = wesnoth.highlight_hex, + deselect_hex = wesnoth.deselect_hex, + get_selected_hex = wesnoth.get_selected_tile, + scroll_to_hex = wesnoth.scroll_to_tile, + lock = wesnoth.lock_view, + is_locked = wesnoth.view_locked, + is_skipping_messages = wesnoth.is_skipping_messages, + skip_messages = wesnoth.skip_messages, + add_hex_overlay = wesnoth.add_tile_overlay, + remove_hex_overlay = wesnoth.remove_tile_overlay, + game_display = wesnoth.theme_items, + get_displayed_unit = wesnoth.get_displayed_unit, + } + + --! Fakes the move of a unit satisfying the given @a filter to position @a x, @a y. + --! @note Usable only during WML actions. + function wesnoth.intf.move_unit_fake(filter, to_x, to_y) + local moving_unit = wesnoth.get_units(filter)[1] + local from_x, from_y = moving_unit.x, moving_unit.y + + wesnoth.intf.scroll_to_hex(from_x, from_y) + to_x, to_y = wesnoth.find_vacant_tile(x, y, moving_unit) + + if to_x < from_x then + moving_unit.facing = "sw" + elseif to_x > from_x then + moving_unit.facing = "se" + end + moving_unit:extract() + + wml_actions.move_unit_fake{ + type = moving_unit.type, + gender = moving_unit.gender, + variation = moving.variation, + side = moving_unit.side, + x = from_x .. ',' .. to_x, + y = from_y .. ',' .. to_y + } + + moving_unit:to_map(to_x, to_y) + wml_actions.redraw{} end end diff --git a/data/lua/helper.lua b/data/lua/helper.lua index f3a8b22b5c552..b5ae57048e840 100644 --- a/data/lua/helper.lua +++ b/data/lua/helper.lua @@ -53,30 +53,7 @@ end --! Fakes the move of a unit satisfying the given @a filter to position @a x, @a y. --! @note Usable only during WML actions. function helper.move_unit_fake(filter, to_x, to_y) - local moving_unit = wesnoth.get_units(filter)[1] - local from_x, from_y = moving_unit.x, moving_unit.y - - wesnoth.intf.scroll_to_hex(from_x, from_y) - to_x, to_y = wesnoth.find_vacant_tile(x, y, moving_unit) - - if to_x < from_x then - moving_unit.facing = "sw" - elseif to_x > from_x then - moving_unit.facing = "se" - end - moving_unit:extract() - - wml_actions.move_unit_fake{ - type = moving_unit.type, - gender = moving_unit.gender, - variation = moving.variation, - side = moving_unit.side, - x = from_x .. ',' .. to_x, - y = from_y .. ',' .. to_y - } - - moving_unit:to_map(to_x, to_y) - wml_actions.redraw{} + wesnoth.intf.move_unit_fake(filter, to_x, to_y) end -- Metatable that redirects access to wml.variables_proxy diff --git a/data/lua/wml/items.lua b/data/lua/wml/items.lua index 902d38c40d038..8f7e61137eaf6 100644 --- a/data/lua/wml/items.lua +++ b/data/lua/wml/items.lua @@ -113,4 +113,8 @@ function methods.place_halo(x, y, name) add_overlay(x, y, { x = x, y = y, halo = name }) end +wesnoth.intf.remove_item = methods.remove +wesnoth.intf.add_item_image = methods.place_image +wesnoth.intf.add_item_halo = methods.place_halo + return methods