diff --git a/jecs.luau b/jecs.luau index c140af8..3f297da 100644 --- a/jecs.luau +++ b/jecs.luau @@ -500,6 +500,14 @@ local function world_has_one_inline(world: ecs_world_t, entity: i53, id: i53): b return records[id] ~= nil end +local function ecs_is_tag(world: ecs_world_t, entity: i53): boolean + local idr = world.component_index[entity] + if idr then + return bit32.band(idr.flags, ECS_ID_IS_TAG) ~= 0 + end + return not world_has_one_inline(world, entity, EcsComponent) +end + local function world_has(world: ecs_world_t, entity: i53, a: i53, b: i53?, c: i53?, d: i53?, e: i53?): boolean @@ -2523,6 +2531,7 @@ return { component = (ECS_COMPONENT :: any) :: () -> Entity, tag = (ECS_TAG :: any) :: () -> Entity, meta = (ECS_META :: any) :: (id: Entity, id: Id, value: T) -> Entity, + is_tag = (ecs_is_tag :: any) :: (World, Id) -> boolean, OnAdd = EcsOnAdd :: Entity<(entity: Entity) -> ()>, OnRemove = EcsOnRemove :: Entity<(entity: Entity) -> ()>, diff --git a/test/addons/observers.luau b/test/addons/observers.luau index cf5e10a..11cac9f 100644 --- a/test/addons/observers.luau +++ b/test/addons/observers.luau @@ -82,6 +82,25 @@ TEST("addons/observers", function() world:set(e, A, true) CHECK(count == 3) end + + do CASE "Call on pairs" + local A = world:component() + + local callcount = 0 + world:added(A, function(entity) + callcount += 1 + end) + world:added(A, function(entity) + callcount += 1 + end) + + local e = world:entity() + local e1 = world:entity() + + world:add(e1, jecs.pair(A, e)) + world:add(e, jecs.pair(A, e1)) + CHECK(callcount == 4) + end end) return FINISH()