mirror of
				https://github.com/Ukendio/jecs.git
				synced 2025-11-04 10:59:18 +00:00 
			
		
		
		
	roblox-ts: Fix columns_map for easier lookups (#263)
	
		
			
	
		
	
	
		
	
		
			Some checks failed
		
		
	
	
	
				
					
				
			
		
			Some checks failed
		
		
	
	
* feat: retype archetype columns_map based on query * feat: move InferComponents into Iter
This commit is contained in:
		
							parent
							
								
									f031dcee8d
								
							
						
					
					
						commit
						ac4441eb84
					
				
					 1 changed files with 25 additions and 20 deletions
				
			
		
							
								
								
									
										45
									
								
								jecs.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										45
									
								
								jecs.d.ts
									
									
									
									
										vendored
									
									
								
							| 
						 | 
					@ -43,18 +43,18 @@ type InferComponents<A extends Id[]> = { [K in keyof A]: InferComponent<A[K]> };
 | 
				
			||||||
type ArchetypeId = number;
 | 
					type ArchetypeId = number;
 | 
				
			||||||
export type Column<T> = T[];
 | 
					export type Column<T> = T[];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export type Archetype<T extends unknown[]> = {
 | 
					export type Archetype<T extends Id[]> = {
 | 
				
			||||||
	id: number;
 | 
						id: number;
 | 
				
			||||||
	types: number[];
 | 
						types: number[];
 | 
				
			||||||
	type: string;
 | 
						type: string;
 | 
				
			||||||
	entities: number[];
 | 
						entities: number[];
 | 
				
			||||||
	columns: Column<unknown>[];
 | 
						columns: Column<unknown>[];
 | 
				
			||||||
	columns_map: Record<Id, Column<T[number]>>
 | 
						columns_map: { [K in T[number]]: Column<InferComponent<K>> };
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Iter<T extends unknown[]> = IterableFunction<LuaTuple<[Entity, ...T]>>;
 | 
					type Iter<T extends Id[]> = IterableFunction<LuaTuple<[Entity, ...InferComponents<T>]>>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export type CachedQuery<T extends unknown[]> = {
 | 
					export type CachedQuery<T extends Id[]> = {
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Returns an iterator that produces a tuple of [Entity, ...queriedComponents].
 | 
						 * Returns an iterator that produces a tuple of [Entity, ...queriedComponents].
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
| 
						 | 
					@ -67,7 +67,7 @@ export type CachedQuery<T extends unknown[]> = {
 | 
				
			||||||
	archetypes(): Archetype<T>[];
 | 
						archetypes(): Archetype<T>[];
 | 
				
			||||||
} & Iter<T>;
 | 
					} & Iter<T>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export type Query<T extends unknown[]> = {
 | 
					export type Query<T extends Id[]> = {
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Returns an iterator that produces a tuple of [Entity, ...queriedComponents].
 | 
						 * Returns an iterator that produces a tuple of [Entity, ...queriedComponents].
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
| 
						 | 
					@ -246,11 +246,11 @@ export class World {
 | 
				
			||||||
	 * @param components The list of components to query.
 | 
						 * @param components The list of components to query.
 | 
				
			||||||
	 * @returns A Query object to iterate over results.
 | 
						 * @returns A Query object to iterate over results.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	query<T extends Id[]>(...components: T): Query<InferComponents<T>>;
 | 
						query<T extends Id[]>(...components: T): Query<T>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	added<T>(component: Entity<T>, listener: (e: Entity, id: Id<T>, value: T) => void): () => void
 | 
						added<T>(component: Entity<T>, listener: (e: Entity, id: Id<T>, value: T) => void): () => void;
 | 
				
			||||||
	changed<T>(component: Entity<T>, listener: (e: Entity, id: Id<T>, value: T) => void): () => void
 | 
						changed<T>(component: Entity<T>, listener: (e: Entity, id: Id<T>, value: T) => void): () => void;
 | 
				
			||||||
	removed<T>(component: Entity<T>, listener: (e: Entity, id: Id<T>) => void): () => void
 | 
						removed<T>(component: Entity<T>, listener: (e: Entity, id: Id<T>) => void): () => void;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function world(): World;
 | 
					export function world(): World;
 | 
				
			||||||
| 
						 | 
					@ -297,11 +297,11 @@ export function ECS_PAIR_FIRST(pair: Pair): number;
 | 
				
			||||||
export function ECS_PAIR_SECOND(pair: Pair): number;
 | 
					export function ECS_PAIR_SECOND(pair: Pair): number;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type StatefulHook = Entity<<T>(e: Entity<T>, id: Id<T>, data: T) => void> & {
 | 
					type StatefulHook = Entity<<T>(e: Entity<T>, id: Id<T>, data: T) => void> & {
 | 
				
			||||||
	readonly __nominal_StatefulHook: unique symbol,
 | 
						readonly __nominal_StatefulHook: unique symbol;
 | 
				
			||||||
}
 | 
					};
 | 
				
			||||||
type StatelessHook = Entity<<T>(e: Entity<T>, id: Id<T>) => void> & {
 | 
					type StatelessHook = Entity<<T>(e: Entity<T>, id: Id<T>) => void> & {
 | 
				
			||||||
	readonly __nominal_StatelessHook: unique symbol,
 | 
						readonly __nominal_StatelessHook: unique symbol;
 | 
				
			||||||
}
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export declare const OnAdd: StatefulHook;
 | 
					export declare const OnAdd: StatefulHook;
 | 
				
			||||||
export declare const OnRemove: StatelessHook;
 | 
					export declare const OnRemove: StatelessHook;
 | 
				
			||||||
| 
						 | 
					@ -319,12 +319,17 @@ export declare const Exclusive: Tag;
 | 
				
			||||||
export declare const Rest: Entity;
 | 
					export declare const Rest: Entity;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export type ComponentRecord = {
 | 
					export type ComponentRecord = {
 | 
				
			||||||
	records: Map<Id, number>,
 | 
						records: Map<Id, number>;
 | 
				
			||||||
	counts: Map<Id, number>,
 | 
						counts: Map<Id, number>;
 | 
				
			||||||
	size: number,
 | 
						size: number;
 | 
				
			||||||
}
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function component_record(world: World, id: Id): ComponentRecord
 | 
					export function component_record(world: World, id: Id): ComponentRecord;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function bulk_insert<const C extends Id[]>(world: World, entity: Entity, ids: C, values: InferComponents<C>): void
 | 
					export function bulk_insert<const C extends Id[]>(
 | 
				
			||||||
export function bulk_remove(world: World, entity: Entity, ids: Id[]): void
 | 
						world: World,
 | 
				
			||||||
 | 
						entity: Entity,
 | 
				
			||||||
 | 
						ids: C,
 | 
				
			||||||
 | 
						values: InferComponents<C>,
 | 
				
			||||||
 | 
					): void;
 | 
				
			||||||
 | 
					export function bulk_remove(world: World, entity: Entity, ids: Id[]): void;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue