mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-24 17:10:03 +00:00
Add tests for entity-child relationships and removal in world queries, fixed world_each
This commit is contained in:
parent
bacf056851
commit
10bbb21024
2 changed files with 33 additions and 0 deletions
|
@ -1995,6 +1995,7 @@ local function world_each(world: World, id): () -> ()
|
||||||
archetype = archetypes[archetype_id]
|
archetype = archetypes[archetype_id]
|
||||||
entities = archetype.entities
|
entities = archetype.entities
|
||||||
row = #entities
|
row = #entities
|
||||||
|
entity = entities[row]
|
||||||
end
|
end
|
||||||
row -= 1
|
row -= 1
|
||||||
return entity
|
return entity
|
||||||
|
|
|
@ -914,6 +914,38 @@ TEST("world:children", function()
|
||||||
end
|
end
|
||||||
CHECK(false)
|
CHECK(false)
|
||||||
end
|
end
|
||||||
|
-- Check query, with tags and children being added inside the query
|
||||||
|
local parent = world:entity()
|
||||||
|
local c1 = world:component()
|
||||||
|
local t1 = world:entity()
|
||||||
|
local t2 = world:entity()
|
||||||
|
world:set(parent, c1, true)
|
||||||
|
local count = 0
|
||||||
|
for entity in world:query(c1) do
|
||||||
|
world:add(entity, t1)
|
||||||
|
local child = world:entity()
|
||||||
|
world:add(child, pair(ChildOf, entity))
|
||||||
|
world:add(child, t2)
|
||||||
|
for child in world:children(entity) do
|
||||||
|
count += 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
CHECK(count == 0)
|
||||||
|
-- Check child still exists outside of query
|
||||||
|
count = 0
|
||||||
|
for entity in world:children(parent) do
|
||||||
|
count += 1
|
||||||
|
end
|
||||||
|
CHECK(count == 0)
|
||||||
|
-- Check removing child
|
||||||
|
local child = world:entity()
|
||||||
|
world:add(child, pair(ChildOf, parent))
|
||||||
|
world:remove(child, pair(ChildOf, parent))
|
||||||
|
count = 0
|
||||||
|
for entity in world:children(parent) do
|
||||||
|
count += 1
|
||||||
|
end
|
||||||
|
CHECK(count == 0)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
TEST("world:clear()", function()
|
TEST("world:clear()", function()
|
||||||
|
|
Loading…
Reference in a new issue