From 84d1980c18c65cbdd8934a8dbbba4d6cfe7262de Mon Sep 17 00:00:00 2001 From: Axel Meyer Date: Sun, 24 May 2026 00:34:14 +0200 Subject: [PATCH] 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. --- init.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/init.lua b/init.lua index 7d42935..e2f480a 100644 --- a/init.lua +++ b/init.lua @@ -680,6 +680,25 @@ function M.set_cell_gid(layer_name, x, y, gid, map_id) map._dirty = true 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) local id = map_id or current_map_id if not id then error("maps.is_indoor: no current map") end