UNPKG

ecsjs

Version:

An entity component system library for JavaScript

37 lines 1.36 kB
import type { EntityMap } from './entity-map.js'; import type { ComponentClass, ComponentInstances, IteratorResult } from './types.js'; /** * @category Iterators * @example * // construct an instance * const iterator = new ComponentIterator(entityMap, Player, Position) * * // iterate each component value that is related to the Player * for(const [entityId, player, position] of iterator) { } * * // you can also reset the iterator back to the start * // without having to create a new ComponentIterator instance * iterator.reset() * for(const [entityId, player, position] of iterator) { } */ export declare class ComponentIterator<TComponentKey extends ComponentClass<any>, TComponentClasses extends ComponentClass<any>[]> { ecs: EntityMap; key: TComponentKey; private keyMap; private components; private entries; /** * {@link ComponentNotRegistered} when any of specified component(s) are not registered */ constructor(ecs: EntityMap, key: TComponentKey, ...components: TComponentClasses); /** * gets the next iterator value */ next(): IteratorResult<ComponentInstances<[ComponentClass<number>, TComponentKey, ...TComponentClasses]>>; /** * resets the iterator back to the first entry */ reset(): void; [Symbol.iterator](): this; } //# sourceMappingURL=iterators.d.ts.map