From 5c19a3b595c04ec5de413bfd0b706da7fff707c3 Mon Sep 17 00:00:00 2001 From: maeriil <104389763+maeriil@users.noreply.github.com> Date: Fri, 31 Jan 2025 09:29:32 -0500 Subject: [PATCH] Typescript Types for Archetypes * resolves #182 - TS types for Archetypes * description for archetype query * updated archetype number type --- jecs.d.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/jecs.d.ts b/jecs.d.ts index 136dcb9..c5288de 100644 --- a/jecs.d.ts +++ b/jecs.d.ts @@ -40,6 +40,23 @@ type FlattenTuple = T extends [infer U] ? U : LuaTuple; type Nullable = { [K in keyof T]: T[K] | undefined }; type InferComponents = { [K in keyof A]: InferComponent }; +type ArchetypeId = number +type Column = unknown[]; + +type ArchetypeRecord = { + count: number; + column: number; +} + +export type Archetype = { + id: number; + types: number[]; + type: string; + entities: number[]; + columns: Column[]; + records: ArchetypeRecord[]; +} + type Iter = IterableFunction>; export type CachedQuery = { @@ -47,6 +64,12 @@ export type CachedQuery = { * Returns an iterator that produces a tuple of [Entity, ...queriedComponents]. */ iter(): Iter; + + /** + * Returns the matched archetypes of the query + * @returns An array of archetypes of the query + */ + archetypes(): Archetype[]; } & Iter; export type Query = { @@ -75,6 +98,12 @@ export type Query = { * @returns A new Query with the exclusion applied. */ without(...components: Id[]): Query; + + /** + * Returns the matched archetypes of the query + * @returns An array of archetypes of the query + */ + archetypes(): Archetype[]; } & Iter; export class World {