From b14e984c66beb366385d29d1ac02d9b7ee489c29 Mon Sep 17 00:00:00 2001 From: Ukendio Date: Fri, 27 Dec 2024 03:47:02 +0100 Subject: [PATCH] Fix shadowed variable --- jecs.luau | 50 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/jecs.luau b/jecs.luau index 68228560..1dea181e 100644 --- a/jecs.luau +++ b/jecs.luau @@ -1651,7 +1651,7 @@ local function query_cached(query: QueryInner) i = #entities entityId = entities[i] columns = archetype.columns - local records = archetype.records + records = archetype.records a = columns[records[A].column] b = columns[records[B].column] end @@ -1675,7 +1675,7 @@ local function query_cached(query: QueryInner) i = #entities entityId = entities[i] columns = archetype.columns - local records = archetype.records + records = archetype.records a = columns[records[A].column] b = columns[records[B].column] c = columns[records[C].column] @@ -1700,7 +1700,7 @@ local function query_cached(query: QueryInner) i = #entities entityId = entities[i] columns = archetype.columns - local records = archetype.records + records = archetype.records a = columns[records[A].column] b = columns[records[B].column] c = columns[records[C].column] @@ -1727,7 +1727,7 @@ local function query_cached(query: QueryInner) i = #entities entityId = entities[i] columns = archetype.columns - local records = archetype.records + records = archetype.records if not F then a = columns[records[A].column] @@ -2142,16 +2142,26 @@ function World.new() return self end -export type Id = Entity +type Id = + | (number & { __jecs_pair_value: T }) + | (number & { __T: T }) -type function ecs_entity_t(entity) - return entity:components()[2]:readproperty(types.singleton("__T")) -end +export type Pair

= number & { + __jecs_pair_value: ecs_id_t> +} -type function Pair(first, second) - local thing = first:components()[2] +type function ecs_id_t(entity) + local ty = entity:components()[2] + local __T = ty:readproperty(types.singleton("__T")) + if not __T then + return ty:readproperty(types.singleton("__jecs_pair_value")) + end + return __T +end - if thing:readproperty(types.singleton("__T")):is("nil") then +type function ecs_pair_t(first, second) + local ty = first:components()[2] + if ty:readproperty(types.singleton("__T")):is("nil") then return second else return first @@ -2160,7 +2170,7 @@ end type Item = (self: Query) -> (Entity, T...) -export type Entity = number & { __T: T } +export type Entity = number & { __T: T } type Iter = (query: Query) -> () -> (Entity, T...) @@ -2250,14 +2260,14 @@ export type World = { children: (self: World, id: Id) -> () -> Entity, --- Searches the world for entities that match a given query - query: ((World, A) -> Query>) - & ((World, A, B) -> Query, ecs_entity_t>) - & ((World, A, B, C) -> Query, ecs_entity_t, ecs_entity_t>) - & ((World, A, B, C, D) -> Query, ecs_entity_t, ecs_entity_t, ecs_entity_t>) - & ((World, A, B, C, D, E) -> Query, ecs_entity_t, ecs_entity_t, ecs_entity_t, ecs_entity_t>) - & ((World, A, B, C, D, E, F) -> Query, ecs_entity_t, ecs_entity_t, ecs_entity_t, ecs_entity_t, ecs_entity_t>) - & ((World, A, B, C, D, E, F, G) -> Query, ecs_entity_t, ecs_entity_t, ecs_entity_t, ecs_entity_t, ecs_entity_t, ecs_entity_t>) - & ((World, A, B, C, D, E, F, G, H) -> Query, ecs_entity_t, ecs_entity_t, ecs_entity_t, ecs_entity_t, ecs_entity_t, ecs_entity_t, ecs_entity_t>) + query: ((World, A) -> Query>) + & ((World, A, B) -> Query, ecs_id_t>) + & ((World, A, B, C) -> Query, ecs_id_t, ecs_id_t>) + & ((World, A, B, C, D) -> Query, ecs_id_t, ecs_id_t, ecs_id_t>) + & ((World, A, B, C, D, E) -> Query, ecs_id_t, ecs_id_t, ecs_id_t, ecs_id_t>) + & ((World, A, B, C, D, E, F) -> Query, ecs_id_t, ecs_id_t, ecs_id_t, ecs_id_t, ecs_id_t>) + & ((World, A, B, C, D, E, F, G) -> Query, ecs_id_t, ecs_entity_t, ecs_id_t, ecs_id_t, ecs_id_t, ecs_id_t>) + & ((World, A, B, C, D, E, F, G, H) -> Query, ecs_id_t, ecs_id_t, ecs_id_t, ecs_id_t, ecs_id_t, ecs_id_t, ecs_id_t>) } return {