Consistent formatting

This commit is contained in:
EncodedVenom 2024-06-15 15:17:24 -04:00
parent eeb48035eb
commit 1d51d79f3f

94
lib/index.d.ts vendored
View file

@ -1,57 +1,56 @@
type Archetype = { type Archetype = {
id: number, id: number;
edges: { edges: {
[key: number]: { [key: number]: {
add: Archetype, add: Archetype;
remove: Archetype, remove: Archetype;
}, };
}, };
types: Array<number>, types: Array<number>;
type: string | number, type: string | number;
entities: Array<number>, entities: Array<number>;
columns: Array<Array<unknown>>, columns: Array<Array<unknown>>;
records: { [key: number]: number }, records: { [key: number]: number };
} };
type ArchetypeMap = { type ArchetypeMap = {
cache: Array<number>, cache: Array<number>;
first: ArchetypeMap, first: ArchetypeMap;
second: ArchetypeMap, second: ArchetypeMap;
parent: ArchetypeMap, parent: ArchetypeMap;
size: number, size: number;
} };
type Query<T extends unknown[]> = { type Query<T extends unknown[]> = {
without: (...components: Entity[]) => Query<T>; without: (...components: Entity[]) => Query<T>;
} & IterableFunction<LuaTuple<[Entity, ...T]>> } & IterableFunction<LuaTuple<[Entity, ...T]>>;
// Exported due to functions below requiring this type. // Exported due to functions below requiring this type.
export type EntityIndex = { export type EntityIndex = {
dense: { dense: {
[key: number]: number [key: number]: number;
}; };
sparse: { sparse: {
[key: number]: { [key: number]: {
archetype: Archetype, archetype: Archetype;
row: number, row: number;
dense: number, dense: number;
componentRecord: ArchetypeMap, componentRecord: ArchetypeMap;
} };
} };
} };
// Utility Types // Utility Types
export type Entity<T = unknown> = number & { __nominal_type_dont_use: T } export type Entity<T = unknown> = number & { __nominal_type_dont_use: T };
export type EntityType<T> = T extends Entity<infer A> ? A : never; export type EntityType<T> = T extends Entity<infer A> ? A : never;
export type InferComponents<A extends Entity[]> = { export type InferComponents<A extends Entity[]> = {
[K in keyof A]: EntityType<A[K]> [K in keyof A]: EntityType<A[K]>;
}; };
type Nullable<T extends unknown[]> = { type Nullable<T extends unknown[]> = {
[K in keyof T]: T[K] | undefined [K in keyof T]: T[K] | undefined;
} };
export class World { export class World {
/** /**
* Creates a new World * Creates a new World
*/ */
@ -124,7 +123,11 @@ export class World {
* @param component2 Target Component 2 * @param component2 Target Component 2
* @returns Data associated with the components if it exists * @returns Data associated with the components if it exists
*/ */
get<A, B>(id: number, component: Entity<A>, component2: Entity<B>): LuaTuple<Nullable<[A, B]>>; get<A, B>(
id: number,
component: Entity<A>,
component2: Entity<B>
): LuaTuple<Nullable<[A, B]>>;
/** /**
* Retrieves the value of three components. This value may be undefined. * Retrieves the value of three components. This value may be undefined.
@ -134,7 +137,12 @@ export class World {
* @param component3 Target Component 3 * @param component3 Target Component 3
* @returns Data associated with the components if it exists * @returns Data associated with the components if it exists
*/ */
get<A, B, C>(id: number, component: Entity<A>, component2: Entity<B>, component3: Entity<C>): LuaTuple<Nullable<[A, B, C]>>; get<A, B, C>(
id: number,
component: Entity<A>,
component2: Entity<B>,
component3: Entity<C>
): LuaTuple<Nullable<[A, B, C]>>;
/** /**
* Retrieves the value of four components. This value may be undefined. * Retrieves the value of four components. This value may be undefined.
@ -145,14 +153,20 @@ export class World {
* @param component4 Target Component 4 * @param component4 Target Component 4
* @returns Data associated with the components if it exists * @returns Data associated with the components if it exists
*/ */
get<A, B, C, D>(id: number, component: Entity<A>, component2: Entity<B>, component3: Entity<C>, component4: Entity<D>): LuaTuple<Nullable<[A, B, C, D]>>; get<A, B, C, D>(
id: number,
component: Entity<A>,
component2: Entity<B>,
component3: Entity<C>,
component4: Entity<D>
): LuaTuple<Nullable<[A, B, C, D]>>;
/** /**
* Searches the world for entities that match a given query * Searches the world for entities that match a given query
* @param components Queried Components * @param components Queried Components
* @returns Iterable function * @returns Iterable function
*/ */
query<T extends Entity[]>(...components: T): Query<InferComponents<T>> query<T extends Entity[]>(...components: T): Query<InferComponents<T>>;
} }
export const pair: (pred: Entity, obj: Entity) => Entity; export const pair: (pred: Entity, obj: Entity) => Entity;
@ -169,7 +183,13 @@ export const ECS_ID: (e: Entity) => Entity;
export const ECS_PAIR: (pred: Entity, obj: Entity) => Entity; export const ECS_PAIR: (pred: Entity, obj: Entity) => Entity;
export const ECS_GENERATION_INC: (e: Entity) => Entity; export const ECS_GENERATION_INC: (e: Entity) => Entity;
export const ECS_GENERATION: (e: Entity) => Entity; export const ECS_GENERATION: (e: Entity) => Entity;
export const ECS_PAIR_RELATION: <T>(entityIndex: EntityIndex, e: Entity<T>) => Entity; export const ECS_PAIR_RELATION: <T>(
export const ECS_PAIR_OBJECT: <T>(entityIndex: EntityIndex, e: Entity<T>) => Entity; entityIndex: EntityIndex,
e: Entity<T>
) => Entity;
export const ECS_PAIR_OBJECT: <T>(
entityIndex: EntityIndex,
e: Entity<T>
) => Entity;
export const getAlive: (entityIndex: EntityIndex, id: Entity) => Entity; export const getAlive: (entityIndex: EntityIndex, id: Entity) => Entity;