Skip to content

Commit

Permalink
Lua API: Add wesnoth.sides.iter
Browse files Browse the repository at this point in the history
This replaces both helper.get_sides and helper.all_teams
  • Loading branch information
CelticMinstrel committed Jul 6, 2021
1 parent 3e469df commit 2fdf3de
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
14 changes: 14 additions & 0 deletions data/lua/core/sides.lua
Expand Up @@ -16,6 +16,20 @@ if wesnoth.kernel_type() == "Game Lua Kernel" then
end
}
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)
Expand Down
2 changes: 2 additions & 0 deletions data/lua/helper.lua
Expand Up @@ -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

0 comments on commit 2fdf3de

Please sign in to comment.