Cleaned up deprecated API usage in core Lua

[ci skip]
This commit is contained in:
Charles Dang 2018-03-13 16:46:05 +11:00
parent 3b581b65e5
commit 0103959c36
25 changed files with 119 additions and 128 deletions

View file

@ -39,7 +39,7 @@ function callbacks.generate_map(params)
local chambers_by_id = {}
local passages = {}
for chamber in helper.child_range(params, "chamber") do
for chamber in wml.child_range(params, "chamber") do
local chance = tonumber(chamber.chance) or 100
local x = chamber.x
local y = chamber.y
@ -62,7 +62,7 @@ function callbacks.generate_map(params)
local locs_set = LS.create()
build_chamber(x, y, locs_set, chamber.size or 3, chamber.jagged or 0)
local items = {}
for item in helper.child_range(chamber, "item_location") do
for item in wml.child_range(chamber, "item_location") do
table.insert(items, item)
end
table.insert(chambers, {
@ -74,7 +74,7 @@ function callbacks.generate_map(params)
items = items,
})
chambers_by_id[id] = chambers[#chambers]
for passage in helper.child_range(chamber, "passage") do
for passage in wml.child_range(chamber, "passage") do
local dst = chambers_by_id[passage.destination]
if dst ~= nil then
table.insert(passages, {
@ -165,10 +165,10 @@ end
function callbacks.generate_scenario(params)
-- This is more or less backwards compatible with the cave generator syntax
local scenario = helper.get_child(params, "scenario")
local scenario = wml.get_child(params, "scenario")
scenario.map_data = callbacks.generate_map(params)
for chamber in helper.child_range(params, "chamber") do
local chamber_items = helper.get_child(chamber, "items")
for chamber in wml.child_range(params, "chamber") do
local chamber_items = wml.get_child(chamber, "items")
if chamber.chance == 100 and chamber_items then
-- TODO: Should we support [event]same_location_as_previous=yes?
for i,tag in ipairs(chamber_items) do

View file

@ -335,7 +335,7 @@ if wesnoth.kernel_type() == "Game Lua Kernel" then
end
--! Creates proxies for all the WML container variables with name @a var.
--! This is similar to helper.get_variable_array, except that the elements
--! This is similar to wml.variable.get_array, except that the elements
--! can be used for writing too.
--! @returns a table containing all the variable proxies (starting at index 1).
function wml.variable.get_proxy_array(var)

View file

@ -1,7 +1,6 @@
local helper = wesnoth.require("helper")
local _ = wesnoth.textdomain 'wesnoth-help'
local T = helper.set_wml_tag_metatable {}
local T = wml.tag
local on_event = wesnoth.require("on_event")
-- The feeding event code
@ -22,9 +21,9 @@ on_event("die", function()
return
end
local u_killer_cfg = u_killer.__cfg
for i,v in ipairs(helper.get_child(u_killer_cfg, "modifications"))do
for i,v in ipairs(wml.get_child(u_killer_cfg, "modifications"))do
if v[1] == "object" and v[2].feeding == true then
local effect = helper.get_child(v[2], "effect")
local effect = wml.get_child(v[2], "effect")
effect.increase_total = effect.increase_total + 1
u_killer_cfg.max_hitpoints = u_killer_cfg.max_hitpoints + 1
u_killer_cfg.hitpoints = u_killer_cfg.hitpoints + 1

View file

@ -1,5 +1,3 @@
local helper = wesnoth.require "helper"
function wesnoth.wml_conditionals.proceed_to_next_scenario(cfg)
local endlevel_data = wesnoth.get_end_level_data()
@ -11,12 +9,12 @@ function wesnoth.wml_conditionals.proceed_to_next_scenario(cfg)
end
function wesnoth.wml_conditionals.lua(cfg)
cfg = helper.shallow_literal(cfg)
cfg = wml.shallow_literal(cfg)
local bytecode, message = load(cfg.code or "")
if not bytecode then
error("~lua:" .. message, 0)
else
return bytecode(helper.get_child(cfg, "args"))
return bytecode(wml.get_child(cfg, "args"))
end
end

View file

@ -11,21 +11,21 @@ end
-- the table, using the [] operator, rather than by using the point syntax
wml_actions["if"] = function(cfg)
if not (helper.get_child(cfg, 'then') or helper.get_child(cfg, 'elseif') or helper.get_child(cfg, 'else')) then
if not (wml.get_child(cfg, 'then') or wml.get_child(cfg, 'elseif') or wml.get_child(cfg, 'else')) then
helper.wml_error("[if] didn't find any [then], [elseif], or [else] children.")
end
if wesnoth.eval_conditional(cfg) then -- evaluate [if] tag
for then_child in helper.child_range(cfg, "then") do
for then_child in wml.child_range(cfg, "then") do
local action = utils.handle_event_commands(then_child, "conditional")
if action ~= "none" then break end
end
return -- stop after executing [then] tags
end
for elseif_child in helper.child_range(cfg, "elseif") do
for elseif_child in wml.child_range(cfg, "elseif") do
if wesnoth.eval_conditional(elseif_child) then -- we'll evaluate the [elseif] tags one by one
for then_tag in helper.child_range(elseif_child, "then") do
for then_tag in wml.child_range(elseif_child, "then") do
local action = utils.handle_event_commands(then_tag, "conditional")
if action ~= "none" then break end
end
@ -34,21 +34,21 @@ wml_actions["if"] = function(cfg)
end
-- no matched condition, try the [else] tags
for else_child in helper.child_range(cfg, "else") do
for else_child in wml.child_range(cfg, "else") do
local action = utils.handle_event_commands(else_child, "conditional")
if action ~= "none" then break end
end
end
wml_actions["while"] = function( cfg )
if helper.child_count(cfg, "do") == 0 then
if wml.child_count(cfg, "do") == 0 then
helper.wml_error "[while] does not contain any [do] tags"
end
-- execute [do] up to 65536 times
for i = 1, 65536 do
if wesnoth.eval_conditional( cfg ) then
for do_child in helper.child_range( cfg, "do" ) do
for do_child in wml.child_range( cfg, "do" ) do
local action = utils.handle_event_commands(do_child, "loop")
if action == "break" then
utils.set_exiting("none")
@ -77,7 +77,7 @@ function wml_actions.continue(cfg)
end
wesnoth.wml_actions["for"] = function(cfg)
if helper.child_count(cfg, "do") == 0 then
if wml.child_count(cfg, "do") == 0 then
helper.wml_error "[for] does not contain any [do] tags"
end
@ -96,7 +96,7 @@ wesnoth.wml_actions["for"] = function(cfg)
else
-- Get a literal config to fetch end and step;
-- this done is to delay expansion of variables
local cfg_lit = helper.literal(cfg)
local cfg_lit = wml.literal(cfg)
first = cfg.start or 0
loop_lim.last = cfg_lit["end"] or first
loop_lim.step = cfg_lit.step or 1
@ -132,7 +132,7 @@ wesnoth.wml_actions["for"] = function(cfg)
end
end
while loop_condition() do
for do_child in helper.child_range( cfg, "do" ) do
for do_child in wml.child_range( cfg, "do" ) do
local action = utils.handle_event_commands(do_child, "loop")
if action == "break" then
utils.set_exiting("none")
@ -151,13 +151,13 @@ wesnoth.wml_actions["for"] = function(cfg)
end
wml_actions["repeat"] = function(cfg)
if helper.child_count(cfg, "do") == 0 then
if wml.child_count(cfg, "do") == 0 then
helper.wml_error "[repeat] does not contain any [do] tags"
end
local times = cfg.times or 1
for i = 1, times do
for do_child in helper.child_range( cfg, "do" ) do
for do_child in wml.child_range( cfg, "do" ) do
local action = utils.handle_event_commands(do_child, "loop")
if action == "break" then
utils.set_exiting("none")
@ -173,12 +173,12 @@ wml_actions["repeat"] = function(cfg)
end
function wml_actions.foreach(cfg)
if helper.child_count(cfg, "do") == 0 then
if wml.child_count(cfg, "do") == 0 then
helper.wml_error "[foreach] does not contain any [do] tags"
end
local array_name = cfg.array or helper.wml_error "[foreach] missing required array= attribute"
local array = helper.get_variable_array(array_name)
local array = wml.variable.get_array(array_name)
if #array == 0 then return end -- empty and scalars unwanted
local item_name = cfg.variable or "this_item"
local this_item = utils.start_var_scope(item_name) -- if this_item is already set
@ -196,7 +196,7 @@ function wml_actions.foreach(cfg)
-- set index variable
wesnoth.set_variable(i_name, index-1) -- here -1, because of WML array
-- perform actions
for do_child in helper.child_range(cfg, "do") do
for do_child in wml.child_range(cfg, "do") do
local action = utils.handle_event_commands(do_child, "loop")
if action == "break" then
utils.set_exiting("none")
@ -232,7 +232,7 @@ function wml_actions.foreach(cfg)
Note that altering the array via indexing (with the index_var)
is not supported; any such changes will be reverted by this line.
]]
helper.set_variable_array(array_name, array)
wml.variable.set_array(array_name, array)
end
function wml_actions.switch(cfg)
@ -240,7 +240,7 @@ function wml_actions.switch(cfg)
local found = false
-- Execute all the [case]s where the value matches.
for v in helper.child_range(cfg, "case") do
for v in wml.child_range(cfg, "case") do
for w in utils.split(v.value) do
if w == tostring(var_value) then
local action = utils.handle_event_commands(v, "switch")
@ -254,7 +254,7 @@ function wml_actions.switch(cfg)
-- Otherwise execute [else] statements.
if not found then
for v in helper.child_range(cfg, "else") do
for v in wml.child_range(cfg, "else") do
local action = utils.handle_event_commands(v, "switch")
if action ~= "none" then break end
end

View file

@ -2,7 +2,7 @@ local helper = wesnoth.require "helper"
local location_set = wesnoth.require "location_set"
local utils = wesnoth.require "wml-utils"
local wml_actions = wesnoth.wml_actions
local T = helper.set_wml_tag_metatable {}
local T = wml.tag
function wesnoth.game_events.on_load(cfg)
if #cfg == 0 then return end
@ -53,7 +53,7 @@ function wml_actions.sync_variable(cfg)
return res
end
)
for variable in helper.child_range(result, "variable") do
for variable in wml.child_range(result, "variable") do
local name = variable.name
if variable.type == "indexed" then
@ -146,18 +146,18 @@ function wml_actions.store_unit_type(cfg)
end
function wml_actions.fire_event(cfg)
local u1 = helper.get_child(cfg, "primary_unit")
local u1 = wml.get_child(cfg, "primary_unit")
u1 = u1 and wesnoth.get_units(u1)[1]
local x1, y1 = 0, 0
if u1 then x1, y1 = u1.x, u1.y end
local u2 = helper.get_child(cfg, "secondary_unit")
local u2 = wml.get_child(cfg, "secondary_unit")
u2 = u2 and wesnoth.get_units(u2)[1]
local x2, y2 = 0, 0
if u2 then x2, y2 = u2.x, u2.y end
local w1 = helper.get_child(cfg, "primary_attack")
local w2 = helper.get_child(cfg, "secondary_attack")
local w1 = wml.get_child(cfg, "primary_attack")
local w2 = wml.get_child(cfg, "secondary_attack")
if w2 then w1 = w1 or {} end
if cfg.id and cfg.id ~= "" then wesnoth.fire_event_by_id(cfg.id, x1, y1, x2, y2, w1, w2)
@ -277,10 +277,10 @@ function wml_actions.unit_worth(cfg)
end
function wml_actions.lua(cfg)
cfg = helper.shallow_literal(cfg)
cfg = wml.shallow_literal(cfg)
local bytecode, message = load(cfg.code or "")
if not bytecode then error("~lua:" .. message, 0) end
bytecode(helper.get_child(cfg, "args"))
bytecode(wml.get_child(cfg, "args"))
end
function wml_actions.music(cfg)
@ -388,7 +388,7 @@ function wml_actions.store_turns(cfg)
end
function wml_actions.store_unit(cfg)
local filter = helper.get_child(cfg, "filter") or
local filter = wml.get_child(cfg, "filter") or
helper.wml_error "[store_unit] missing required [filter] tag"
local kill_units = cfg.kill
@ -436,9 +436,9 @@ function wml_actions.store_locations(cfg)
end
function wml_actions.store_reachable_locations(cfg)
local unit_filter = helper.get_child(cfg, "filter") or
local unit_filter = wml.get_child(cfg, "filter") or
helper.wml_error "[store_reachable_locations] missing required [filter] tag"
local location_filter = helper.get_child(cfg, "filter_location")
local location_filter = wml.get_child(cfg, "filter_location")
local range = cfg.range or "movement"
local moves = cfg.moves or "current"
local variable = cfg.variable or helper.wml_error "[store_reachable_locations] missing required variable= key"
@ -497,7 +497,7 @@ end
function wml_actions.capture_village(cfg)
local side = cfg.side
local filter_side = helper.get_child(cfg, "filter_side")
local filter_side = wml.get_child(cfg, "filter_side")
local fire_event = cfg.fire_event
if side then side = tonumber(side) or helper.wml_error("invalid side in [capture_village]") end
if filter_side then
@ -514,7 +514,7 @@ end
function wml_actions.terrain(cfg)
local terrain = cfg.terrain or helper.wml_error("[terrain] missing required terrain= attribute")
cfg = helper.shallow_parsed(cfg)
cfg = wml.shallow_parsed(cfg)
cfg.terrain = nil
for i, loc in ipairs(wesnoth.get_locations(cfg)) do
wesnoth.set_terrain(loc[1], loc[2], terrain, cfg.layer, cfg.replace_if_failed)
@ -574,7 +574,7 @@ function wml_actions.transform_unit(cfg)
local hitpoints = unit.hitpoints
local experience = unit.experience
local recall_cost = unit.recall_cost
local status = helper.get_child( unit.__cfg, "status" )
local status = wml.get_child( unit.__cfg, "status" )
unit.experience = unit.max_experience
wesnoth.advance_unit(unit, false, false)
@ -609,7 +609,7 @@ function wml_actions.store_side(cfg)
end
function wml_actions.add_ai_behavior(cfg)
local unit = wesnoth.get_units(helper.get_child(cfg, "filter"))[1] or
local unit = wesnoth.get_units(wml.get_child(cfg, "filter"))[1] or
helper.wml_error("[add_ai_behavior]: no unit specified")
local side = cfg.side or
@ -790,7 +790,7 @@ function wml_actions.inspect(cfg)
end
function wml_actions.label( cfg )
local new_cfg = helper.parsed( cfg )
local new_cfg = wml.parsed( cfg )
for index, location in ipairs( wesnoth.get_locations( cfg ) ) do
new_cfg.x, new_cfg.y = location[1], location[2]
wesnoth.label( new_cfg )
@ -871,7 +871,7 @@ end
wml_actions.teleport = function(cfg)
local context = wesnoth.current.event_context
local filter = helper.get_child(cfg, "filter") or { x = context.x1, y = context.y1 }
local filter = wml.get_child(cfg, "filter") or { x = context.x1, y = context.y1 }
local unit = wesnoth.get_units(filter)[1]
if not unit then
-- No error if no unit matches.
@ -902,7 +902,7 @@ end
local function parse_fog_cfg(cfg)
-- Side filter
local ssf = helper.get_child(cfg, "filter_side")
local ssf = wml.get_child(cfg, "filter_side")
local sides = wesnoth.get_sides(ssf or {})
-- Location filter
local locs = wesnoth.get_locations(cfg)

View file

@ -53,7 +53,7 @@ end
function utils.get_sides(cfg, key_name, filter_name)
key_name = key_name or "side"
filter_name = filter_name or "filter_side"
local filter = helper.get_child(cfg, filter_name)
local filter = wml.get_child(cfg, filter_name)
if filter then
if cfg[key_name] then
wesnoth.log('warn', "ignoring duplicate side filter information (inline side=)")
@ -67,7 +67,7 @@ end
function utils.optional_side_filter(cfg, key_name, filter_name)
key_name = key_name or "side"
filter_name = filter_name or "filter_side"
if cfg[key_name] == nil and helper.get_child(cfg, filter_name) == nil then
if cfg[key_name] == nil and wml.get_child(cfg, filter_name) == nil then
return true
end
local sides = utils.get_sides(cfg, key_name, filter_name)
@ -108,7 +108,7 @@ function utils.handle_event_commands(cfg, scope_type)
-- the execution, hence the manual handling of [insert_tag].
scope_type = scope_type or "plain"
scope_stack:push(scope_type)
local cmds = helper.shallow_literal(cfg)
local cmds = wml.shallow_literal(cfg)
for i = 1,#cmds do
local v = cmds[i]
local cmd = v[1]
@ -192,7 +192,7 @@ end
--note: when using these, make sure that nothing can throw over the call to end_var_scope
function utils.start_var_scope(name)
local var = helper.get_variable_array(name) --containers and arrays
local var = wml.variable.get_array(name) --containers and arrays
if #var == 0 then var = wesnoth.get_variable(name) end --scalars (and nil/empty)
wesnoth.set_variable(name)
return var
@ -201,7 +201,7 @@ end
function utils.end_var_scope(name, var)
wesnoth.set_variable(name)
if type(var) == "table" then
helper.set_variable_array(name, var)
wml.variable.set_array(name, var)
else
wesnoth.set_variable(name, var)
end

View file

@ -1,10 +1,10 @@
local helper = wesnoth.require "helper"
local T = helper.set_wml_tag_metatable{}
local T = wml.tag
local function add_animation(anim, cfg)
cfg = helper.shallow_parsed(cfg)
cfg = wml.shallow_parsed(cfg)
local flag = cfg.flag or helper.wml_error("[animate_unit] is missing flag")
local filter = helper.get_child(cfg, "filter")
local filter = wml.get_child(cfg, "filter")
local unit
if filter then
unit = wesnoth.get_units{
@ -19,8 +19,8 @@ local function add_animation(anim, cfg)
end
if unit and not wesnoth.is_fogged(wesnoth.current.side, unit.x, unit.y) then
local primary = helper.get_child(cfg, "primary_attack")
local secondary = helper.get_child(cfg, "secondary_attack")
local primary = wml.get_child(cfg, "primary_attack")
local secondary = wml.get_child(cfg, "secondary_attack")
-- We don't have access to the secondary unit at this point.
-- Thus, for the secondary attack, we just create a dummy attack
-- which exactly matches the filter.
@ -71,7 +71,7 @@ local function add_animation(anim, cfg)
-- (should make the game not scroll if view locked or prefs disables it)
wesnoth.scroll_to_tile(unit.x, unit.y, true, false, true, false)
local facing = helper.get_child(cfg, "facing")
local facing = wml.get_child(cfg, "facing")
if facing then
local facing_loc = wesnoth.get_locations(facing)[1]
if facing_loc then
@ -101,7 +101,7 @@ local function add_animation(anim, cfg)
})
end
for c in helper.child_range(cfg, "animate") do
for c in wml.child_range(cfg, "animate") do
add_animation(anim, c)
end
end

View file

@ -3,7 +3,7 @@ local utils = wesnoth.require "wml-utils"
local already_ended = false
function wesnoth.wml_actions.endlevel(cfg)
local parsed = helper.parsed(cfg)
local parsed = wml.parsed(cfg)
if already_ended then
wesnoth.message("Repeated [endlevel] execution, ignoring")
return
@ -27,7 +27,7 @@ function wesnoth.wml_actions.endlevel(cfg)
end
local side_results = {}
for result in helper.child_range(parsed, "result") do
for result in wml.child_range(parsed, "result") do
local side = result.side or helper.wml_error("[result] in [endlevel] missing required side= key")
side_results[side] = result
end

View file

@ -2,10 +2,10 @@ local helper = wesnoth.require "helper"
local utils = wesnoth.require "wml-utils"
function wesnoth.wml_actions.find_path(cfg)
local filter_unit = helper.get_child(cfg, "traveler") or helper.wml_error("[find_path] missing required [traveler] tag")
local filter_unit = wml.get_child(cfg, "traveler") or helper.wml_error("[find_path] missing required [traveler] tag")
-- only the first unit matching
local unit = wesnoth.get_units(filter_unit)[1] or helper.wml_error("[find_path]'s filter didn't match any unit")
local filter_location = helper.get_child(cfg, "destination") or helper.wml_error( "[find_path] missing required [destination] tag" )
local filter_location = wml.get_child(cfg, "destination") or helper.wml_error( "[find_path] missing required [destination] tag" )
-- support for $this_unit
local this_unit = utils.start_var_scope("this_unit")

View file

@ -1,12 +1,12 @@
local helper = wesnoth.require "helper"
local utils = wesnoth.require "wml-utils"
local wml_actions = wesnoth.wml_actions
local T = helper.set_wml_tag_metatable {}
local T = wml.tag
function wml_actions.harm_unit(cfg)
local filter = helper.get_child(cfg, "filter") or helper.wml_error("[harm_unit] missing required [filter] tag")
local filter = wml.get_child(cfg, "filter") or helper.wml_error("[harm_unit] missing required [filter] tag")
-- we need to use shallow_literal field, to avoid raising an error if $this_unit (not yet assigned) is used
if not helper.shallow_literal(cfg).amount then helper.wml_error("[harm_unit] has missing required amount= attribute") end
if not wml.shallow_literal(cfg).amount then helper.wml_error("[harm_unit] has missing required amount= attribute") end
local variable = cfg.variable -- kept out of the way to avoid problems
local _ = wesnoth.textdomain "wesnoth"
-- #textdomain wesnoth
@ -31,9 +31,9 @@ function wml_actions.harm_unit(cfg)
local delay = cfg.delay or 500
local kill = cfg.kill
local fire_event = cfg.fire_event
local primary_attack = helper.get_child(cfg, "primary_attack")
local secondary_attack = helper.get_child(cfg, "secondary_attack")
local harmer_filter = helper.get_child(cfg, "filter_second")
local primary_attack = wml.get_child(cfg, "primary_attack")
local secondary_attack = wml.get_child(cfg, "secondary_attack")
local harmer_filter = wml.get_child(cfg, "filter_second")
local experience = cfg.experience
local resistance_multiplier = tonumber(cfg.resistance_multiplier) or 1
if harmer_filter then harmer = wesnoth.get_units(harmer_filter)[1] end

View file

@ -1,8 +1,7 @@
local helper = wesnoth.require "helper"
local T = helper.set_wml_tag_metatable {}
local T = wml.tag
function wesnoth.wml_actions.heal_unit(cfg)
local healers = helper.get_child(cfg, "filter_second")
local healers = wml.get_child(cfg, "filter_second")
if healers then
healers = wesnoth.get_units{
ability_type = "heals",
@ -12,7 +11,7 @@ function wesnoth.wml_actions.heal_unit(cfg)
healers = {}
end
local who = helper.get_child(cfg, "filter")
local who = wml.get_child(cfg, "filter")
if who then
who = wesnoth.get_units(who)
else

View file

@ -73,7 +73,7 @@ end
function wml_actions.item(cfg)
local locs = wesnoth.get_locations(cfg)
cfg = helper.parsed(cfg)
cfg = wml.parsed(cfg)
if not cfg.name then
cfg.name = "item_" .. tostring(next_item_name)
next_item_name = next_item_name + 1

View file

@ -5,7 +5,7 @@ local kill_recursion_preventer = location_set.create()
function wesnoth.wml_actions.kill(cfg)
local number_killed = 0
local secondary_unit = helper.get_child(cfg, "secondary_unit")
local secondary_unit = wml.get_child(cfg, "secondary_unit")
local killer_loc = {0, 0}
if secondary_unit then
secondary_unit = wesnoth.get_units(secondary_unit)[1]
@ -44,8 +44,8 @@ function wesnoth.wml_actions.kill(cfg)
if cfg.animate and unit.valid == "map" then
wesnoth.scroll_to_tile(death_loc)
local anim = wesnoth.create_animator()
local primary = helper.get_child(cfg, "primary_attack")
local secondary = helper.get_child(cfg, "secondary_attack")
local primary = wml.get_child(cfg, "primary_attack")
local secondary = wml.get_child(cfg, "secondary_attack")
-- Yes, we get the primary attack from the secondary unit and vice versa
-- The primary attack in a death animation is the weapon that caused the death
-- In other words, the attacker's weapon. The attacker is the secondary unit.

View file

@ -273,7 +273,7 @@ local function message_user_choice(cfg, speaker, options, text_input, sound, voi
end
function wesnoth.wml_actions.message(cfg)
local show_if = helper.get_child(cfg, "show_if") or {}
local show_if = wml.get_child(cfg, "show_if") or {}
if not wesnoth.eval_conditional(show_if) then
log("[message] skipped because [show_if] did not pass", "debug")
return
@ -281,7 +281,7 @@ function wesnoth.wml_actions.message(cfg)
-- Only the first text_input tag is considered
local text_input
for text_input_cfg in helper.child_range(cfg, "text_input") do
for text_input_cfg in wml.child_range(cfg, "text_input") do
if text_input ~= nil then
log("Too many [text_input] tags, only first one accepted", "warning")
break
@ -290,8 +290,8 @@ function wesnoth.wml_actions.message(cfg)
end
local options, option_events = {}, {}
for option in helper.child_range(cfg, "option") do
local condition = helper.get_child(option, "show_if") or {}
for option in wml.child_range(cfg, "option") do
local condition = wml.get_child(option, "show_if") or {}
if wesnoth.eval_conditional(condition) then
if option.message and not option.image and not option.label then
@ -320,7 +320,7 @@ function wesnoth.wml_actions.message(cfg)
end
table.insert(option_events, {})
for cmd in helper.child_range(option, "command") do
for cmd in wml.child_range(option, "command") do
table.insert(option_events[#option_events], cmd)
end
end

View file

@ -9,11 +9,11 @@ function wesnoth.wml_actions.modify_ai(cfg)
final = start and (string.find(cfg.path, '[', start, true) - 1) or -1
start = start or string.find(cfg.path, "[^.]*$") or 1
local comp_type = string.sub(cfg.path, start, final)
component = helper.get_child(cfg, comp_type)
component = wml.get_child(cfg, comp_type)
if component == nil then
helper.wml_error("Missing component definition in [modify_ai]")
end
component = helper.parsed(component)
component = wml.parsed(component)
end
for i = 1, #sides do
if cfg.action == "add" then

View file

@ -1,6 +1,5 @@
local helper = wesnoth.require "helper"
local utils = wesnoth.require "wml-utils"
local T = helper.set_wml_tag_metatable {}
local T = wml.tag
local side_changes_needing_redraw = {
'shroud', 'fog', 'reset_map', 'reset_view', 'shroud_data',
@ -96,7 +95,7 @@ function wesnoth.wml_actions.modify_side(cfg)
wesnoth.switch_ai(side.side, cfg.switch_ai)
end
local ai, replace_ai = {}, false
for next_ai in helper.child_range(cfg, "ai") do
for next_ai in wml.child_range(cfg, "ai") do
table.insert(ai, T.ai(next_ai))
if next_ai.ai_algorithm then
replace_ai = true

View file

@ -8,7 +8,7 @@ function wml_actions.modify_unit(cfg)
local replace_mode = cfg.mode == "replace"
local function handle_attributes(cfg, unit_path, toplevel)
for current_key, current_value in pairs(helper.shallow_parsed(cfg)) do
for current_key, current_value in pairs(wml.shallow_parsed(cfg)) do
if type(current_value) ~= "table" and (not toplevel or (current_key ~= "type" and current_key ~= "mode")) then
wesnoth.set_variable(string.format("%s.%s", unit_path, current_key), current_value)
end
@ -17,7 +17,7 @@ function wml_actions.modify_unit(cfg)
local function handle_child(cfg, unit_path)
local children_handled = {}
local cfg = helper.shallow_parsed(cfg)
local cfg = wml.shallow_parsed(cfg)
handle_attributes(cfg, unit_path)
for current_index, current_table in ipairs(cfg) do
@ -29,7 +29,7 @@ function wml_actions.modify_unit(cfg)
end
end
local filter = helper.get_child(cfg, "filter") or helper.wml_error "[modify_unit] missing required [filter] tag"
local filter = wml.get_child(cfg, "filter") or helper.wml_error "[modify_unit] missing required [filter] tag"
local function handle_unit(unit_num)
local children_handled = {}
local unit_path = string.format("%s[%u]", unit_variable, unit_num)
@ -37,16 +37,16 @@ function wml_actions.modify_unit(cfg)
wesnoth.set_variable("this_unit", this_unit)
handle_attributes(cfg, unit_path, true)
for current_index, current_table in ipairs(helper.shallow_parsed(cfg)) do
for current_index, current_table in ipairs(wml.shallow_parsed(cfg)) do
local current_tag = current_table[1]
if current_tag == "filter" then
-- nothing
elseif current_tag == "object" or current_tag == "trait" or current_tag == "advancement" then
local mod = current_table[2]
if mod.delayed_variable_substitution then
mod = helper.literal(mod)
mod = wml.literal(mod)
else
mod = helper.parsed(mod)
mod = wml.parsed(mod)
end
local unit = wesnoth.get_variable(unit_path)
unit = wesnoth.create_unit(unit)

View file

@ -8,7 +8,7 @@ function wesnoth.wml_actions.move_unit(cfg)
local muf_force_scroll = cfg.force_scroll
local check_passability = cfg.check_passability
if check_passability == nil then check_passability = true end
cfg = helper.literal(cfg)
cfg = wml.literal(cfg)
cfg.to_x, cfg.to_y, cfg.fire_event = nil, nil, nil
local units = wesnoth.get_units(cfg)

View file

@ -1,7 +1,6 @@
local helper = wesnoth.require "helper"
local utils = wesnoth.require "wml-utils"
local T = helper.set_wml_tag_metatable {}
local T = wml.tag
local wml_actions = wesnoth.wml_actions
local used_items = {}
@ -17,7 +16,7 @@ function wml_actions.object(cfg)
local unit, command_type, text
local filter = helper.get_child(cfg, "filter")
local filter = wml.get_child(cfg, "filter")
if filter then
unit = wesnoth.get_units(filter)[1]
else
@ -46,9 +45,9 @@ function wml_actions.object(cfg)
local dvs = cfg.delayed_variable_substitution
local add = cfg.no_write ~= true
if dvs then
wesnoth.add_modification(unit, "object", helper.literal(cfg), add)
wesnoth.add_modification(unit, "object", wml.literal(cfg), add)
else
wesnoth.add_modification(unit, "object", helper.parsed(cfg), add)
wesnoth.add_modification(unit, "object", wml.parsed(cfg), add)
end
if not silent then
@ -66,7 +65,7 @@ function wml_actions.object(cfg)
wesnoth.show_popup_dialog(name, text, cfg.image)
end
for cmd in helper.child_range(cfg, command_type) do
for cmd in wml.child_range(cfg, command_type) do
local action = utils.handle_event_commands(cmd, "conditional")
if action ~= "none" then break end
end

View file

@ -1,4 +1,3 @@
local helper = wesnoth.require "helper"
local wml_actions = wesnoth.wml_actions
local game_events = wesnoth.game_events
@ -54,8 +53,8 @@ local function generate_objectives(cfg)
local bullet = cfg.bullet or "• "
for obj in helper.child_range(cfg, "objective") do
local show_if = helper.get_child(obj, "show_if")
for obj in wml.child_range(cfg, "objective") do
local show_if = wml.get_child(obj, "show_if")
if not show_if or wesnoth.eval_conditional(show_if) then
local objective_bullet = obj.bullet or bullet
local condition = obj.condition
@ -106,8 +105,8 @@ local function generate_objectives(cfg)
end
end
for obj in helper.child_range(cfg, "gold_carryover") do
local show_if = helper.get_child(obj, "show_if")
for obj in wml.child_range(cfg, "gold_carryover") do
local show_if = wml.get_child(obj, "show_if")
if not show_if or wesnoth.eval_conditional(show_if) then
local gold_carryover_bullet = obj.bullet or bullet
local r = obj.red or 255
@ -140,8 +139,8 @@ local function generate_objectives(cfg)
end
end
for note in helper.child_range(cfg, "note") do
local show_if = helper.get_child(note, "show_if")
for note in wml.child_range(cfg, "note") do
local show_if = wml.get_child(note, "show_if")
if not show_if or wesnoth.eval_conditional(show_if) then
local note_bullet = note.bullet or bullet
local r = note.red or 255
@ -191,7 +190,7 @@ end
function wml_actions.objectives(cfg)
if cfg.delayed_variable_substitution ~= true then
cfg = helper.parsed(cfg)
cfg = wml.parsed(cfg)
end
local sides_cfg = wesnoth.get_sides(cfg)
@ -199,7 +198,7 @@ function wml_actions.objectives(cfg)
local objectives = generate_objectives(cfg)
local function set_objectives(sides, save)
local cfg2 = helper.literal(cfg)
local cfg2 = wml.literal(cfg)
remove_ssf_info_from(cfg2)
for i, team in ipairs(sides) do
if save then scenario_objectives[team.side] = cfg2 end
@ -208,7 +207,7 @@ function wml_actions.objectives(cfg)
end
end
if #sides_cfg == #wesnoth.sides or #sides_cfg == 0 then
scenario_objectives[0] = helper.literal(cfg)
scenario_objectives[0] = wml.literal(cfg)
remove_ssf_info_from(scenario_objectives[0])
set_objectives(wesnoth.sides)
else

View file

@ -2,10 +2,10 @@ local helper = wesnoth.require "helper"
local utils = wesnoth.require "wml-utils"
wesnoth.wml_actions.random_placement = function(cfg)
local parsed = helper.shallow_parsed(cfg)
local parsed = wml.shallow_parsed(cfg)
-- TODO: In most cases this tag is used to place units, so maybe make include_borders=no the default for [filter_location]?
local filter = helper.get_child(parsed, "filter_location") or {}
local command = helper.get_child(parsed, "command") or helper.wml_error("[random_placement] missing required [command] subtag")
local filter = wml.get_child(parsed, "filter_location") or {}
local command = wml.get_child(parsed, "command") or helper.wml_error("[random_placement] missing required [command] subtag")
local distance = cfg.min_distance or 0
local num_items = cfg.num_items or helper.wml_error("[random_placement] missing required 'num_items' attribute")
local variable = cfg.variable or helper.wml_error("[random_placement] missing required 'variable' attribute")

View file

@ -5,7 +5,7 @@ function wesnoth.wml_actions.role(cfg)
-- role= and type= are handled differently than in other tags,
-- so we need to remove them from the filter
local role = cfg.role
local filter = helper.shallow_literal(cfg)
local filter = wml.shallow_literal(cfg)
if role == nil then
helper.wml_error("missing role= in [role]")
@ -35,12 +35,12 @@ function wesnoth.wml_actions.role(cfg)
-- the SUF will be id= which we will add in a moment
-- keep this in sync with the C++ recall function!!!
local recall = nil
local child = helper.get_child(cfg, "auto_recall")
local child = wml.get_child(cfg, "auto_recall")
if child ~= nil then
if helper.get_nth_child(cfg, "auto_recall", 2) ~= nil then
if wml.get_nth_child(cfg, "auto_recall", 2) ~= nil then
wesnoth.log("debug", "More than one [auto_recall] found within [role]", true)
end
local original = helper.shallow_literal(child)
local original = wml.shallow_literal(child)
recall = {}
recall.x = original.x
recall.y = original.y
@ -104,7 +104,7 @@ function wesnoth.wml_actions.role(cfg)
end
-- no matching unit found, try the [else] tags
for else_child in helper.child_range(cfg, "else") do
for else_child in wml.child_range(cfg, "else") do
local action = utils.handle_event_commands(else_child, "conditional")
if action ~= "none" then return end
end

View file

@ -8,7 +8,7 @@ function wesnoth.wml_actions.set_variable(cfg)
end
if cfg.literal ~= nil then
wesnoth.set_variable(name, helper.shallow_literal(cfg).literal)
wesnoth.set_variable(name, wml.shallow_literal(cfg).literal)
end
if cfg.to_variable then
@ -111,7 +111,7 @@ function wesnoth.wml_actions.set_variable(cfg)
wesnoth.set_variable(name, fcn(wesnoth.get_variable(name)))
end
local join_child = helper.get_child(cfg, "join")
local join_child = wml.get_child(cfg, "join")
if join_child then
local array_name = join_child.variable or helper.wml_error "missing variable= attribute in [join]"
local separator = join_child.separator
@ -120,7 +120,7 @@ function wesnoth.wml_actions.set_variable(cfg)
local string_to_join = ''
for i, element in ipairs(helper.get_variable_array(array_name)) do
for i, element in ipairs(wml.variable.get_array(array_name)) do
if element[key_name] ~= nil or (not remove_empty) then
if #string_to_join > 0 then
string_to_join = string_to_join .. separator

View file

@ -1,5 +1,3 @@
local helper = wesnoth.require "helper"
-- This function returns true if it managed to explain the failure
local function explain(current_cfg, expect, logger)
for i,t in ipairs(current_cfg) do
@ -27,7 +25,7 @@ local function explain(current_cfg, expect, logger)
for k,v in pairs(this_cfg) do
if type(k) ~= "number" then
local format = "%s\n\t\t%s=%s"
local literal = tostring(helper.literal(this_cfg)[k])
local literal = tostring(wml.literal(this_cfg)[k])
if literal ~= v then
format = format .. "=%s"
end