import { Text as Text2D } from '../text/2d/text'; import { Text as Text3D } from '../text/3d/text'; import { InputManager } from '../input/input.manager'; import { Renderer } from '../renderer/renderer'; import { ShaderProgram } from '../shader/program/shaderProgram'; import { State as State2D } from '../state/2d/state'; import { State as State3D } from '../state/3d/state'; import { System as System2D } from '../system/2d/system'; import { System as System3D } from '../system/3d/system'; import { UI as UI2D } from '../ui/2d/ui'; import { UI as UI3D } from '../ui/3d/ui'; import { World as World2D } from '../world/2d/world'; import { World as World3D } from '../world/3d/world'; import { GameConfigBase, GameConfigDefaults } from './game.config.base'; import { AudioManager } from '../audio/audio.manager'; import { ClassType } from '../aura.types'; /** * Abstract core Game; implementing the abstractable behavior for the operation of both 2D and 3D Games * * Broken down into concrete 2D and 3D variants, providing domain-specific behavior and type safety for Aura2D and Aura3D respectively * * Games operate on the Entity-Component-System architecture, and make use of States (analogous to Scenes) for runtime functionality * * This abstract Game centralises EntityManagement by weay of the World, Text and UI management utilities, as well as update and rendering * * Game execution begins when `start()` is called upon a Game instance, providing the name of a registered State to switch to */ export declare abstract class GameBase { /** Abstract 2D or 3D World; to be type narrowed by the subclass */ abstract readonly world: World2D | World3D; /** Abstract 2D or 3D Text; to be type narrowed by the subclass */ abstract readonly text: Text2D | Text3D; /** Abstract 2D or 3D UI; to be type narrowed by the subclass */ abstract readonly ui: UI2D | UI3D; /** Audio manager for adding and playing sounds */ readonly audio: AudioManager; /** InputManager */ readonly input: InputManager; /** Renderer */ readonly renderer: Renderer; /** HTML Canvas */ canvas: HTMLCanvasElement | undefined; /** Abstract mapping of 2D or 3D States, to be type narrowed by the subclass */ protected abstract readonly states: Map; /** Abstract reference to the current 2D or 3D State, to be type narrowed by the subclass */ protected abstract currentState: State2D | State3D | undefined; /** Abstract mapping of 2D or 3D Systems, to be type narrowed by the subclass */ protected abstract readonly systems: Map; /** Frame time step, calculated during run() */ protected frameDelta: number; /** Time of the last frame, set during run() */ protected lastFrameTime: number; /** Generic mapping of Game Data, useful for storing and retrieving arbitrary global data at Game runtime */ protected readonly data: Map; /** Debug Mode, as potentially set by the GameConfig */ protected debugMode: GameConfigBase['debugMode']; /** Internal-use DebugData for tracking certain game statistics while in Debug Mode */ protected readonly debugData: { frameCount: number; fps: string; }; /** * Default GameConfig fallback values for various configuration options */ protected readonly defaults: GameConfigDefaults; /** * Reference to the potential GameConfig init() method */ protected init: GameConfigBase['init']; /** * Flag for whether or not the Game is stopped and therefore should not request any animation frames */ private stopped; /** * Constructor. Take an optional GameConfig, and initialise all generic/abstractable aspects of the Game * * @param config the optional GameConfig */ constructor(config: GameConfigBase, defaultShaders: Array); /** * Abstract single 2D or 3D State addition; to be implemented and type narrowed by the subclass * * @param state the 2D or 3D State to add */ abstract addState(state: State2D | State3D): void; /** * Abstract multi 2D or 3D State addition; to be implemented and type narrowed by the subclass * * @param states the 2D or 3D States to add */ abstract addStates(...states: Array): void; /** * Switch to the named State * * Ends the current State, then initializes the new State before switching for frame updates * * Throws an error if the desired State is not found for runtime safety * * @param name the name of the State to switch to */ switchToState(name: string): void; /** * Abstract single 2D or 3D System addition; to be implemented and type narrowed by the subclass * * @param system the 2D or 3D System to add */ abstract addSystem(system: ClassType): void; /** * Abstract multi 2D or 3D System addition; to be implemented and type narrowed by the subclass * * @param system the 2D or 3D Systems to add */ abstract addSystems(...systems: Array>): void; /** * Remove a single System by name * * @param name the name of the System to remove */ removeSystem(name: string): void; /** * Remvove a list of Systems by name * * @param names the names of the Systems to remove */ removeSystems(...names: Array): void; /** * Check if the Game has a named System * * @param name the name of the System to check * * @returns whether or not the Game has the named System */ hasSystem(name: string): boolean; /** * Check if the Game has a list of named Systems * * @param names the names of the Systems to check * * @returns whether or not the Game has all of the named Systems */ hasSystems(...names: Array): boolean; /** * Abstract system retrieval method; to be implemented and type narrowed by the subclass * * @param name the name of the system to retrieve * * @returns the retrieved system */ abstract getSystem(name: string): System2D | System3D; /** * Set the value of some arbitrary generic Game Data * * @typeparam the type of the data being set * * @param key the key for the Data * @param value the value for the Data */ setData(key: string, value: T): void; /** * Retrieve the value of some arbitrary generic Game Data by key * * Throws an error if there's no data by the given key * * @typeparam T the type of the Data being retrieved * * @param key the key of the Data to retrieve * * @returns the retrieved Data */ getData(key: string): T; /** * Delete some arbitrary generic Game Data by key * * @param key the key of the Data to delete */ deleteData(key: string): void; /** * Create a given ShaderProgram, making it available for use in Entity Shader Components * * All ShaderPrograms to be used by the application should be registered before execution is begun with `start()` * * @param shader the ShaderProgram to register */ registerShader(shader: ShaderProgram): void; /** * Begin game executon by calling the optional GameConfig init(), switching to the named State, and finally executing the main loop * * @param state the name of the State to start with */ start(state: string): void; /** * Destroy the game [WIP] */ destroy(): void; /** * Abstract State initialization routine, to be implemented by the subclass for type safety in State initialization methods */ protected abstract initState(): void; /** * Abstract State end routine, to be implemented by the subclass for type safety in State end methods */ protected abstract endState(): void; /** * Abstract frame update routine; to be implemented by the subclass for type safety on core construct update routines */ protected abstract update(): void; /** * Main game execution routine, representing the production of a single frame * * Performs the following actions in order: * - calculates the frame delta * - executes the abstract update(), triggering the update of all Systems and the current State * - executes the World update() * - executes the UI update() * - executed the Font update() * - clears the screen * - renders the World * - renders the UI * - renders the Font * - handles debugData if appropriate */ private run; }