UNPKG

@curbl/ecs

Version:

Small Entity Component System

53 lines (52 loc) 1.78 kB
import { Entity } from './entity'; import { System } from './system'; export declare class ECS { private readonly entityStore; private readonly systemStore; private readonly componentBitMask; constructor(); setMaxEntityPoolSize(size: number): void; setUpdateMethods(methods: string[]): void; reset(): void; addEntity(...components: unknown[]): Readonly<Entity>; addSystem(system: System): void; active(entity: Entity): boolean; removeSystem(system: System): void; hasSystem(system: System): boolean; /** * Register as a Component * * @ECS.Component('quad') * class Quad { * size: number; * } * * @ECS.System('quad') * class QuadSystem extends System { * update() { * const entity = this.entities[0]; * entity.get('quad'); * } * } * *internal* sets the static __id and __bit property * @param id * @constructor */ Component(id: string): <T extends new (...args: any[]) => any>(constructor: T) => T; /** * register as system * a system gets all entities with the specified components * @ECS.Component('position') * class Position { x = 0; y = 0; } * @ECS.System('position') * class PositionSystem extends System {} * @param components * @returns */ System(...components: [string, ...string[]] | [new (...args: any[]) => any, ...(new (...args: any[]) => any)[]]): <T extends new (...args: any[]) => any>(constructor: T) => { new (...args: any[]): { [x: string]: any; }; } & T; update(a1?: any, a2?: any, a3?: any, a4?: any, a5?: any, a6?: any, a7?: any, a8?: any, a9?: any): void; }