Lua API: Add wesnoth.sides.iter

This replaces both helper.get_sides and helper.all_teams
This commit is contained in:
Celtic Minstrel 2021-07-04 15:58:21 -04:00 committed by Celtic Minstrel
parent 1e42f80c13
commit 47951c4700
2 changed files with 16 additions and 0 deletions

View File

@ -17,6 +17,20 @@ if wesnoth.kernel_type() == "Game Lua Kernel" then
}
setmetatable(wesnoth.sides, sides_mt)
function wesnoth.sides.iter(filter)
local function f(s)
local i = s.i
while i < #wesnoth.sides do
i = i + 1
if filter == nil or wesnoth.sides.matches(i, filter) then
s.i = i
return wesnoth.sides[i], i
end
end
end
return f, { i = 0 }
end
-- Deprecated functions
function wesnoth.set_side_variable(side, var, val)
wesnoth.sides[side].variables[var] = val

View File

@ -112,5 +112,7 @@ helper.get_user_choice = wesnoth.deprecate_api('helper.get_user_choice', 'gui.ge
helper.rand = wesnoth.deprecate_api('helper.rand', 'mathx.random_choice', 1, nil, mathx.random_choice)
helper.round = wesnoth.deprecate_api('helper.round', 'mathx.round', 1, nil, mathx.round)
helper.shuffle = wesnoth.deprecate_api('helper.shuffle', 'mathx.shuffle', 1, nil, mathx.shuffle)
helper.all_teams = wesnoth.deprecate_api('helper.all_teams', 'wesnoth.sides.iter', 1, nil, helper.all_teams)
helper.get_sides = wesnoth.deprecate_api('helper.get_sides', 'wesnoth.sides.iter', 1, nil, helper.get_sides)
return helper