import type { EntityMap } from './entity-map.js'; import { ComponentIterator } from './iterator.js'; import type { ComponentClass, ComponentClasses, Iterator, SingleOrArray } from './types.js'; /** * A reusable query for retrieving entities and their components * @category Queries * @example * const query = ecs.query(Player, Position) * * // get the first entry * const [playerId, player, position] = query.firstEntry() ?? [] * * // get the first key * const [playerId, position] = query.firstKey() ?? [] * * // get the first value * const [player, position] = query.firstValue() ?? [] * * // iterate * for (const [playerId, player, position] of query) { * * } */ export declare class ComponentQuery { ecs: EntityMap; private keyMap; private componentMaps; /** * Creates a new component query * @param ecs - The {@link EntityMap} instance to query * @param components - The first component class is the primary component. Optional additional component classes to retrieve for each entity. * @throws {@link ComponentNotRegistered} when any of specified component(s) are not registered */ constructor(ecs: EntityMap, ...components: [ComponentClass, ...ComponentClasses]); /** * Gets the first entry matching the query. * * Includes the entity id, the key component data, and any related component data. * @returns A tuple of `[entityId, keyComponentData, ...relatedComponentData]`, or `undefined` if no entities match. */ firstEntry(): [number, TKey, ...TRelated] | undefined; /** * Gets the first key matching the query. * * @returns The entity id if no related components were specified in the constructor. * * Otherwise, a tuple of `[entityId, ...relatedComponentData]`. * * Returns `undefined` if no entities match. */ firstKey(): SingleOrArray<[number, ...TRelated]> | undefined; /** * Get the first component data matching the query. * * @returns The key component data if no related components were specified in the constructor. * * Otherwise, a tuple of `[keyComponentData, ...relatedComponentData]`. * * Returns `undefined` if no entities match. */ firstValue(): SingleOrArray<[TKey, ...TRelated]> | undefined; /** * Returns the count of entities matching the query * @returns The number of entities that have the key component */ get entityCount(): number; /** * Destroys all entities matching the query * @returns The total number of components destroyed across all affected entities * @example * const destroyedCount = query.destroyEntities() */ destroyEntities(): number; /** * Gets all entity ids matching the query. * * @returns An {@link ArrayIterator} of entity ids. */ keys(): ArrayIterator; /** * Gets all component data matching the query. * * @returns An {@link Iterator} of `[keyComponentData, ...relatedComponentData]` tuples containing component data * @example * const query = ecs.query(Player, Position) * for (const [player, position] of query.values()) { } */ values(): Iterator<[TKey, ...TRelated]>; /** * Gets all component data entries matching the query * * @returns A {@link ComponentIterator} instance that yields `[entityId, keyComponentData, ...relatedComponentData]` * @example * const query = ecs.query(Player, Position) * for (const [entityId, player, position] of query.entries()) { } */ entries(): ComponentIterator; /** * @returns A {@link ComponentIterator} instance that yields `[entityId, keyComponentData, ...relatedComponentData]` */ [Symbol.iterator](): ComponentIterator; } //# sourceMappingURL=query.d.ts.map