Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port [object] ActionWML tag from C++ to Lua
Lua API additions: - wesnoth.show_popup_dialog() - optional write_to_mods parameter to wesnoth.add_modification
- Loading branch information
1 parent
d4835b0
commit 3760200
Showing
10 changed files
with
119 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
|
||
local helper = wesnoth.require "lua/helper.lua" | ||
local utils = wesnoth.require "lua/wml-utils.lua" | ||
local T = helper.set_wml_tag_metatable {} | ||
local wml_actions = wesnoth.wml_actions | ||
|
||
local used_items = {} | ||
|
||
function wml_actions.object(cfg) | ||
local context = wesnoth.current.event_context | ||
|
||
-- If this item has already been used | ||
if cfg.id and used_items[cfg.id] then return end | ||
|
||
local unit | ||
local filter = helper.get_child(cfg, "filter") | ||
if filter then | ||
unit = wesnoth.get_units(filter)[1] | ||
end | ||
if not unit then | ||
unit = wesnoth.get_unit(contxt.x, context.y) | ||
end | ||
|
||
local command_type, text | ||
if unit then | ||
text = tostring(cfg.description or "") | ||
command_type = "then" | ||
|
||
local dvs = cfg.delayed_variable_substitution | ||
local add = cfg.no_write ~= true | ||
if dvs then | ||
wesnoth.add_modification(unit, "object", helper.literal(cfg), add) | ||
else | ||
wesnoth.add_modification(unit, "object", helper.parsed(cfg), add) | ||
end | ||
|
||
wesnoth.select_hex(unit.x, unit.y) | ||
|
||
-- Mark this item as used up | ||
if cfg.id then used_items[cfg.id] = true end | ||
else | ||
text = tostring(cfg.cannot_use_message or "") | ||
command_type = "else" | ||
end | ||
|
||
-- Default to silent if object has no description | ||
local silent = cfg.silent | ||
if silent == nil then silent = (text:len() == 0) end | ||
|
||
if not silent then | ||
wml_actions.redraw{} | ||
local name = tostring(cfg.name or "") | ||
wesnoth.show_popup_dialog(name, text, cfg.image) | ||
end | ||
|
||
for cmd in helper.child_range(cfg, command_type) do | ||
utils.handle_event_commands(cmd) | ||
end | ||
end | ||
|
||
local old_on_load = wesnoth.game_events.on_load | ||
function wesnoth.game_events.on_load(cfg) | ||
for i = 1,#cfg do | ||
if cfg[i][1] == "used_items" then | ||
-- Not quite sure if this will work | ||
-- Might need to loop through and copy each ID separately | ||
used_items = cfg[i][2] | ||
table.remove(cfg, i) | ||
break | ||
end | ||
end | ||
old_on_load(cfg) | ||
end | ||
|
||
local old_on_save = wesnoth.game_events.on_save | ||
function wesnoth.game_events.on_save() | ||
local cfg = old_on_save() | ||
table.insert(cfg, T.used_items(used_items) ) | ||
return cfg | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters