UNPKG

@miniplex/core

Version:

A developer-friendly entity management system for games and similarly demanding applications, based on ECS architecture.

55 lines (54 loc) 2.33 kB
import { Bucket } from "./Bucket"; import { IEntity } from "./types"; export declare class World<E extends IEntity> extends Bucket<E> { constructor(...args: ConstructorParameters<typeof Bucket<E>>); private nextId; private entityToId; private idToEntity; /** * Returns the ID of the given entity. If the entity is not known to this world, * it returns `undefined`. * * @param entity The entity to get the ID of. * @returns The ID of the entity, or `undefined` if the entity is not known to this world. */ id(entity: E): number | undefined; /** * Given an ID, returns the entity with that ID. If the ID is not known to this world, * it returns `undefined`. * * @param id The ID of the entity to get. * @returns The entity with the given ID, or `undefined` if the ID is not known to this world. */ entity(id: number): E | undefined; /** * Adds a component to an entity. * If the entity already has the component, this function will do nothing. * * @param entity The entity to add the property to. * @param component The component to add. * @param value The value of the component. * @returns `true` if the entity was updated, `false` otherwise. */ addComponent<P extends keyof E>(entity: E, component: P, value: E[P]): boolean; /** * Removes a component from an entity. If the entity does not have the component, * this function will do nothing. * * @param entity The entity to remove the component from. * @param component The component to remove. * @returns `true` if the entity was updated, `false` otherwise. */ removeComponent<P extends keyof E>(entity: E, component: P): boolean; /** * Updates the value of a component on the given entity. * If the entity does not have the component, this function will do nothing. * * @param entity The entity to update. * @param component The component to update. * @param value The new value of the component. * @returns `true` if the entity was updated, `false` otherwise. */ setComponent<P extends keyof E>(entity: E, component: P, value: E[P]): boolean; archetype<P extends keyof E>(...components: P[]): Bucket<import("./types").WithRequiredKeys<E, P>>; }