mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-25 09:30:03 +00:00
Consistent formatting
This commit is contained in:
parent
eeb48035eb
commit
1d51d79f3f
1 changed files with 148 additions and 128 deletions
94
lib/index.d.ts
vendored
94
lib/index.d.ts
vendored
|
@ -1,57 +1,56 @@
|
|||
type Archetype = {
|
||||
id: number,
|
||||
id: number;
|
||||
edges: {
|
||||
[key: number]: {
|
||||
add: Archetype,
|
||||
remove: Archetype,
|
||||
},
|
||||
},
|
||||
types: Array<number>,
|
||||
type: string | number,
|
||||
entities: Array<number>,
|
||||
columns: Array<Array<unknown>>,
|
||||
records: { [key: number]: number },
|
||||
}
|
||||
add: Archetype;
|
||||
remove: Archetype;
|
||||
};
|
||||
};
|
||||
types: Array<number>;
|
||||
type: string | number;
|
||||
entities: Array<number>;
|
||||
columns: Array<Array<unknown>>;
|
||||
records: { [key: number]: number };
|
||||
};
|
||||
|
||||
type ArchetypeMap = {
|
||||
cache: Array<number>,
|
||||
first: ArchetypeMap,
|
||||
second: ArchetypeMap,
|
||||
parent: ArchetypeMap,
|
||||
size: number,
|
||||
}
|
||||
cache: Array<number>;
|
||||
first: ArchetypeMap;
|
||||
second: ArchetypeMap;
|
||||
parent: ArchetypeMap;
|
||||
size: number;
|
||||
};
|
||||
|
||||
type Query<T extends unknown[]> = {
|
||||
without: (...components: Entity[]) => Query<T>;
|
||||
} & IterableFunction<LuaTuple<[Entity, ...T]>>
|
||||
} & IterableFunction<LuaTuple<[Entity, ...T]>>;
|
||||
|
||||
// Exported due to functions below requiring this type.
|
||||
export type EntityIndex = {
|
||||
dense: {
|
||||
[key: number]: number
|
||||
[key: number]: number;
|
||||
};
|
||||
sparse: {
|
||||
[key: number]: {
|
||||
archetype: Archetype,
|
||||
row: number,
|
||||
dense: number,
|
||||
componentRecord: ArchetypeMap,
|
||||
}
|
||||
}
|
||||
}
|
||||
archetype: Archetype;
|
||||
row: number;
|
||||
dense: number;
|
||||
componentRecord: ArchetypeMap;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
// 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 InferComponents<A extends Entity[]> = {
|
||||
[K in keyof A]: EntityType<A[K]>
|
||||
[K in keyof A]: EntityType<A[K]>;
|
||||
};
|
||||
type Nullable<T extends unknown[]> = {
|
||||
[K in keyof T]: T[K] | undefined
|
||||
}
|
||||
[K in keyof T]: T[K] | undefined;
|
||||
};
|
||||
|
||||
export class World {
|
||||
|
||||
/**
|
||||
* Creates a new World
|
||||
*/
|
||||
|
@ -124,7 +123,11 @@ export class World {
|
|||
* @param component2 Target Component 2
|
||||
* @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.
|
||||
|
@ -134,7 +137,12 @@ export class World {
|
|||
* @param component3 Target Component 3
|
||||
* @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.
|
||||
|
@ -145,14 +153,20 @@ export class World {
|
|||
* @param component4 Target Component 4
|
||||
* @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
|
||||
* @param components Queried Components
|
||||
* @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;
|
||||
|
@ -169,7 +183,13 @@ export const ECS_ID: (e: Entity) => Entity;
|
|||
export const ECS_PAIR: (pred: Entity, obj: Entity) => Entity;
|
||||
export const ECS_GENERATION_INC: (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_OBJECT: <T>(entityIndex: EntityIndex, e: Entity<T>) => Entity;
|
||||
export const ECS_PAIR_RELATION: <T>(
|
||||
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;
|
Loading…
Reference in a new issue