@hiddentao/clockwork-engine
Version:
A TypeScript/PIXI.js game engine for deterministic, replayable games with built-in rendering
87 lines • 3.13 kB
TypeScript
import { EventEmitter } from "./EventEmitter";
import type { GameObject } from "./GameObject";
import type { IGameLoop } from "./IGameLoop";
export declare enum GameObjectGroupEventType {
ITEM_ADDED = "itemAdded",
ITEM_REMOVED = "itemRemoved",
LIST_CLEARED = "listCleared",
DESTROYED_ITEMS_CLEARED = "destroyedItemsCleared"
}
export interface GameObjectGroupEvents extends Record<string, (...args: any[]) => void> {
[GameObjectGroupEventType.ITEM_ADDED]: (gameObject: GameObject) => void;
[GameObjectGroupEventType.ITEM_REMOVED]: (gameObjectId: string) => void;
[GameObjectGroupEventType.LIST_CLEARED]: () => void;
[GameObjectGroupEventType.DESTROYED_ITEMS_CLEARED]: (gameObjects: GameObject[]) => void;
}
/**
* A group/collection manager for GameObjects
*/
export declare class GameObjectGroup<T extends GameObject = GameObject> extends EventEmitter<GameObjectGroupEvents> implements IGameLoop {
protected gameObjects: Map<string, T>;
constructor();
/**
* Add a GameObject to the group
* @param gameObject The GameObject to add
* @returns The same GameObject that was added
*/
add(gameObject: T): T;
/**
* Remove a GameObject from the group
* @param gameObject The GameObject to remove
* @returns True if the GameObject was removed, false if it wasn't in the group
*/
remove(gameObject: T): boolean;
/**
* Check if a GameObject is in the group
* @param gameObject The GameObject to check for
* @returns True if the GameObject is in the group
*/
has(gameObject: T): boolean;
/**
* Check if a GameObject with the given ID is in the group
* @param id The ID to check for
* @returns True if a GameObject with this ID is in the group
*/
hasId(id: string): boolean;
/**
* Get a GameObject by its ID
* @param id The ID of the GameObject to retrieve
* @returns The GameObject with the given ID, or undefined if not found
*/
getById(id: string): T | undefined;
/**
* Get all active (non-destroyed) GameObjects
* @returns Array of active GameObjects
*/
getAllActive(): T[];
/**
* Get the number of GameObjects in the group
* @returns Total count of GameObjects (including destroyed ones)
*/
size(): number;
/**
* Get the number of active (non-destroyed) GameObjects
* @returns Count of non-destroyed GameObjects
*/
activeSize(): number;
/**
* Clear all GameObjects from the group
*/
clear(): void;
/**
* Destroy all active GameObjects and then clear the group
*/
clearAndDestroy(): void;
/**
* Remove all destroyed GameObjects from the group
* @returns Number of destroyed GameObjects that were removed
*/
clearDestroyed(): number;
/**
* Update all GameObjects in the group
* @param deltaTicks Number of ticks since last update
* @param totalTicks Total number of ticks processed since start
*/
update(deltaTicks: number, totalTicks: number): void;
}
//# sourceMappingURL=GameObjectGroup.d.ts.map