mirror of
				https://github.com/Ukendio/jecs.git
				synced 2025-10-31 17:20:32 +00:00 
			
		
		
		
	Fix get type to include undefined and add documentation
This commit is contained in:
		
							parent
							
								
									5475b69e1c
								
							
						
					
					
						commit
						aa6fe8d92b
					
				
					 1 changed files with 93 additions and 5 deletions
				
			
		
							
								
								
									
										98
									
								
								lib/index.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										98
									
								
								lib/index.d.ts
									
									
									
									
										vendored
									
									
								
							|  | @ -56,24 +56,112 @@ export type EntityType<T> = T extends Entity<infer A> ? A : never; | |||
| export type InferComponents<A extends Entity[]> = { | ||||
|     [K in keyof A]: EntityType<A[K]> | ||||
| }; | ||||
| 
 | ||||
| type PossiblyUndefinedPack<T extends unknown[]> = { | ||||
| 	[K in keyof T]: T[K] | undefined | ||||
| } | ||||
| 
 | ||||
| export class World { | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Creates a new World | ||||
| 	 */ | ||||
| 	constructor(); | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Creates a new entity | ||||
| 	 * @returns Entity | ||||
| 	 */ | ||||
|     entity(): Entity; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Creates a new entity located in the first 256 ids. | ||||
| 	 * These should be used for static components for fast access. | ||||
| 	 * @returns Entity<T> | ||||
| 	 */ | ||||
|     component<T = unknown>(): Entity<T>; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Gets the target of a relationship. For example, when a user calls | ||||
| 	 * `world.target(id, ChildOf(parent))`, you will obtain the parent entity. | ||||
| 	 * @param id Entity | ||||
| 	 * @param relation The Relationship | ||||
| 	 * @returns The Parent Entity if it exists | ||||
| 	 */ | ||||
|     target(id: Entity, relation: Entity): Entity | undefined; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Deletes an entity and all its related components and relationships. | ||||
| 	 * @param id Entity to be destroyed | ||||
| 	 */ | ||||
|     delete(id: Entity): void; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Adds a component to the entity with no value | ||||
| 	 * @param id Target Entity | ||||
| 	 * @param component Component | ||||
| 	 */ | ||||
|     add<T>(id: Entity, component: Entity<T>): void; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Assigns a value to a component on the given entity | ||||
| 	 * @param id Target Entity | ||||
| 	 * @param component Target Component | ||||
| 	 * @param data Component Data | ||||
| 	 */ | ||||
|     set<T>(id: Entity, component: Entity<T>, data: T): void; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Removes a component from the given entity | ||||
| 	 * @param id Target Entity | ||||
| 	 * @param component Target Component | ||||
| 	 */ | ||||
|     remove(id: Entity, component: Entity): void; | ||||
| 
 | ||||
|     get<A>(id: number, component: Entity<A>): A; // Manually typed out since there is a hard limit.
 | ||||
|     get<A, B>(id: number, component: Entity<A>, component2: Entity<B>): LuaTuple<[A, B]>; | ||||
|     get<A, B, C>(id: number, component: Entity<A>, component2: Entity<B>, component3: Entity<C>): LuaTuple<[A, B, C]>; | ||||
|     get<A, B, C, D>(id: number, component: Entity<A>, component2: Entity<B>, component3: Entity<C>, component4: Entity<D>): LuaTuple<[A, B, C, D]>; | ||||
| 	// 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 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<A, B>(id: number, component: Entity<A>, component2: Entity<B>): LuaTuple<PossiblyUndefinedPack<[A, B]>>; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * 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<A, B, C>(id: number, component: Entity<A>, component2: Entity<B>, component3: Entity<C>): LuaTuple<PossiblyUndefinedPack<[A, B, C]>>; | ||||
| 
 | ||||
| 	/** | ||||
| 	 * 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<A, B, C, D>(id: number, component: Entity<A>, component2: Entity<B>, component3: Entity<C>, component4: Entity<D>): LuaTuple<PossiblyUndefinedPack<[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>> | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue