Skip to content

Commit

Permalink
resolves #182 - TS types for Archetypes
Browse files Browse the repository at this point in the history
  • Loading branch information
maeriil committed Jan 31, 2025
1 parent cc7daa6 commit 2c2b327
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions jecs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,39 @@ type FlattenTuple<T extends unknown[]> = T extends [infer U] ? U : LuaTuple<T>;
type Nullable<T extends unknown[]> = { [K in keyof T]: T[K] | undefined };
type InferComponents<A extends Id[]> = { [K in keyof A]: InferComponent<A[K]> };

type i53 = number
type i24 = number
type Ty = i53[];
type ArchetypeId = number
type Column = unknown[];

type ArchetypeRecord = {
count: number;
column: number;
}

export type Archetype = {
id: number;
types: Ty;
type: string;
entities: number[];
columns: Column[];
records: ArchetypeRecord[];
}

type Iter<T extends unknown[]> = IterableFunction<LuaTuple<[Entity, ...T]>>;

export type CachedQuery<T extends unknown[]> = {
/**
* Returns an iterator that produces a tuple of [Entity, ...queriedComponents].
*/
iter(): Iter<T>;

/**
* Returns the archetype of the query
* @returns An array of archetype of the query
*/
archetypes(): Archetype[];
} & Iter<T>;

export type Query<T extends unknown[]> = {
Expand Down Expand Up @@ -75,6 +101,12 @@ export type Query<T extends unknown[]> = {
* @returns A new Query with the exclusion applied.
*/
without(...components: Id[]): Query<T>;

/**
* Returns the archetype of the query
* @returns An array of archetype of the query
*/
archetypes(): Archetype[];
} & Iter<T>;

export class World {
Expand Down

0 comments on commit 2c2b327

Please sign in to comment.