mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-25 01:20:04 +00:00
Add back symmetric and non idempotent add function
This commit is contained in:
parent
cf694bddd1
commit
1c69a634d5
1 changed files with 15 additions and 0 deletions
15
lib/init.lua
15
lib/init.lua
|
@ -441,6 +441,21 @@ local function archetypeTraverseAdd(world: World, componentId: i53, from: Archet
|
|||
return add
|
||||
end
|
||||
|
||||
function World.add(world: World, entityId: i53, componentId: i53)
|
||||
local entityIndex = world.entityIndex
|
||||
local record = entityIndex.sparse[entityId]
|
||||
local from = record.archetype
|
||||
local to = archetypeTraverseAdd(world, componentId, from)
|
||||
if from and not (from == world.ROOT_ARCHETYPE) then
|
||||
moveEntity(entityIndex, entityId, record, to)
|
||||
else
|
||||
if #to.types > 0 then
|
||||
newEntity(entityId, record, to)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Symmetric like `World.add` but idempotent
|
||||
function World.set(world: World, entityId: i53, componentId: i53, data: unknown)
|
||||
local record = world.entityIndex.sparse[entityId]
|
||||
local from = record.archetype
|
||||
|
|
Loading…
Reference in a new issue