mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-24 17:10:03 +00:00
Fixed world:delete() not calling OnRemove hook
This commit is contained in:
parent
2171e68ee8
commit
610b668665
2 changed files with 46 additions and 1 deletions
|
@ -957,8 +957,10 @@ local function archetype_delete(world: World, archetype: Archetype, row: number,
|
|||
|
||||
-- TODO: if last == 0 then deactivate table
|
||||
|
||||
local component_index = world.componentIndex
|
||||
for _, id in id_types do
|
||||
local on_remove: (entity: i53) -> () = world_get_one_inline(world, id, EcsOnRemove)
|
||||
local idr = component_index[id]
|
||||
local on_remove: idr.hooks.on_remove
|
||||
if on_remove then
|
||||
on_remove(delete)
|
||||
end
|
||||
|
|
|
@ -1659,4 +1659,47 @@ TEST("wildcard query", function()
|
|||
CHECK(counter == 1)
|
||||
end
|
||||
end)
|
||||
|
||||
TEST("world:delete() invokes OnRemove hook", function()
|
||||
do CASE "#1"
|
||||
local world = world_new()
|
||||
|
||||
local A = world:entity()
|
||||
local entity = world:entity()
|
||||
|
||||
local called = false
|
||||
world:set(A, jecs.OnRemove, function(e)
|
||||
called = true
|
||||
end)
|
||||
|
||||
world:add(entity, A)
|
||||
world:delete()
|
||||
|
||||
CHECK(called)
|
||||
end
|
||||
do CASE "#2"
|
||||
local world = world_new()
|
||||
local pair = jecs.pair
|
||||
|
||||
local Relation = world:entity()
|
||||
local A = world:entity()
|
||||
local B = world:entity()
|
||||
|
||||
world:add(B, pair(jecs.OnDelete, jecs.Delete))
|
||||
|
||||
local entity = world:entity()
|
||||
|
||||
local called = false
|
||||
world:set(A, jecs.OnRemove, function(e)
|
||||
called = true
|
||||
end)
|
||||
|
||||
world:add(entity, A)
|
||||
world:add(entity, pair(Relation, B))
|
||||
|
||||
world:remove(entity, B)
|
||||
|
||||
CHECK(called)
|
||||
end
|
||||
end)
|
||||
FINISH()
|
||||
|
|
Loading…
Reference in a new issue