import { Component } from "./Component"; import { EntityHandle } from './EntityHandle'; import * as EventEmitter from "eventemitter3"; import { Entity, EntityProp } from './Entity'; import { ComponentBitmaskMap } from './ComponentBitmaskMap'; export interface EntityMap { [id: string]: EntityProp; } /** * The EntityComponentManager stores and manages all Entities and their components * Its also responsible for adding and removing components from and entity or creating/removing entities */ export declare class EntityComponentManager { private readonly _events; private _uuid; private componentBitmask; private readonly _entities; constructor(componentBitmaskMap: ComponentBitmaskMap, events: EventEmitter, uuid?: () => string); /** * Creates an Entity, adds it to the list of Entities but does not add it to the actual ECS * @param entity * @param components */ createEntity(entity?: T | Entity, components?: { [x: string]: Component; }): T & EntityHandle; private updateComponentBitmask; /** * Adds the Entity with the provided Components(or existing ones) to the ECS, * @param injectedEntity - Entity to add to the ECS * @param components - Components for the entity, if provided this will override the current components of the entity * @param silent - dispatch the entityAdded signal(If added silent the entity wont be added to an system) * @param silentWorker - do not dispatch entity added worker - used to manage shared entities between WebWorkers */ addEntity(entity: T, components?: { [x: string]: Component; }, silent?: boolean, silentWorker?: boolean): T & Entity; /** * Updates entities, if the entity already exists the old and new components will be merged * otherwise the entity will be added as a new entity * @param entities * @param silent * @param silentWorker */ updateEntities(entities: EntityMap, silent?: boolean, silentWorker?: boolean): void; /** * returns a list of entities that match the given bitmask * @param bitmask */ getEntitiesByBitmask(bitmask: number): Entity[]; /** * Return a list of entities with the specified components * since we need to check all entities this can be quite slow * @param components - list of components the entity needs to have */ getEntities(...components: { new (config?: { [p: string]: any; }): any; }[]): T[]; /** * @param entity - Entity to remove * @param silent - do not dispatch onEntityRemoved Signal(Removing the Entity from the Systems)# * @param silentWorker - do not dispatch WorkerEvent * @returns {Entity} - the removed Entity */ removeEntity(entity: T, silent?: boolean, silentWorker?: boolean): T; /** * removes all Entities from the ecs */ removeAllEntities(): Entity[]; /** * Returns true if the entity is in the ECS * @param entity * @returns {boolean} */ hasEntity(entity: EntityProp): boolean; /** * Adds a component to the Entity * @param entity - Entity * @param component - Component to add * @param silent - If true this onComponentAdded signal is not dispatched and no system is updated * @param silentWorker - if true no worker signal is dispatched */ addComponent(entity: EntityProp, component: T, silent?: boolean, silentWorker?: boolean): void; /** * Removes a component from the Entity * @param entity - Entity * @param component - Component type to remove or the Id * @param silent - if true the onComponentRemoved signal is not dispatched and no system will be updated * @param silentWorker * @returns {boolean} */ removeComponent(entity: EntityProp, component: { new (...args: any[]): T; } | string, silent?: boolean, silentWorker?: boolean): boolean; readonly entities: { [p: string]: Entity; }; uuid: () => string; readonly events: EventEmitter; }