2022-06-14 20:17:06 +02:00
|
|
|
local api = stairsplus.api
|
2022-06-14 01:11:20 +02:00
|
|
|
|
2022-09-22 21:55:29 +02:00
|
|
|
api.registered_on_register_shapes = {}
|
2022-06-14 20:17:06 +02:00
|
|
|
api.registered_shapes = {}
|
|
|
|
api.shapes_by_group = {}
|
2022-06-14 01:11:20 +02:00
|
|
|
|
2022-09-22 21:55:29 +02:00
|
|
|
function api.register_on_register_shape(func)
|
|
|
|
table.insert(api.registered_on_register_shapes, func)
|
|
|
|
end
|
|
|
|
|
2022-06-14 20:17:06 +02:00
|
|
|
function api.register_shape(name, def)
|
2022-06-16 01:18:11 +02:00
|
|
|
stairsplus.log("info", "registering shape %q", name)
|
2022-06-20 23:29:13 +02:00
|
|
|
def.shape_groups = def.shape_groups or {}
|
2022-06-14 20:17:06 +02:00
|
|
|
api.registered_shapes[name] = def
|
2022-06-14 01:11:20 +02:00
|
|
|
|
2022-06-20 23:29:13 +02:00
|
|
|
for group in pairs(def.shape_groups) do
|
2022-06-14 20:17:06 +02:00
|
|
|
local shapes = api.shapes_by_group[group] or {}
|
2022-06-14 01:11:20 +02:00
|
|
|
table.insert(shapes, name)
|
2022-06-14 20:17:06 +02:00
|
|
|
api.shapes_by_group[group] = shapes
|
2022-06-14 01:11:20 +02:00
|
|
|
end
|
2022-09-22 21:55:29 +02:00
|
|
|
|
|
|
|
for _, func in ipairs(api.registered_on_register_shapes) do
|
|
|
|
func(name, def)
|
|
|
|
end
|
2022-06-14 01:11:20 +02:00
|
|
|
end
|
2022-06-20 23:29:13 +02:00
|
|
|
|
|
|
|
function api.register_shape_group(shape_group, shapes)
|
|
|
|
for _, shape in ipairs(shapes) do
|
|
|
|
api.registered_shapes[shape].shape_groups[shape_group] = 1
|
|
|
|
end
|
|
|
|
api.shapes_by_group[shape_group] = shapes
|
|
|
|
end
|