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
276
lib/index.d.ts
vendored
276
lib/index.d.ts
vendored
|
@ -1,158 +1,172 @@
|
||||||
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: {
|
||||||
|
[key: number]: {
|
||||||
|
archetype: Archetype;
|
||||||
|
row: number;
|
||||||
|
dense: number;
|
||||||
|
componentRecord: ArchetypeMap;
|
||||||
};
|
};
|
||||||
sparse: {
|
};
|
||||||
[key: number]: {
|
};
|
||||||
archetype: Archetype,
|
|
||||||
row: number,
|
|
||||||
dense: number,
|
|
||||||
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
|
||||||
|
*/
|
||||||
|
constructor();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new World
|
* Creates a new entity
|
||||||
*/
|
* @returns Entity
|
||||||
constructor();
|
*/
|
||||||
|
entity(): Entity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new entity
|
* Creates a new entity located in the first 256 ids.
|
||||||
* @returns Entity
|
* These should be used for static components for fast access.
|
||||||
*/
|
* @returns Entity<T>
|
||||||
entity(): Entity;
|
*/
|
||||||
|
component<T = unknown>(): Entity<T>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new entity located in the first 256 ids.
|
* Gets the target of a relationship. For example, when a user calls
|
||||||
* These should be used for static components for fast access.
|
* `world.target(id, ChildOf(parent))`, you will obtain the parent entity.
|
||||||
* @returns Entity<T>
|
* @param id Entity
|
||||||
*/
|
* @param relation The Relationship
|
||||||
component<T = unknown>(): Entity<T>;
|
* @returns The Parent Entity if it exists
|
||||||
|
*/
|
||||||
|
target(id: Entity, relation: Entity): Entity | undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the target of a relationship. For example, when a user calls
|
* Deletes an entity and all its related components and relationships.
|
||||||
* `world.target(id, ChildOf(parent))`, you will obtain the parent entity.
|
* @param id Entity to be destroyed
|
||||||
* @param id Entity
|
*/
|
||||||
* @param relation The Relationship
|
delete(id: Entity): void;
|
||||||
* @returns The Parent Entity if it exists
|
|
||||||
*/
|
|
||||||
target(id: Entity, relation: Entity): Entity | undefined;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes an entity and all its related components and relationships.
|
* Adds a component to the entity with no value
|
||||||
* @param id Entity to be destroyed
|
* @param id Target Entity
|
||||||
*/
|
* @param component Component
|
||||||
delete(id: Entity): void;
|
*/
|
||||||
|
add<T>(id: Entity, component: Entity<T>): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a component to the entity with no value
|
* Assigns a value to a component on the given entity
|
||||||
* @param id Target Entity
|
* @param id Target Entity
|
||||||
* @param component Component
|
* @param component Target Component
|
||||||
*/
|
* @param data Component Data
|
||||||
add<T>(id: Entity, component: Entity<T>): void;
|
*/
|
||||||
|
set<T>(id: Entity, component: Entity<T>, data: T): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assigns a value to a component on the given entity
|
* Removes a component from the given entity
|
||||||
* @param id Target Entity
|
* @param id Target Entity
|
||||||
* @param component Target Component
|
* @param component Target Component
|
||||||
* @param data Component Data
|
*/
|
||||||
*/
|
remove(id: Entity, component: Entity): void;
|
||||||
set<T>(id: Entity, component: Entity<T>, data: T): void;
|
|
||||||
|
|
||||||
/**
|
// Manually typed out get since there is a hard limit.
|
||||||
* Removes a component from the given entity
|
|
||||||
* @param id Target Entity
|
|
||||||
* @param component Target Component
|
|
||||||
*/
|
|
||||||
remove(id: Entity, component: Entity): void;
|
|
||||||
|
|
||||||
// Manually typed out get since there is a hard limit.
|
/**
|
||||||
|
* Retrieves the value of one component. This value may be undefined.
|
||||||
|
* @param id Target Entity
|
||||||
|
* @param component Target Component
|
||||||
|
* @returns Data associated with the component if it exists
|
||||||
|
*/
|
||||||
|
get<A>(id: number, component: Entity<A>): A | undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the value of one component. This value may be undefined.
|
* Retrieves the value of two components. This value may be undefined.
|
||||||
* @param id Target Entity
|
* @param id Target Entity
|
||||||
* @param component Target Component
|
* @param component Target Component 1
|
||||||
* @returns Data associated with the component if it exists
|
* @param component2 Target Component 2
|
||||||
*/
|
* @returns Data associated with the components if it exists
|
||||||
get<A>(id: number, component: Entity<A>): A | undefined;
|
*/
|
||||||
|
get<A, B>(
|
||||||
|
id: number,
|
||||||
|
component: Entity<A>,
|
||||||
|
component2: Entity<B>
|
||||||
|
): LuaTuple<Nullable<[A, B]>>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the value of two components. This value may be undefined.
|
* Retrieves the value of three components. This value may be undefined.
|
||||||
* @param id Target Entity
|
* @param id Target Entity
|
||||||
* @param component Target Component 1
|
* @param component Target Component 1
|
||||||
* @param component2 Target Component 2
|
* @param component2 Target Component 2
|
||||||
* @returns Data associated with the components if it exists
|
* @param component3 Target Component 3
|
||||||
*/
|
* @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, C>(
|
||||||
|
id: number,
|
||||||
|
component: Entity<A>,
|
||||||
|
component2: Entity<B>,
|
||||||
|
component3: Entity<C>
|
||||||
|
): LuaTuple<Nullable<[A, B, C]>>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the value of three components. This value may be undefined.
|
* Retrieves the value of four components. This value may be undefined.
|
||||||
* @param id Target Entity
|
* @param id Target Entity
|
||||||
* @param component Target Component 1
|
* @param component Target Component 1
|
||||||
* @param component2 Target Component 2
|
* @param component2 Target Component 2
|
||||||
* @param component3 Target Component 3
|
* @param component3 Target Component 3
|
||||||
* @returns Data associated with the components if it exists
|
* @param component4 Target Component 4
|
||||||
*/
|
* @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, D>(
|
||||||
|
id: number,
|
||||||
|
component: Entity<A>,
|
||||||
|
component2: Entity<B>,
|
||||||
|
component3: Entity<C>,
|
||||||
|
component4: Entity<D>
|
||||||
|
): LuaTuple<Nullable<[A, B, C, D]>>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the value of four components. This value may be undefined.
|
* Searches the world for entities that match a given query
|
||||||
* @param id Target Entity
|
* @param components Queried Components
|
||||||
* @param component Target Component 1
|
* @returns Iterable function
|
||||||
* @param component2 Target Component 2
|
*/
|
||||||
* @param component3 Target Component 3
|
query<T extends Entity[]>(...components: T): Query<InferComponents<T>>;
|
||||||
* @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]>>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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>>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|
Loading…
Reference in a new issue