import { LevelConfig, LevelConstructor, PropertyHandler } from "../interfaces/level.d.ts"; import { Disposable } from "../interfaces/lifecycle.d.ts"; import { Level } from "../classes/level.d.ts"; import { GameEventBus } from "../classes/eventBus.d.ts"; import { GameEngine } from "../classes/gameEngine.d.ts"; import { LoggingUtility } from "../utils/logger.d.ts"; /** * Options for level transitions. */ export interface TransitionOptions { /** If true, the old level is kept loaded (not disposed) after transitioning away */ keepAlive?: boolean; /** If true, the new level is loaded but not activated — currentLevel remains unchanged */ preloadOnly?: boolean; } /** * Manages game levels, acting as a factory for level instantiation. * * The LevelManager is responsible for: * - Registering level configurations and custom level classes * - Creating level instances with properly injected dependencies * - Managing the lifecycle of loaded levels (loading, activation, disposal) * * Levels are not instantiated directly. Instead, use the manager's factory methods: * * ```typescript * // Register a config * levelManager.registerLevelConfig({ name: 'Level1', scene: 'level1.glb' }); * * // Register a custom level class * levelManager.registerLevelClass('custom', MyCustomLevel); * * // Load creates the instance with deps injected * await levelManager.loadLevel('Level1'); * ``` */ export declare class LevelManager implements Disposable { private _eventBus; private _gameEngine; private _log; private _logger?; /** Map of registered level configurations by name */ private _levelConfigs; /** Map of registered custom level classes by name */ private _levelClasses; /** Map of loaded level instances by name */ private _loadedLevels; /** Map of registered property handlers for scene node metadata */ private _propertyHandlers; /** The currently active level */ private _currentLevel; /** Unsubscribe functions for event subscriptions */ private _eventUnsubscribers; /** * Gets the currently active level */ get currentLevel(): Level | null; /** * Gets the registered property handlers */ get propertyHandlers(): Map; constructor(eventBus: GameEventBus, logger?: LoggingUtility); /** * Late-bind the GameEngine after construction. * Called by createGameEngine() after the GameEngine instance is created. */ $setGameEngine(gameEngine: GameEngine): void; private _handleProgress; private _handleComplete; private _handleError; /** * Creates the LevelContext with all dependencies */ private _createContext; /** * Creates a Level instance from a config using the appropriate class */ private _createLevelInstance; /** * Registers a level configuration. * The level will be instantiated when loadLevel() is called. * * @param config */ registerLevelConfig(config: LevelConfig): void; /** * Registers a custom Level class that can be referenced in configs. * When a config specifies `class: "my-level"`, this class will be instantiated. * * @param name - The key used in LevelConfig.class to reference this constructor * @param levelClass */ registerLevelClass(name: string, levelClass: LevelConstructor): void; /** * Register a property handler for processing custom properties on scene nodes. * Handlers are called for each node that has the specified property in its metadata. * * @param property - The metadata property name to match (e.g., 'sound', 'collider') * @param handler */ registerPropertyHandler(property: string, handler: PropertyHandler): void; /** * Unregister a property handler. * * @param property */ unregisterPropertyHandler(property: string): void; /** * Clear all registered property handlers. * Primarily useful for testing to ensure a clean state between tests. */ clearAllPropertyHandlers(): void; /** * Gets a loaded level by name. * Returns null if the level is not currently loaded. * * @param name */ getLevel(name: string): Level | null; /** * Gets a registered level config by name. * * @param name */ getLevelConfig(name: string): LevelConfig | null; /** * Loads a level by name. The level config must be registered first. * * @param name */ loadLevel(name: string): Promise; /** * Loads a level from a config. The config will be registered automatically. * * @param config */ loadLevel(config: LevelConfig): Promise; /** * Activates a level by name, loading it if necessary. * * @param name */ activateLevel(name: string): Promise; /** * Activates a level from a config, loading it if necessary. * * @param config */ activateLevel(config: LevelConfig): Promise; /** * Unloads a level and disposes its resources. * Clears currentLevel if this was the active level. * * @param name */ unloadLevel(name: string): Promise; /** * Unloads the current level and disposes its resources */ unloadCurrentLevel(): Promise; /** * Orchestrates a level-to-level transition with lifecycle hooks and events. * * Flow: deactivate old -> load new -> dispose old (unless keepAlive) -> activate new. * If `preloadOnly` is true, the new level is loaded but not activated. * * @param levelName - The name of the level to transition to (must be registered) * @param options */ transition(levelName: string, options?: TransitionOptions): Promise; /** * Tears down the level manager and cleans up any resources */ $teardown(): Promise; }