mirror of
https://github.com/Ukendio/jecs.git
synced 2026-02-04 15:15:21 +00:00
ts type update
This commit is contained in:
parent
18b72149c7
commit
b974dd9e52
1 changed files with 253 additions and 221 deletions
54
src/jecs.d.ts
vendored
54
src/jecs.d.ts
vendored
|
|
@ -30,9 +30,13 @@ export type Pair<P = unknown, O = unknown> = number & {
|
||||||
* An `Id` can be either a single Entity or a Pair of Entities.
|
* An `Id` can be either a single Entity or a Pair of Entities.
|
||||||
* By providing `TData`, you can specifically require an Id that yields that type.
|
* By providing `TData`, you can specifically require an Id that yields that type.
|
||||||
*/
|
*/
|
||||||
export type Id<TData = unknown> = Entity<TData> | Pair<TData, unknown> | Pair<TagDiscriminator, TData>;
|
export type Id<TData = unknown> =
|
||||||
|
| Entity<TData>
|
||||||
|
| Pair<TData, unknown>
|
||||||
|
| Pair<TagDiscriminator, TData>;
|
||||||
|
|
||||||
export type InferComponent<E> = E extends Entity<infer D>
|
export type InferComponent<E> =
|
||||||
|
E extends Entity<infer D>
|
||||||
? D
|
? D
|
||||||
: E extends Pair<infer P, infer O>
|
: E extends Pair<infer P, infer O>
|
||||||
? P extends TagDiscriminator
|
? P extends TagDiscriminator
|
||||||
|
|
@ -63,7 +67,7 @@ type Iter<T extends Id[]> = IterFn<T> & {
|
||||||
* @hidden
|
* @hidden
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
(): never
|
(): never;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type CachedQuery<T extends Id[]> = {
|
export type CachedQuery<T extends Id[]> = {
|
||||||
|
|
@ -77,6 +81,16 @@ export type CachedQuery<T extends Id[]> = {
|
||||||
* @returns An array of archetypes of the query
|
* @returns An array of archetypes of the query
|
||||||
*/
|
*/
|
||||||
archetypes(): Archetype<T>[];
|
archetypes(): Archetype<T>[];
|
||||||
|
|
||||||
|
has(entity: Entity): boolean;
|
||||||
|
|
||||||
|
ids: Id<any>[];
|
||||||
|
|
||||||
|
filter_with?: Id<any>[];
|
||||||
|
|
||||||
|
filter_without?: Id<any>[];
|
||||||
|
|
||||||
|
archetypes_map: Map<number, number>;
|
||||||
} & Iter<T>;
|
} & Iter<T>;
|
||||||
|
|
||||||
export type Query<T extends Id[]> = {
|
export type Query<T extends Id[]> = {
|
||||||
|
|
@ -111,6 +125,14 @@ export type Query<T extends Id[]> = {
|
||||||
* @returns An array of archetypes of the query
|
* @returns An array of archetypes of the query
|
||||||
*/
|
*/
|
||||||
archetypes(): Archetype<T>[];
|
archetypes(): Archetype<T>[];
|
||||||
|
|
||||||
|
has(entity: Entity): boolean;
|
||||||
|
|
||||||
|
ids: Id<any>[];
|
||||||
|
|
||||||
|
filter_with?: Id<any>[];
|
||||||
|
|
||||||
|
filter_without?: Id<any>[];
|
||||||
} & Iter<T>;
|
} & Iter<T>;
|
||||||
|
|
||||||
export class World {
|
export class World {
|
||||||
|
|
@ -160,7 +182,10 @@ export class World {
|
||||||
* @param entity The target entity.
|
* @param entity The target entity.
|
||||||
* @param component The component (or tag) to add.
|
* @param component The component (or tag) to add.
|
||||||
*/
|
*/
|
||||||
add<C>(entity: Entity, component: TagDiscriminator extends InferComponent<C> ? C : Id<TagDiscriminator>): void;
|
add<C>(
|
||||||
|
entity: Entity,
|
||||||
|
component: TagDiscriminator extends InferComponent<C> ? C : Id<TagDiscriminator>,
|
||||||
|
): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Installs a hook on the given component.
|
* Installs a hook on the given component.
|
||||||
|
|
@ -168,7 +193,11 @@ export class World {
|
||||||
* @param hook The hook to install.
|
* @param hook The hook to install.
|
||||||
* @param value The hook callback.
|
* @param value The hook callback.
|
||||||
*/
|
*/
|
||||||
set<T>(component: Entity<T>, hook: StatefulHook, value: (e: Entity, id: Id<T>, data: T) => void): void;
|
set<T>(
|
||||||
|
component: Entity<T>,
|
||||||
|
hook: StatefulHook,
|
||||||
|
value: (e: Entity, id: Id<T>, data: T) => void,
|
||||||
|
): void;
|
||||||
set<T>(component: Entity<T>, hook: StatelessHook, value: (e: Entity, id: Id<T>) => void): void;
|
set<T>(component: Entity<T>, hook: StatelessHook, value: (e: Entity, id: Id<T>) => void): void;
|
||||||
/**
|
/**
|
||||||
* Assigns a value to a component on the given entity.
|
* Assigns a value to a component on the given entity.
|
||||||
|
|
@ -272,7 +301,10 @@ export class World {
|
||||||
query<T extends Id[]>(...components: T): Query<T>;
|
query<T extends Id[]>(...components: T): Query<T>;
|
||||||
|
|
||||||
added<T>(component: Entity<T>, listener: (e: Entity, id: Id<T>, value: T) => void): () => void;
|
added<T>(component: Entity<T>, listener: (e: Entity, id: Id<T>, value: T) => void): () => void;
|
||||||
changed<T>(component: Entity<T>, listener: (e: Entity, id: Id<T>, value: T) => void): () => void;
|
changed<T>(
|
||||||
|
component: Entity<T>,
|
||||||
|
listener: (e: Entity, id: Id<T>, value: T) => void,
|
||||||
|
): () => void;
|
||||||
removed<T>(component: Entity<T>, listener: (e: Entity, id: Id<T>) => void): () => void;
|
removed<T>(component: Entity<T>, listener: (e: Entity, id: Id<T>) => void): () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -349,14 +381,14 @@ export type ComponentRecord = {
|
||||||
|
|
||||||
export function component_record(world: World, id: Id): ComponentRecord;
|
export function component_record(world: World, id: Id): ComponentRecord;
|
||||||
|
|
||||||
type TagToUndefined<T> = T extends TagDiscriminator ? undefined : T
|
type TagToUndefined<T> = T extends TagDiscriminator ? undefined : T;
|
||||||
type TrimOptional<T extends unknown[]> = T extends [...infer L, infer R]
|
type TrimOptional<T extends unknown[]> = T extends [...infer L, infer R]
|
||||||
? unknown extends R
|
? unknown extends R
|
||||||
? L | T | TrimOptional<L>
|
? L | T | TrimOptional<L>
|
||||||
: R extends undefined
|
: R extends undefined
|
||||||
? L | T | TrimOptional<L>
|
? L | T | TrimOptional<L>
|
||||||
: T
|
: T
|
||||||
: T
|
: T;
|
||||||
|
|
||||||
export function bulk_insert<const C extends Id[]>(
|
export function bulk_insert<const C extends Id[]>(
|
||||||
world: World,
|
world: World,
|
||||||
|
|
@ -367,9 +399,9 @@ export function bulk_insert<const C extends Id[]>(
|
||||||
export function bulk_remove(world: World, entity: Entity, ids: Id[]): void;
|
export function bulk_remove(world: World, entity: Entity, ids: Id[]): void;
|
||||||
|
|
||||||
export type EntityRecord<T extends Id[]> = {
|
export type EntityRecord<T extends Id[]> = {
|
||||||
archetype: Archetype<T>,
|
archetype: Archetype<T>;
|
||||||
row: number,
|
row: number;
|
||||||
dense: number,
|
dense: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function record<T extends Id[] = []>(world: World, entity: Entity): EntityRecord<T>;
|
export function record<T extends Id[] = []>(world: World, entity: Entity): EntityRecord<T>;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue