@game-vir/entity
Version:
Entity system for game development.
28 lines (27 loc) • 1.22 kB
TypeScript
import { type AnyObject } from '@augment-vir/common';
import { type AbstractConstructor, type Constructor } from 'type-fest';
/**
* Map all ancestor constructors of an object to the objects.
*
* @category Internal
*/
export declare class ConstructorMap {
protected readonly topMostConstructor: Function | undefined;
/** A map of constructors to their added instances. */
readonly map: Map<Function, Set<AnyObject>>;
readonly isDestroyed: boolean;
constructor(topMostConstructor?: Function | undefined);
/**
* Add a new instance, mapping each of its ancestor constructors to it inside
* {@link ConstructorMap.map}.
*/
add(instance: AnyObject): void;
/** Gets all added instances of the given constructor. */
getInstances<T>(constructor: AbstractConstructor<T> | Constructor<T>): Set<T>;
/** Remove a new instance, removing it from all mappings inside {@link ConstructorMap.map}. */
remove(instance: AnyObject): void;
/** Recursively map all ancestor prototypes to the given instance. */
protected traverseConstructors(instance: AnyObject, prototype: any, operation: 'add' | 'remove'): void;
/** Clean up the internal map. */
destroy(): void;
}