Skip to content

Commit

Permalink
Lua API reorganization: interface module
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Nov 12, 2018
1 parent b94ccf9 commit b42c5ba
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 24 deletions.
48 changes: 48 additions & 0 deletions data/lua/core.lua
Expand Up @@ -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

Expand Down
25 changes: 1 addition & 24 deletions data/lua/helper.lua
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions data/lua/wml/items.lua
Expand Up @@ -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

0 comments on commit b42c5ba

Please sign in to comment.