import Registry from './Registry.js'; import Component from './Component.js'; import TransformComponent from '../components/TransformComponent.js'; import TagComponent from '../components/TagComponent.js'; import BoundsComponent from '../components/BoundsComponent.js'; /** * Interface representing an abstract class constructor. */ export interface AbstractConstructor { prototype: T; name: string; } /** * Base class for all entities in the game world. */ export default abstract class GameObject { /** Unique identifier for the game object. */ readonly id: string; private _components; /** * The transform component for this object, managing position and scale. */ get transform(): TransformComponent; /** * The tag component for this object, managing its name and rendering order. */ get metadata(): TagComponent; /** * The bounds component for this object, defining its physical area. */ get bounds(): BoundsComponent | undefined; /** * Sets the bounds component for this object. */ set bounds(val: BoundsComponent | undefined); /** * initialises a new instance of a GameObject. * @param tag A descriptive name for the object. * @param zIndex The rendering order (higher numbers are drawn on top). * @param sourceId Hidden identifier linking runtime object to its source code location. */ constructor(tag?: string, zIndex?: number, sourceId?: string); /** * Listens for an event on this object's event bus. * @param type The event type. * @param callback The function to run when the event occurs. */ on(type: string, callback: (event: CustomEvent) => void): void; /** * Stops listening for an event on this object's event bus. * @param type The event type. * @param callback The function to remove. */ off(type: string, callback: (event: CustomEvent) => void): void; /** * Emits a custom event on this object's event bus. * @param type The event type. * @param detail Optional data to pass with the event. */ emit(type: string, detail?: unknown): void; /** * Adds a component to this game object. * @param component The component instance to add. */ addComponent(component: Component): void; /** * Removes a component from this game object by its class. * @param componentClass The class of the component to remove. */ removeComponent(componentClass: AbstractConstructor): void; /** * Checks if this object has a component of the specified class. * @param componentClass The class to check for. * @returns True if the component exists. */ hasComponent(componentClass: AbstractConstructor): boolean; /** * Retrieves a component from this object by its class. * @param componentClass The class of the component to retrieve. * @returns The component instance, or undefined if not found. */ getComponent(componentClass: AbstractConstructor): T | undefined; /** * Registers this object with the active scene or global engine loop. */ registerSelf(): void; /** Static helper for tests to bypass Registry circularity if mocked. */ static _registry: typeof Registry; /** * Removes this object from the active scene or global engine loop. */ destroySelf(): void; }