From 155a943b8c20e5cba32d09d0d5e7967705ddee32 Mon Sep 17 00:00:00 2001 From: EncodedVenom Date: Fri, 14 Jun 2024 13:25:28 -0400 Subject: [PATCH] Typescript Types --- lib/index.d.ts | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 lib/index.d.ts diff --git a/lib/index.d.ts b/lib/index.d.ts new file mode 100644 index 0000000..119b667 --- /dev/null +++ b/lib/index.d.ts @@ -0,0 +1,99 @@ +type i53 = number; +type i24 = number; + +type Ty = Array; + +type Column = Array; + +type Archetype = { + id: number, + edges: { + [key: i53]: { + add: Archetype, + remove: Archetype, + }, + }, + types: Ty, + type: string | number, + entities: Array, + columns: Array, + records: { [key: number]: number }, +} + +type ArchetypeMap = { + cache: Array, + first: ArchetypeMap, + second: ArchetypeMap, + parent: ArchetypeMap, + size: number, +} + +type ArchetypeRecord = number; + +export type Entity = number & { __nominal_type_dont_use: T } + +type EntityIndex = { + dense: { + [key: i24]: i53 + }; + sparse: { + [key: i53]: Record + } +} + +type Record = { + archetype: Archetype, + row: number, + dense: i24, + componentRecord: ArchetypeMap, +} + +type ExtractFromLuaTuple = T extends LuaTuple ? U : never; + +type QueryShim = { + without: (...args: ExtractFromLuaTuple) => QueryShim; +} & IterableFunction; + +interface World { + entity(): Entity; + component(): Entity; + + target(id: Entity, relation: Entity): Entity | undefined; + delete(id: Entity): void; + + add(id: Entity, component: Entity): void; + set(id: Entity, component: Entity, data: T): void; + remove(id: Entity, component: Entity): void; + + get(id: number, component: Entity): A; // Manually typed out since there is a hard limit. + get(id: number, component: Entity, component2: Entity): LuaTuple<[A, B]>; + get(id: number, component: Entity, component2: Entity, component3: Entity): LuaTuple<[A, B, C]>; + get(id: number, component: Entity, component2: Entity, component3: Entity, component4: Entity): LuaTuple<[A, B, C, D]>; + + query(...entities: T): QueryShim> +} + +interface WorldConstructor { + new(): World +} + +export const World: WorldConstructor; + +export const pair: (pred: Entity, obj: Entity) => Entity; + +export const OnAdd: Entity; +export const OnRemove: Entity; +export const OnSet: Entity; +export const Wildcard: Entity; +export const w: Entity; +export const REST: Entity; + +export const IS_PAIR: (e: number) => boolean; +export const ECS_ID: (e: i53) => i24; +export const ECS_PAIR: (pred: i53, obj: i53) => i53; +export const ECS_GENERATION_INC: (e: i53) => i53; +export const ECS_GENERATION: (e: i53) => i53; +export const ECS_PAIR_RELATION: (entityIndex: EntityIndex, e: Entity) => i53; +export const ECS_PAIR_OBJECT: (entityIndex: EntityIndex, e: Entity) => i53; + +export const getAlive: (entityIndex: EntityIndex, id: i24) => i53; \ No newline at end of file