From eaafd272802de1d8b59a908b11a49eb76e2989c9 Mon Sep 17 00:00:00 2001 From: Marcus Date: Tue, 24 Dec 2024 23:39:32 +0200 Subject: [PATCH] Add support for components in both positions of pairs (#164) * Add support for components in both positions of pairs * Export type function * Rework query types --- jecs.luau | 52 +++++++++++++--------------------------------------- 1 file changed, 13 insertions(+), 39 deletions(-) diff --git a/jecs.luau b/jecs.luau index 832763cb..1aed04f5 100644 --- a/jecs.luau +++ b/jecs.luau @@ -1777,7 +1777,11 @@ end export type Id = Entity -type function _Pair(first, second) +type function ecs_entity_t(entity) + return entity:components()[2]:readproperty(types.singleton("__T")) +end + +export type function Pair(first, second) local thing = first:components()[2] if thing:readproperty(types.singleton("__T")):is("nil") then @@ -1787,8 +1791,6 @@ type function _Pair(first, second) end end -export type Pair = _Pair - type Item = (self: Query) -> (Entity, T...) export type Entity = number & { __T: T } @@ -1856,42 +1858,14 @@ export type World = { children: (self: World, id: Id) -> () -> Entity, --- Searches the world for entities that match a given query - query: ((self: World, Id) -> Query) - & ((self: World, Id, Id) -> Query) - & ((self: World, Id, Id, Id) -> Query) - & ((self: World, Id, Id, Id, Id) -> Query) - & ((self: World, Id, Id, Id, Id, Id) -> Query) - & (( - self: World, - Id, - Id, - Id, - Id, - Id, - Id - ) -> Query) - & (( - self: World, - Id, - Id, - Id, - Id, - Id, - Id, - Id - ) -> Query) - & (( - self: World, - Id, - Id, - Id, - Id, - Id, - Id, - Id, - Id, - ...Id - ) -> 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>) } return {