Skip to content

Commit

Permalink
Add parent method
Browse files Browse the repository at this point in the history
  • Loading branch information
Ukendio committed Jul 3, 2024
1 parent b8f35cc commit ec83346
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,10 @@ function World.entity(world: World): i53
end

-- 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
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 record = entityIndex.sparse[entity]
local archetype = record.archetype
Expand All @@ -384,6 +385,13 @@ function World.target(world: World, entity: i53, relation: i24): i24?
return ECS_PAIR_OBJECT(entityIndex, archetype.types[archetypeRecord])
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
local function destructColumns(columns: { Column }, count: number, row: number)
if row == count then
Expand Down

0 comments on commit ec83346

Please sign in to comment.