mirror of
https://github.com/Reuh/ubiquitousse.git
synced 2025-10-27 17:19:31 +00:00
ecs: add callbackFiltered and emitFiltered
This commit is contained in:
parent
bd28610ff4
commit
aa332a0adf
20 changed files with 697 additions and 568 deletions
40
ecs/commonsystems/children.can
Normal file
40
ecs/commonsystems/children.can
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
--- Children system.
|
||||
-- Allows to build a hierarchy between entities.
|
||||
--
|
||||
-- An entity's parent entity is stored in its `parent` component.
|
||||
-- An entity's children are stored in its `children` component (list of children entities).
|
||||
--
|
||||
-- You can set theses values before adding the entity to the world; when you add the entity it will add itself
|
||||
-- to its parent children list and add all its children to the world.
|
||||
--
|
||||
-- If you remove an entity from the world, it will also remove all its children from the world.
|
||||
|
||||
return {
|
||||
name = "children",
|
||||
filter = true,
|
||||
onAdd = :(e)
|
||||
if not e.children then e.children = {} end
|
||||
if e.parent then -- add to parent
|
||||
let parentchildren = e.parent.children
|
||||
table.insert(parentchildren, e)
|
||||
end
|
||||
for _, o in ipairs(e.children) do -- add predefined children
|
||||
o.parent = e
|
||||
@world:add(o)
|
||||
end
|
||||
end,
|
||||
onRemove = :(e)
|
||||
for i=#e.children, 1, -1 do -- remove children
|
||||
@world:remove(e.children[i])
|
||||
end
|
||||
if e.parent then -- remove from parent
|
||||
let parentchildren = e.parent.children
|
||||
for i=#parentchildren, 1, -1 do
|
||||
if parentchildren[i] == e then
|
||||
table.remove(parentchildren, i)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue