mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-24 17:10:03 +00:00
Fixed hooks invocation in the event of relationship target deletion. (#179)
Some checks are pending
Some checks are pending
* Fixed hooks invocation (case #3) * Reverted world:component() to world:entity() Co-authored-by: lolmanurfunny <77128366+lolmanurfunny@users.noreply.github.com> * Removed whitespace --------- Co-authored-by: lolmanurfunny <77128366+lolmanurfunny@users.noreply.github.com>
This commit is contained in:
parent
0296c4b2f9
commit
5e3739036a
2 changed files with 20 additions and 1 deletions
|
@ -1158,7 +1158,6 @@ do
|
||||||
local idr_t_archetype = archetypes[archetype_id]
|
local idr_t_archetype = archetypes[archetype_id]
|
||||||
|
|
||||||
local idr_t_types = idr_t_archetype.types
|
local idr_t_types = idr_t_archetype.types
|
||||||
local on_remove = idr_t.hooks.on_remove
|
|
||||||
|
|
||||||
for _, child in idr_t_archetype.entities do
|
for _, child in idr_t_archetype.entities do
|
||||||
table.insert(children, child)
|
table.insert(children, child)
|
||||||
|
@ -1180,6 +1179,7 @@ do
|
||||||
end
|
end
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
|
local on_remove = id_record.hooks.on_remove
|
||||||
local to = archetype_traverse_remove(world, id, idr_t_archetype)
|
local to = archetype_traverse_remove(world, id, idr_t_archetype)
|
||||||
if on_remove then
|
if on_remove then
|
||||||
for _, child in children do
|
for _, child in children do
|
||||||
|
|
|
@ -1699,6 +1699,25 @@ TEST("world:delete() invokes OnRemove hook", function()
|
||||||
|
|
||||||
world:delete(B)
|
world:delete(B)
|
||||||
|
|
||||||
|
CHECK(called)
|
||||||
|
end
|
||||||
|
do CASE "#3"
|
||||||
|
local world = world_new()
|
||||||
|
local pair = jecs.pair
|
||||||
|
|
||||||
|
local viewingContainer = world:entity()
|
||||||
|
local character = world:entity()
|
||||||
|
local container = world:entity()
|
||||||
|
|
||||||
|
local called = false
|
||||||
|
world:set(viewingContainer, jecs.OnRemove, function(e)
|
||||||
|
called = true
|
||||||
|
end)
|
||||||
|
|
||||||
|
world:add(character, pair(viewingContainer, container))
|
||||||
|
|
||||||
|
world:delete(container)
|
||||||
|
|
||||||
CHECK(called)
|
CHECK(called)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
Loading…
Reference in a new issue