feat(composition): expose get_container for inventory readback
Add composition.get_container(entity) -> table or nil. Returns the
container block from the entity's template (e.g. {kind="list"}), or
nil if the template declared no container block. Loud-Error if the
entity was not created by composition.
The internal storage (tpl.container) was already present since v0.2.0
(stashed on the template record with a comment "B.2 reads this") but
had no public getter. This fills the oversight without any semantic
change to v0.2.0.
This commit is contained in:
17
init.lua
17
init.lua
@@ -427,4 +427,21 @@ function M.list_templates()
|
||||
return out
|
||||
end
|
||||
|
||||
-- Returns the container block from the entity's template, or nil if the
|
||||
-- template declared no container block. Loud-Error if entity was not
|
||||
-- created by composition.
|
||||
function M.get_container(target_entity)
|
||||
local reg_id = target_entity and target_entity:get_property("composition.reg_id")
|
||||
if not reg_id or reg_id == 0 then
|
||||
error("composition.get_container: entity was not created by composition")
|
||||
end
|
||||
local meta = entity_meta[reg_id]
|
||||
if not meta then
|
||||
error("composition.get_container: entity was not created by composition")
|
||||
end
|
||||
local tpl = templates[meta.template_id]
|
||||
if not tpl then return nil end
|
||||
return tpl.container -- nil when not declared
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user