diff --git a/src/lib/ecs/query.ts b/src/lib/ecs/query.ts index 2de068f..e978d2c 100644 --- a/src/lib/ecs/query.ts +++ b/src/lib/ecs/query.ts @@ -220,40 +220,30 @@ export class Query { /** * Runs a callback for each entity that matches the query. * - * If the callback returns `false`, the iteration will stop, and no other - * entities in this query will be iterated over. - * - * #### Usage Example: - * ```ts - * query.forEach((entity) => { - * // ... - * }); - * ``` - * - * @param callback The callback to run for each entity. + * TODO: This should be turned into a *[Symbol.iterator] method whenever + * that is supported. */ - public forEach(callback: (entityId: EntityId) => boolean | void): void { + public *iter(): Generator { for (const archetype of this.archetypes) { for (const entityId of archetype.entities) { - if (callback(entityId) === false) { - return; - } + yield entityId; } } } /** - * Runs a callback for each entity that matches the query. - * - * TODO: This should be turned into a *[Symbol.iterator] method whenever - * that is supported. + * @returns an array of all matching entities mapped to their IDs. */ - public *iterate(): Generator { + public items(): Array { + const idList: Array = new Array(); + for (const archetype of this.archetypes) { for (const entityId of archetype.entities) { - yield entityId; + idList.push(entityId); } } + + return idList; } /**