Skip to content

Commit

Permalink
Move WC's filter tag helpers into core
Browse files Browse the repository at this point in the history
  • Loading branch information
CelticMinstrel committed Feb 23, 2021
1 parent c55373f commit b4de3df
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 35 deletions.
@@ -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 {})
Expand Down
45 changes: 45 additions & 0 deletions data/lua/core/map.lua
Expand Up @@ -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)
Expand Down

0 comments on commit b4de3df

Please sign in to comment.