Skip to content

Commit

Permalink
Add support for components in both positions of pairs (#164)
Browse files Browse the repository at this point in the history
* Add support for components in both positions of pairs

* Export type function

* Rework query types
  • Loading branch information
Ukendio authored Dec 24, 2024
1 parent ee9bc6a commit eaafd27
Showing 1 changed file with 13 additions and 39 deletions.
52 changes: 13 additions & 39 deletions jecs.luau
Original file line number Diff line number Diff line change
Expand Up @@ -1777,7 +1777,11 @@ end

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

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
Expand All @@ -1787,8 +1791,6 @@ type function _Pair(first, second)
end
end

export type Pair<T, U> = _Pair<T, U>

type Item<T...> = (self: Query<T...>) -> (Entity, T...)

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

--- Searches the world for entities that match a given query
query: (<A>(self: World, Id<A>) -> Query<A>)
& (<A, B>(self: World, Id<A>, Id<B>) -> Query<A, B>)
& (<A, B, C>(self: World, Id<A>, Id<B>, Id<C>) -> Query<A, B, C>)
& (<A, B, C, D>(self: World, Id<A>, Id<B>, Id<C>, Id<D>) -> Query<A, B, C, D>)
& (<A, B, C, D, E>(self: World, Id<A>, Id<B>, Id<C>, Id<D>, Id<E>) -> Query<A, B, C, D, E>)
& (<A, B, C, D, E, F>(
self: World,
Id<A>,
Id<B>,
Id<C>,
Id<D>,
Id<E>,
Id<F>
) -> Query<A, B, C, D, E, F>)
& (<A, B, C, D, E, F, G>(
self: World,
Id<A>,
Id<B>,
Id<C>,
Id<D>,
Id<E>,
Id<F>,
Id<G>
) -> Query<A, B, C, D, E, F, G>)
& (<A, B, C, D, E, F, G, H>(
self: World,
Id<A>,
Id<B>,
Id<C>,
Id<D>,
Id<E>,
Id<F>,
Id<G>,
Id<H>,
...Id<any>
) -> Query<A, B, C, D, E, F, G, H>),
query: (<A>(World, A) -> Query<ecs_entity_t<A>>)
& (<A, B>(World, A, B) -> Query<ecs_entity_t<A>, ecs_entity_t<B>>)
& (<A, B, C>(World, A, B, C) -> Query<ecs_entity_t<A>, ecs_entity_t<B>, ecs_entity_t<C>>)
& (<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>>)
& (<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>>)
& (<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>>)
& (<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>>)
& (<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>>)
}

return {
Expand Down

0 comments on commit eaafd27

Please sign in to comment.