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