Add support for components in both positions of pairs (#164)
Some checks are pending
Analysis / Run Luau Analyze (push) Waiting to run
Deploy VitePress site to Pages / build (push) Waiting to run
Deploy VitePress site to Pages / Deploy (push) Blocked by required conditions
Unit Testing / Run Luau Tests (push) Waiting to run

* Add support for components in both positions of pairs

* Export type function

* Rework query types
This commit is contained in:
Marcus 2024-12-24 23:39:32 +02:00 committed by GitHub
parent ee9bc6a775
commit eaafd27280
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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
@ -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 }
@ -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 {