From b4de3df0fc357a8cda76d7fda1ccca12c5b95aba Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Mon, 22 Feb 2021 22:11:58 -0500 Subject: [PATCH] Move WC's filter tag helpers into core --- .../lua/map/postgeneration_utils/engine.lua | 36 +-------------- data/lua/core/map.lua | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+), 35 deletions(-) diff --git a/data/campaigns/World_Conquest/lua/map/postgeneration_utils/engine.lua b/data/campaigns/World_Conquest/lua/map/postgeneration_utils/engine.lua index e629c1bfb32c..88f8b0c85353 100644 --- a/data/campaigns/World_Conquest/lua/map/postgeneration_utils/engine.lua +++ b/data/campaigns/World_Conquest/lua/map/postgeneration_utils/engine.lua @@ -1,40 +1,6 @@ -- helper functions for lua map generation. -f = { - terrain = function(terrain) - return { "terrain", terrain } - end, - all = function(...) - return { "all", ... } - end, - any = function(...) - return { "any", ... } - end, - none = function(...) - return { "none", ... } - end, - notall = function(...) - return { "notall", ... } - end, - adjacent = function(f, ad, count) - return { "adjacent", f, adjacent = ad, count = count } - end, - find_in = function(terrain) - return { "find_in", terrain } - end, - radius = function(r, f, f_r) - return { "radius", r, f, filter_radius = f_r} - end, - x = function(terrain) - return { "x", terrain } - end, - y = function(terrain) - return { "y", terrain } - end, - is_loc = function(loc) - return f.all(f.x(loc[1]), f.y(loc[2])) - end -} +f = wesnoth.map.filter_tags function get_locations(t) local filter = wesnoth.map.filter(t.filter, t.filter_extra or {}) diff --git a/data/lua/core/map.lua b/data/lua/core/map.lua index 88ffaf03c252..82809e882873 100644 --- a/data/lua/core/map.lua +++ b/data/lua/core/map.lua @@ -253,6 +253,51 @@ if wesnoth.kernel_type() == "Game Lua Kernel" then end if wesnoth.kernel_type() == "Mapgen Lua Kernel" then + -- Filter support + local filter_tags = { + terrain = function(terrain) + return { "terrain", terrain } + end, + all = function(...) + return { "all", ... } + end, + any = function(...) + return { "any", ... } + end, + none = function(...) + return { "none", ... } + end, + notall = function(...) + return { "notall", ... } + end, + adjacent = function(f, ad, count) + return { "adjacent", f, adjacent = ad, count = count } + end, + find_in = function(terrain) + return { "find_in", terrain } + end, + radius = function(r, f, f_r) + return { "radius", r, f, filter_radius = f_r} + end, + x = function(terrain) + return { "x", terrain } + end, + y = function(terrain) + return { "y", terrain } + end, + is_loc = function(loc) + return filter_tags.all(f.x(loc[1]), f.y(loc[2])) + end, + formula = function(f) + return { "formula", f} + end, + } + + wesnoth.map.filter_tags = setmetatable({}, { + __index = function(_, k) return filter_tags[k] end, + __newindex = function() error('wesnoth.map.filter_tags is read-only') end, + }) + -- More map module stuff wesnoth.create_filter = wesnoth.deprecate_api('wesnoth.create_filter', 'wesnoth.map.filter', 1, nil, wesnoth.map.filter) wesnoth.create_map = wesnoth.deprecate_api('wesnoth.create_map', 'wesnoth.map.create', 1, nil, wesnoth.map.create)