diff --git a/src/index.d.ts b/src/index.d.ts index 19c5ed7..6d7e771 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -3,7 +3,16 @@ type Query = { /** * this: Query is necessary to use a colon instead of a period for emits. */ + + /** + * Resets the Iterator for a query. + */ drain: (this: Query) => Query + /** + * Modifies the query to include specified components, but will not include the values. + * @param components The components to include + * @returns Modified Query + */ with: (this: Query, ...components: Entity[]) => Query /** * Modifies the Query to exclude specified components @@ -15,7 +24,7 @@ type Query = { * Modifies component data with a callback function * @param fn The function to modify data */ - replace: (this: Query, fn: (...components: T) => T extends [infer U] ? U : LuaTuple) => void; + replace: (this: Query, fn: (...components: T) => FlattenTuple) => void; } & IterableFunction>; // Utility Types @@ -27,6 +36,15 @@ export type InferComponents = { type Nullable = { [K in keyof T]: T[K] | undefined; }; +type FlattenTuple = T extends [infer U] ? U : LuaTuple; + +// Utility type for world:get +type TupleForWorldGet = + | [Entity] + | [Entity, Entity] + | [Entity, Entity, Entity] + | [Entity, Entity, Entity, Entity] + | [Entity, Entity, Entity, Entity, Entity] export class World { /** @@ -64,6 +82,7 @@ export class World { /** * Deletes an entity and all its related components and relationships. + * For most situations, you should be using the clear method instead of deletion. * @param id Entity to be destroyed */ delete(id: Entity): void; @@ -93,57 +112,14 @@ export class World { // Manually typed out get since there is a hard limit. /** - * Retrieves the value of one component. This value may be undefined. + * Retrieves the values of specified components for an entity. + * Some values may not exist when called. + * A maximum of 5 components are allowed at a time. * @param id Target Entity - * @param component Target Component - * @returns Data associated with the component if it exists + * @param components Target Components + * @returns Data associated with target components if it exists. */ - get(id: number, component: Entity): A | undefined; - - /** - * Retrieves the value of two components. This value may be undefined. - * @param id Target Entity - * @param component Target Component 1 - * @param component2 Target Component 2 - * @returns Data associated with the components if it exists - */ - get( - id: number, - component: Entity, - component2: Entity - ): LuaTuple>; - - /** - * Retrieves the value of three components. This value may be undefined. - * @param id Target Entity - * @param component Target Component 1 - * @param component2 Target Component 2 - * @param component3 Target Component 3 - * @returns Data associated with the components if it exists - */ - get( - id: number, - component: Entity, - component2: Entity, - component3: Entity - ): LuaTuple>; - - /** - * Retrieves the value of four components. This value may be undefined. - * @param id Target Entity - * @param component Target Component 1 - * @param component2 Target Component 2 - * @param component3 Target Component 3 - * @param component4 Target Component 4 - * @returns Data associated with the components if it exists - */ - get( - id: number, - component: Entity, - component2: Entity, - component3: Entity, - component4: Entity - ): LuaTuple>; + get(id: Entity, ...components: T): FlattenTuple>> /** * Searches the world for entities that match a given query