Skip to content

Commit eaafd27

Browse files
authored
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
1 parent ee9bc6a commit eaafd27

File tree

1 file changed

+13
-39
lines changed

1 file changed

+13
-39
lines changed

jecs.luau

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,7 +1777,11 @@ end
17771777

17781778
export type Id<T = unknown> = Entity<T>
17791779

1780-
type function _Pair(first, second)
1780+
type function ecs_entity_t(entity)
1781+
return entity:components()[2]:readproperty(types.singleton("__T"))
1782+
end
1783+
1784+
export type function Pair(first, second)
17811785
local thing = first:components()[2]
17821786

17831787
if thing:readproperty(types.singleton("__T")):is("nil") then
@@ -1787,8 +1791,6 @@ type function _Pair(first, second)
17871791
end
17881792
end
17891793

1790-
export type Pair<T, U> = _Pair<T, U>
1791-
17921794
type Item<T...> = (self: Query<T...>) -> (Entity, T...)
17931795

17941796
export type Entity<T = unknown> = number & { __T: T }
@@ -1856,42 +1858,14 @@ export type World = {
18561858
children: (self: World, id: Id) -> () -> Entity,
18571859

18581860
--- Searches the world for entities that match a given query
1859-
query: (<A>(self: World, Id<A>) -> Query<A>)
1860-
& (<A, B>(self: World, Id<A>, Id<B>) -> Query<A, B>)
1861-
& (<A, B, C>(self: World, Id<A>, Id<B>, Id<C>) -> Query<A, B, C>)
1862-
& (<A, B, C, D>(self: World, Id<A>, Id<B>, Id<C>, Id<D>) -> Query<A, B, C, D>)
1863-
& (<A, B, C, D, E>(self: World, Id<A>, Id<B>, Id<C>, Id<D>, Id<E>) -> Query<A, B, C, D, E>)
1864-
& (<A, B, C, D, E, F>(
1865-
self: World,
1866-
Id<A>,
1867-
Id<B>,
1868-
Id<C>,
1869-
Id<D>,
1870-
Id<E>,
1871-
Id<F>
1872-
) -> Query<A, B, C, D, E, F>)
1873-
& (<A, B, C, D, E, F, G>(
1874-
self: World,
1875-
Id<A>,
1876-
Id<B>,
1877-
Id<C>,
1878-
Id<D>,
1879-
Id<E>,
1880-
Id<F>,
1881-
Id<G>
1882-
) -> Query<A, B, C, D, E, F, G>)
1883-
& (<A, B, C, D, E, F, G, H>(
1884-
self: World,
1885-
Id<A>,
1886-
Id<B>,
1887-
Id<C>,
1888-
Id<D>,
1889-
Id<E>,
1890-
Id<F>,
1891-
Id<G>,
1892-
Id<H>,
1893-
...Id<any>
1894-
) -> Query<A, B, C, D, E, F, G, H>),
1861+
query: (<A>(World, A) -> Query<ecs_entity_t<A>>)
1862+
& (<A, B>(World, A, B) -> Query<ecs_entity_t<A>, ecs_entity_t<B>>)
1863+
& (<A, B, C>(World, A, B, C) -> Query<ecs_entity_t<A>, ecs_entity_t<B>, ecs_entity_t<C>>)
1864+
& (<A, B, C, D>(World, A, B, C, D) -> Query<ecs_entity_t<A>, ecs_entity_t<B>, ecs_entity_t<C>, ecs_entity_t<D>>)
1865+
& (<A, B, C, D, E>(World, A, B, C, D, E) -> Query<ecs_entity_t<A>, ecs_entity_t<B>, ecs_entity_t<C>, ecs_entity_t<D>, ecs_entity_t<E>>)
1866+
& (<A, B, C, D, E, F>(World, A, B, C, D, E, F) -> Query<ecs_entity_t<A>, ecs_entity_t<B>, ecs_entity_t<C>, ecs_entity_t<D>, ecs_entity_t<E>, ecs_entity_t<F>>)
1867+
& (<A, B, C, D, E, F, G>(World, A, B, C, D, E, F, G) -> Query<ecs_entity_t<A>, ecs_entity_t<B>, ecs_entity_t<C>, ecs_entity_t<D>, ecs_entity_t<E>, ecs_entity_t<F>, ecs_entity_t<G>>)
1868+
& (<A, B, C, D, E, F, G, H>(World, A, B, C, D, E, F, G, H) -> Query<ecs_entity_t<A>, ecs_entity_t<B>, ecs_entity_t<C>, ecs_entity_t<D>, ecs_entity_t<E>, ecs_entity_t<F>, ecs_entity_t<G>, ecs_entity_t<H>>)
18951869
}
18961870

18971871
return {

0 commit comments

Comments
 (0)