mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-25 01:20:04 +00:00
Add parent method
This commit is contained in:
parent
b8f35ccb85
commit
ec833464a5
1 changed files with 10 additions and 2 deletions
|
@ -361,9 +361,10 @@ function World.entity(world: World): i53
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO:
|
-- TODO:
|
||||||
-- should have an additional `index` parameter which selects the nth target
|
-- TODO:
|
||||||
|
-- should have an additional `nth` parameter which selects the nth target
|
||||||
-- this is important when an entity can have multiple relationships with the same target
|
-- this is important when an entity can have multiple relationships with the same target
|
||||||
function World.target(world: World, entity: i53, relation: i24): i24?
|
local function target(world: World, entity: i53, relation: i24--[[, nth: number]]): i24?
|
||||||
local entityIndex = world.entityIndex
|
local entityIndex = world.entityIndex
|
||||||
local record = entityIndex.sparse[entity]
|
local record = entityIndex.sparse[entity]
|
||||||
local archetype = record.archetype
|
local archetype = record.archetype
|
||||||
|
@ -384,6 +385,13 @@ function World.target(world: World, entity: i53, relation: i24): i24?
|
||||||
return ECS_PAIR_OBJECT(entityIndex, archetype.types[archetypeRecord])
|
return ECS_PAIR_OBJECT(entityIndex, archetype.types[archetypeRecord])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function parent(world: World, entity: i53)
|
||||||
|
return target(world, entity, EcsChildOf)
|
||||||
|
end
|
||||||
|
|
||||||
|
World.target = target
|
||||||
|
World.parent = parent
|
||||||
|
|
||||||
-- should reuse this logic in World.set instead of swap removing in transition archetype
|
-- should reuse this logic in World.set instead of swap removing in transition archetype
|
||||||
local function destructColumns(columns: { Column }, count: number, row: number)
|
local function destructColumns(columns: { Column }, count: number, row: number)
|
||||||
if row == count then
|
if row == count then
|
||||||
|
|
Loading…
Reference in a new issue