UNPKG

@curbl/ecs

Version:

Small Entity Component System

63 lines (62 loc) 2.23 kB
import { EntityStore } from './entityStore'; import { Bitmask } from './bitmask'; export interface Entity { __id: string; __bitmask: Bitmask; get<T>(component: string | (new (...args: any[]) => T)): T; has<T>(component: string | (new (...args: any[]) => T)): boolean; add<T>(component: T): void; remove<T>(component: string | (new (...args: any[]) => T)): void; dispose(): void; pause(): void; unpause(): void; active(): boolean; __updateMaskAndNew(): void; __updateRemoved(): void; } export declare class EntityHandle implements Entity { readonly __id: string; readonly __bitmask: Bitmask; private dead; private dirty; private paused; private readonly store; private readonly components; private readonly updates; private readonly removedComponents; constructor(id: string, store: EntityStore); private addComponent; add<T>(component: T): void; get<T>(component: string | (new (...args: any[]) => T)): T; has<T>(component: string | (new (...args: any[]) => T)): boolean; private removeComponent; remove<T>(component: string | (new (...args: any[]) => T)): void; dispose(): void; active(): boolean; /** * remove the entity from the ECS(all systems) * and do not handle updates, components can still be removed or added * but they wont be active until the entity is unpaused * Note: this will trigger onEntityRemoved on all systems containing the entity */ pause(): void; /** * unpause the entity adding it back to the ecs and all systems * triggering onEntityAdded for all systems again */ unpause(): void; /** * update the removed components */ __updateRemoved(): void; /** * update bitmask and add new components * this way system update events like onEntityAdded will be called with the new components * and onEntityRemoved will still have the removed components * make sure to call __updateRemoved afterwards to actually remove the components */ __updateMaskAndNew(): void; private markDirty; private __add; private __clear; }