Replace uses of wml_utils.split with stringx.split

This commit is contained in:
Celtic Minstrel 2019-12-04 08:46:04 -05:00
parent 31467d29d7
commit d9b5e3c4df
9 changed files with 29 additions and 48 deletions

View file

@ -24,7 +24,7 @@ end
local function on_event(eventname, arg1, arg2)
if string.match(eventname, ",") then
for elem in utils.split(eventname or "") do
for _,elem in ipairs((eventname or ""):split()) do
on_event(elem, arg1, arg2)
end
return

View file

@ -240,7 +240,7 @@ function wml_actions.switch(cfg)
-- Execute all the [case]s where the value matches.
for v in wml.child_range(cfg, "case") do
for w in utils.split(v.value) do
for _,w in ipairs(v.value:split()) do
if w == tostring(var_value) then
local action = utils.handle_event_commands(v, "switch")
found = true

View file

@ -24,7 +24,7 @@ function wml_actions.sync_variable(cfg)
local result = wesnoth.synchronize_choice(
function()
local res = {}
for name_raw in utils.split(names) do
for _,name_raw in ipairs(names:split()) do
local name = name_raw:trim()
local variable_type = string.sub(name, string.len(name)) == "]" and "indexed" or ( wml.variables[name .. ".length"] > 0 and "array" or "attribute")
local variable_info = { name = name, type = variable_type }
@ -109,7 +109,7 @@ function wml_actions.clear_variable(cfg, variables)
local names = cfg.name or
wml.error "[clear_variable] missing required name= attribute."
if variables == nil then variables = wml.variables end
for w in utils.split(names) do
for _,w in ipairs(names:split()) do
variables[w:trim()] = nil
end
end
@ -128,7 +128,7 @@ function wml_actions.store_unit_type(cfg)
local types = cfg.type or
wml.error "[store_unit_type] missing required type= attribute."
local writer = utils.vwriter.init(cfg, "unit_type")
for w in utils.split(types) do
for _,w in ipairs(types:split()) do
local unit_type = wesnoth.unit_types[w] or
wml.error(string.format("Attempt to store nonexistent unit type '%s'.", w))
utils.vwriter.write(writer, unit_type.__cfg)
@ -159,7 +159,7 @@ function wml_actions.allow_recruit(cfg)
local unit_types = cfg.type or wml.error("[allow_recruit] missing required type= attribute")
for index, team in ipairs(wesnoth.sides.find(cfg)) do
local v = team.recruit
for type in utils.split(unit_types) do
for _,type in ipairs(unit_types:split()) do
table.insert(v, type)
wesnoth.add_known_unit(type)
end
@ -171,7 +171,7 @@ function wml_actions.allow_extra_recruit(cfg)
local recruits = cfg.extra_recruit or wml.error("[allow_extra_recruit] missing required extra_recruit= attribute")
for index, unit in ipairs(wesnoth.units.find_on_map(cfg)) do
local v = unit.extra_recruit
for recruit in utils.split(recruits) do
for _,recruit in iapirs(recruits:split()) do
table.insert(v, recruit)
wesnoth.add_known_unit(recruit)
end
@ -184,7 +184,7 @@ function wml_actions.disallow_recruit(cfg)
for index, team in ipairs(wesnoth.sides.find(cfg)) do
if unit_types then
local v = team.recruit
for w in utils.split(unit_types) do
for _,w in ipairs(unit_types:split()) do
for i, r in ipairs(v) do
if r == w then
table.remove(v, i)
@ -203,7 +203,7 @@ function wml_actions.disallow_extra_recruit(cfg)
local recruits = cfg.extra_recruit or wml.error("[disallow_extra_recruit] missing required extra_recruit= attribute")
for index, unit in ipairs(wesnoth.units.find_on_map(cfg)) do
local v = unit.extra_recruit
for w in utils.split(recruits) do
for _,w in ipairs(recruits:split()) do
for i, r in ipairs(v) do
if r == w then
table.remove(v, i)
@ -218,21 +218,13 @@ end
function wml_actions.set_recruit(cfg)
local recruit = cfg.recruit or wml.error("[set_recruit] missing required recruit= attribute")
for index, team in ipairs(wesnoth.sides.find(cfg)) do
local v = {}
for w in utils.split(recruit) do
table.insert(v, w)
end
team.recruit = v
team.recruit = recruit:split()
end
end
function wml_actions.set_extra_recruit(cfg)
local recruits = cfg.extra_recruit or wml.error("[set_extra_recruit] missing required extra_recruit= attribute")
local v = {}
for w in utils.split(recruits) do
table.insert(v, w)
end
local v = recruits:split()
for index, unit in ipairs(wesnoth.units.find_on_map(cfg)) do
unit.extra_recruit = v
@ -254,7 +246,7 @@ function wml_actions.unit_worth(cfg)
local hp = u.hitpoints / u.max_hitpoints
local xp = u.experience / u.max_experience
local best_adv = ut.cost
for w in utils.split(ut.__cfg.advances_to) do
for _,w in ipairs(ut.advances_to) do
local uta = wesnoth.unit_types[w]
if uta and uta.cost > best_adv then best_adv = uta.cost end
end
@ -742,7 +734,7 @@ end
function wml_actions.remove_time_area(cfg)
local id = cfg.id or wml.error("[remove_time_area] missing required id= key")
for w in utils.split(id) do
for _,w in ipairs(id:split()) do
wesnoth.remove_time_area(w)
end
end
@ -783,7 +775,7 @@ end
function wml_actions.remove_event(cfg)
local id = cfg.id or wml.error("[remove_event] missing required id= key")
for w in utils.split(id) do
for _,w in ipairs(id:split()) do
wesnoth.remove_event_handler(w)
end
end
@ -892,7 +884,7 @@ end
function wml_actions.remove_sound_source(cfg)
local ids = cfg.id or wml.error("[remove_sound_source] missing required id= attribute")
for id in utils.split(ids) do
for _,id in ipairs(ids:split()) do
wesnoth.remove_sound_source(id)
end
end

View file

@ -85,10 +85,7 @@ function wesnoth.wml_actions.endlevel(cfg)
local victory = there_is_a_local_human_victory or (not there_is_a_local_human_defeat and proceed_to_next_level)
if cfg.music then
local music = {}
for track in utils.split(cfg.music) do
table.insert(music, track)
end
local music = cfg.music:split()
if victory then
wesnoth.game_config.victory_music = music
else

View file

@ -382,7 +382,7 @@ function wesnoth.wml_actions.message(cfg)
local show_for_side = false
-- Sanity checks on side number and controller
for side in utils.split(sides_for) do
for _,side in ipairs(tostring(sides_for):split()) do
side = tonumber(side)
if side > 0 and side <= #wesnoth.sides
and wesnoth.sides[side].controller == "human"

View file

@ -26,11 +26,7 @@ function wesnoth.wml_actions.modify_side(cfg)
side.defeat_condition = cfg.defeat_condition
end
if cfg.recruit then
local recruits = {}
for recruit in utils.split(cfg.recruit) do
table.insert(recruits, recruit)
end
side.recruit = recruits
side.recruit = cfg.recruit:split()
end
if cfg.village_support then
side.village_support = cfg.village_support

View file

@ -6,16 +6,6 @@ local wml_actions = wesnoth.wml_actions
-- in the first part of this file and the fallback (old) implementation in the
-- second part of this file
local function split_to_array(str)
-- Split string @str into a table using the delimiter @sep (default: ',')
local fields = {}
for c in utils.split(str) do
fields[#fields+1] = c
end
return fields
end
local function make_set(t)
local res = {}
for i, v in ipairs(t) do
@ -125,7 +115,7 @@ local function simple_modify_unit(cfg)
u["goto"] = { cfg.goto_x or u["goto"][1] , cfg.goto_y or u["goto"][2] }
end
if cfg.extra_recruit then
u.extra_recruit = split_to_array(cfg.extra_recruit)
u.extra_recruit = cfg.extra_recruit:split()
end
if cfg.ai_special == "guardian" then
u.status.guardian = true

View file

@ -5,7 +5,7 @@ local function path_locs(path)
-- Index is 1 for x, 2 for y
local function special_locations(index)
return function()
for loc in utils.split(path.location_id) do
for _,loc in ipairs(tostring(path.location_id):split()) do
loc = wesnoth.special_locations[loc]
if loc then coroutine.yield(loc[index]) end
end
@ -18,7 +18,7 @@ local function path_locs(path)
local function relative_locations(index)
return function(u)
local last = {x = u.x, y = u.y}
for dir in utils.split(cfg.dir) do
for _,dir in ipairs(cfg.dir:split()) do
local count = 1
if dir:find(":") then
local error_dir = dir
@ -34,7 +34,13 @@ local function path_locs(path)
end
end
else
return utils.split(path.to_x), utils.split(path.to_y)
-- Index is 1 for x, 2 for y
local function abs_locations(coord)
for _,s in tostring(path[coord]):split() do
coroutine.yield(tonumber(s))
end
end
return coroutine.wrap(abs_locations('to_x')), coroutine.wrap(abs_locations('to_y'))
end
end

View file

@ -13,7 +13,7 @@ function wesnoth.wml_actions.role(cfg)
local types = {}
if cfg.type then
for value in utils.split(cfg.type) do
for _,value in ipairs(cfg.type:split()) do
table.insert(types, value:trim())
end
end