Add set_roof write API to lib-core.maps

Allocates the roof array on-demand if the map didn't have one,
validates value in {0, 1}, and bounds-checks the target cell.
This commit is contained in:
Axel Meyer
2026-05-24 00:34:14 +02:00
parent 45b1f93363
commit 84d1980c18

View File

@@ -680,6 +680,25 @@ function M.set_cell_gid(layer_name, x, y, gid, map_id)
map._dirty = true map._dirty = true
end end
function M.set_roof(x, y, value, map_id)
local map = require_map(map_id)
if x < 0 or y < 0 or x >= map.size.w or y >= map.size.h then
error(string.format("maps.set_roof: cell (%d,%d) out of bounds for size %dx%d",
x, y, map.size.w, map.size.h))
end
if value ~= 0 and value ~= 1 then
error(string.format("maps.set_roof: value %s must be 0 or 1", tostring(value)))
end
if not map.roof then
local cell_count = map.size.w * map.size.h
map.roof = {}
for i = 1, cell_count do map.roof[i] = 0 end
end
local idx = y * map.size.w + x + 1
map.roof[idx] = value
map._dirty = true
end
function M.is_indoor(x, y, map_id) function M.is_indoor(x, y, map_id)
local id = map_id or current_map_id local id = map_id or current_map_id
if not id then error("maps.is_indoor: no current map") end if not id then error("maps.is_indoor: no current map") end