Lua Cave Mapgen: Use stable iteration of location sets
This commit is contained in:
parent
0166235d99
commit
2dee1e5f96
2 changed files with 17 additions and 6 deletions
|
@ -92,11 +92,10 @@ function callbacks.generate_map(params)
|
|||
|
||||
for i,v in ipairs(chambers) do
|
||||
local locs_list = {}
|
||||
for k2,loc in ipairs(v.locs_set:to_pairs()) do
|
||||
local x, y = table.unpack(loc)
|
||||
for x, y in v.locs_set:stable_iter() do
|
||||
clear_tile(x, y)
|
||||
if map:on_inner_board(x, y) then
|
||||
table.insert(locs_list, loc)
|
||||
table.insert(locs_list, {x,y})
|
||||
end
|
||||
end
|
||||
for i1, item in ipairs(v.items or {}) do
|
||||
|
@ -138,8 +137,8 @@ function callbacks.generate_map(params)
|
|||
for i, loc in ipairs(path) do
|
||||
local locs_set = LS.create()
|
||||
build_chamber(loc[1], loc[2], locs_set, width, jagged)
|
||||
for k,v in ipairs(locs_set:to_pairs()) do
|
||||
clear_tile(v[1], v[2])
|
||||
for x,y in locs_set:stable_iter() do
|
||||
clear_tile(x, y)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -86,6 +86,12 @@ function methods:filter(f)
|
|||
end
|
||||
|
||||
function methods:iter(f)
|
||||
if f == nil then
|
||||
local locs = self
|
||||
return coroutine.wrap(function()
|
||||
locs:iter(coroutine.yield)
|
||||
end)
|
||||
end
|
||||
for p,v in pairs(self.values) do
|
||||
local x, y = revindex(p)
|
||||
f(x, y, v)
|
||||
|
@ -97,10 +103,16 @@ function methods:stable_iter(f)
|
|||
for p,v in pairs(self.values) do
|
||||
table.insert(indices, p)
|
||||
end
|
||||
if f == nil then
|
||||
local locs = self
|
||||
return coroutine.wrap(function()
|
||||
locs:stable_iter(coroutine.yield)
|
||||
end)
|
||||
end
|
||||
table.sort(indices)
|
||||
for i,p in ipairs(indices) do
|
||||
local x, y = revindex(p)
|
||||
f(x, y)
|
||||
f(x, y, self.values[p])
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue