mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-25 09:30:03 +00:00
Merge branch 'types-dx' of https://github.com/alicesaidhi/jecs into alicesaidhi-types-dx
This commit is contained in:
commit
e4dd2654ae
1 changed files with 42 additions and 20 deletions
62
lib/init.lua
62
lib/init.lua
|
@ -845,13 +845,20 @@ function World.__iter(world: World): () -> (number?, unknown?)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- __nominal_type_dont_use could not be any or T as it causes a type error
|
||||||
|
-- or produces a union
|
||||||
|
export type Component<T=any> = T & {__nominal_type_dont_use: never}
|
||||||
|
export type Entity<T=any> = Component<T>
|
||||||
|
export type Relationship<T=any> = Component<T>
|
||||||
|
type ctype<T> = Component<T>
|
||||||
|
|
||||||
export type QueryShim<T...> = typeof(setmetatable(
|
export type QueryShim<T...> = typeof(setmetatable(
|
||||||
{} :: {
|
{} :: {
|
||||||
--- Excludes the given selection from the query
|
--- Excludes the given selection from the query
|
||||||
without: <U...>(QueryShim<T...>, U...) -> QueryShim<T...>
|
without: <U...>(QueryShim<T...>, U...) -> QueryShim<T...>
|
||||||
},
|
},
|
||||||
{} :: {
|
{} :: {
|
||||||
__iter: () -> (number, T...)
|
__iter: (QueryShim<T...>) -> () -> (Entity, T...)
|
||||||
}
|
}
|
||||||
))
|
))
|
||||||
|
|
||||||
|
@ -859,43 +866,58 @@ export type WorldShim = typeof(setmetatable(
|
||||||
{} :: {
|
{} :: {
|
||||||
|
|
||||||
--- Creates a new entity
|
--- Creates a new entity
|
||||||
entity: <T>(WorldShim) -> T,
|
entity: <T>(WorldShim) -> Entity<T>,
|
||||||
--- Creates a new entity located in the first 256 ids.
|
--- Creates a new entity located in the first 256 ids.
|
||||||
--- These should be used for static components for fast access.
|
--- These should be used for static components for fast access.
|
||||||
component: <T>(WorldShim) -> T,
|
component: <T>(WorldShim) -> Component<T>,
|
||||||
--- Gets the target of an relationship. For example, when a user calls
|
--- Gets the target of an relationship. For example, when a user calls
|
||||||
--- `world:target(id, ChildOf(parent))`, you will obtain the parent entity.
|
--- `world:target(id, ChildOf(parent))`, you will obtain the parent entity.
|
||||||
target: <T>(WorldShim, id: unknown, relation: unknown) -> T?,
|
target: (WorldShim, id: Entity, relation: Relationship) -> Entity?,
|
||||||
--- Deletes an entity and all it's related components and relationships.
|
--- Deletes an entity and all it's related components and relationships.
|
||||||
delete: (WorldShim, id: unknown) -> (),
|
delete: (WorldShim, id: Entity) -> (),
|
||||||
|
|
||||||
--- Adds a component to the entity with no value
|
--- Adds a component to the entity with no value
|
||||||
add: <T>(WorldShim, id: unknown, component: T) -> (),
|
add: <T>(WorldShim, id: Entity, component: Component<T>) -> (),
|
||||||
--- Assigns a value to a component on the given entity
|
--- Assigns a value to a component on the given entity
|
||||||
set: <T>(WorldShim, id: unknown, component: T, data: T) -> (),
|
set: <T>(WorldShim, id: Entity, component: Component<T>, data: T) -> (),
|
||||||
--- Removes a component from the given entity
|
--- Removes a component from the given entity
|
||||||
remove: (WorldShim, id: unknown, component: unknown) -> (),
|
remove: (WorldShim, id: Entity, component: Component) -> (),
|
||||||
--- Retrieves the value of up to 4 components. These values may be nil.
|
--- Retrieves the value of up to 4 components. These values may be nil.
|
||||||
get: <T...>(WorldShim, id: unknown, T...) -> T...,
|
get:
|
||||||
|
(<A>(WorldShim, id: any, ctype<A>) -> A)
|
||||||
|
& (<A, B>(WorldShim, id: Entity, ctype<A>, ctype<B>) -> (A, B))
|
||||||
|
& (<A, B, C>(WorldShim, id: Entity, ctype<A>, ctype<B>, ctype<C>) -> (A, B, C))
|
||||||
|
& <A, B, C, D>(WorldShim, id: Entity, ctype<A>, ctype<B>, ctype<C>, ctype<D>) -> (A, B, C, D),
|
||||||
|
|
||||||
--- Searches the world for entities that match a given query
|
--- Searches the world for entities that match a given query
|
||||||
query: <T...>(WorldShim, T...) -> Query
|
query:
|
||||||
|
(<A>(WorldShim, ctype<A>) -> QueryShim<A>)
|
||||||
|
& (<A, B>(WorldShim, ctype<A>, ctype<B>) -> QueryShim<A, B>)
|
||||||
|
& (<A, B, C>(WorldShim, ctype<A>, ctype<B>, ctype<C>) -> QueryShim<A, B, C>)
|
||||||
|
& (<A, B, C, D>(WorldShim, ctype<A>, ctype<B>, ctype<C>, ctype<D>) -> QueryShim<A, B, C, D>)
|
||||||
|
& (<A, B, C, D, E>(WorldShim, ctype<A>, ctype<B>, ctype<C>, ctype<D>, ctype<E>) -> QueryShim<A, B, C, D, E>)
|
||||||
|
& (<A, B, C, D, E, F>(WorldShim, ctype<A>, ctype<B>, ctype<C>, ctype<D>, ctype<E>, ctype<F>) -> QueryShim<A, B, C, D, E, F>)
|
||||||
|
& (<A, B, C, D, E, F, G>(WorldShim, ctype<A>, ctype<B>, ctype<C>, ctype<D>, ctype<E>, ctype<F>, ctype<G>) -> QueryShim<A, B, C, D, E, F, G>)
|
||||||
|
& (<A, B, C, D, E, F, G, H>(WorldShim, ctype<A>, ctype<B>, ctype<C>, ctype<D>, ctype<E>, ctype<F>, ctype<G>, ctype<H>) -> QueryShim<A, B, C, D, E, F, G, H>)
|
||||||
|
& (<A, B, C, D, E, F, G, H, I>(WorldShim, ctype<A>, ctype<B>, ctype<C>, ctype<D>, ctype<E>, ctype<F>, ctype<G>, ctype<H>, ctype<I>) -> QueryShim<A, B, C, D, E, F, G, H, I>)
|
||||||
|
& (<A, B, C, D, E, F, G, H, I, J>(WorldShim, ctype<A>, ctype<B>, ctype<C>, ctype<D>, ctype<E>, ctype<F>, ctype<G>, ctype<H>, ctype<I>, ctype<J>) -> QueryShim<A, B, C, D, E, F, G, H, I, J>)
|
||||||
|
& (<A, B, C, D, E, F, G, H, I, J, K>(WorldShim, ctype<A>, ctype<B>, ctype<C>, ctype<D>, ctype<E>, ctype<F>, ctype<G>, ctype<H>, ctype<I>, ctype<J>, ctype<K>, ...ctype<any>) -> QueryShim<A, B, C, D, E, F, G, H, I, J, K, ...any>)
|
||||||
|
|
||||||
},
|
},
|
||||||
{} :: {
|
{} :: {
|
||||||
__iter: (world: World) -> () -> (number, {[unknown]: unknown?})
|
__iter: (world: WorldShim) -> () -> (number, {[unknown]: unknown?})
|
||||||
}
|
}
|
||||||
|
|
||||||
))
|
))
|
||||||
|
|
||||||
return table.freeze({
|
return table.freeze({
|
||||||
World = World :: {new: () -> WorldShim},
|
World = (World :: any) :: {new: () -> WorldShim},
|
||||||
|
|
||||||
OnAdd = ON_ADD,
|
OnAdd = (ON_ADD :: any) :: Component,
|
||||||
OnRemove = ON_REMOVE,
|
OnRemove = (ON_REMOVE :: any) :: Component,
|
||||||
OnSet = ON_SET,
|
OnSet = (ON_SET :: any) :: Component,
|
||||||
Wildcard = WILDCARD,
|
Wildcard = (WILDCARD :: any) :: Component,
|
||||||
w = WILDCARD,
|
w = (WILDCARD :: any) :: Component,
|
||||||
Rest = REST,
|
Rest = REST,
|
||||||
|
|
||||||
IS_PAIR = ECS_IS_PAIR,
|
IS_PAIR = ECS_IS_PAIR,
|
||||||
|
@ -906,6 +928,6 @@ return table.freeze({
|
||||||
ECS_PAIR_RELATION = ECS_PAIR_RELATION,
|
ECS_PAIR_RELATION = ECS_PAIR_RELATION,
|
||||||
ECS_PAIR_OBJECT = ECS_PAIR_OBJECT,
|
ECS_PAIR_OBJECT = ECS_PAIR_OBJECT,
|
||||||
|
|
||||||
pair = ECS_PAIR,
|
pair = (ECS_PAIR :: any) :: <R, T>(pred: Entity<R>, obj: Entity<T>) -> Relationship<R>,
|
||||||
getAlive = getAlive,
|
getAlive = getAlive
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue