import type Application from "./../application/application.ts"; import Camera2d from "./../camera/camera2d.ts"; import { Color } from "./../math/color.ts"; import type World from "./../physics/world.js"; import type Light2d from "./../renderable/light2d.js"; import type Renderer from "./../video/renderer.js"; interface StageSettings { cameras: Camera2d[]; /** * Default camera class to instantiate when this stage has no * explicit `cameras` list. Overrides any app-level `cameraClass` * setting for this specific stage. Built-in stages (e.g. * {@link DefaultLoadingScreen}) pin this to {@link Camera2d} so * the loader stays 2D regardless of app-wide `cameraClass`. */ cameraClass?: new (minX: number, minY: number, maxX: number, maxY: number) => Camera2d; onResetEvent?: (app: Application, ...args: unknown[]) => void; onDestroyEvent?: (app: Application) => void; } /** * a default "Stage" object. * every "stage" object (title screen, credits, ingame, etc...) to be managed * through the state manager must inherit from this base class. * @category Application * @see state */ export default class Stage { /** * The list of active cameras in this stage. * Cameras will be rendered based on this order defined in this list. * Only the "default" camera will be resized when the window or canvas is resized. */ cameras: Map; /** * The list of active lights in this stage. * * Since 19.3.0, `Light2d` is a first-class world Renderable — the * recommended pattern is to add lights directly to `app.world` (or any * container, including a sprite, so the light follows it via parent * transforms). The `lights` Map remains for backward compatibility: * any entry added via `this.lights.set(name, light)` in * `onResetEvent()` is automatically adopted into the world tree at * stage reset time so it renders normally. * @see Light2d * @see Stage.ambientLight * @example * // recommended: * const whiteLight = new Light2d(100, 100, 140, 140, "#fff", 0.7); * app.world.addChild(whiteLight); * * // legacy (still works, auto-adopted into world): * this.lights.set("whiteLight", whiteLight); * * this.ambientLight.parseCSS("#1117"); */ lights: Map; /** * Internal set of active lights, auto-populated by `Light2d`'s * `onActivateEvent` / `onDeactivateEvent` hooks. Used by Camera2d's * ambient-overlay pass to compute the cutouts. * @ignore */ _activeLights: Set; /** * an ambient light that will be added to the stage rendering * @default "#000000" * @see Light2d */ ambientLight: Color; /** * Base light level applied to every normal-mapped sprite in the * lit rendering path. Unlike {@link Stage#ambientLight} (which is * the dark overlay punched by each light's cutout), this color is * added to every lit pixel so unlit areas don't render pure * black. Defaults to black (0, 0, 0) — sprites without a * `normalMap` ignore it entirely. * @default "#000000" */ ambientLightingColor: Color; /** * The given constructor options */ settings: StageSettings; /** * @param settings - The stage parameters * @param [settings.cameras=[]] - a list of cameras (experimental) * @param [settings.onResetEvent] - called by the state manager when reseting the object * @param [settings.onDestroyEvent] - called by the state manager before switching to another state */ constructor(settings?: Partial); /** * Called by `Light2d.onActivateEvent` to register the light with the * stage's ambient-overlay cutout list. Users normally don't call this. * @ignore */ _registerLight(light: Light2d): void; /** * Called by `Light2d.onDeactivateEvent` to deregister the light. * @ignore */ _unregisterLight(light: Light2d): void; /** * Object reset function * @ignore */ reset(app: Application, ...extraArgs: unknown[]): void; /** * update function * @ignore * @param dt - time since the last update in milliseconds. * @returns true if the stage needs to be redrawn */ update(dt: number): boolean; /** * draw the current stage * * Lights are rendered as part of the world tree (they're now first-class * Renderables) and the ambient overlay pass runs inside each Camera's * post-effect FBO bracket via {@link Stage#drawLighting}. * @ignore * @param renderer - the renderer object to draw with * @param world - the world object to draw */ draw(renderer: Renderer, world: World): void; /** * Draw the stage's ambient-light overlay with cutouts for each active * light. Called from each `Camera2d` inside its post-effect FBO bracket — * lights themselves render via the world tree (they're standard * Renderables); this pass only paints the dark fill that the lights cut * holes through. * * Subclasses can override this method to implement custom lighting (e.g. * per-pixel normal-mapped lighting via a custom shader). Called once per * camera per frame. * @param renderer - the active renderer * @param camera - the camera currently rendering this stage * @param translateX - the same world-to-screen X translate that * `Camera2d.draw()` applies to the world container (i.e. * `camera.pos.x + camera.offset.x` for the default camera, plus * the container's own offset for non-default cameras) * @param translateY - the world-to-screen Y translate (see `translateX`) */ drawLighting(renderer: Renderer, camera: Camera2d, translateX?: number, translateY?: number): void; /** * destroy function * @ignore */ destroy(app: Application): void; /** * onResetEvent function
* called by the state manager when resetting the object * this is typically where you will load a level, add renderables, etc... * @param app - the current application instance * @param args - optional arguments passed when switching state * @see state#change */ onResetEvent(app: Application, ...args: unknown[]): void; /** * onDestroyEvent function
* called by the state manager before switching to another state * @param app - the current application instance */ onDestroyEvent(app: Application): void; } export {}; //# sourceMappingURL=stage.d.ts.map