import type { ReplayChange, ReplayObject, ReplayTimeline } from "./replay.types.ts"; /** What the camera follows: nothing (the whole surface), the action (the players near the puck or ball, and it), or the puck or ball alone. */ export type FollowMode = "off" | "action" | "puck"; /** The modes, in the order the controls list them after "off". */ export declare const FOLLOW_MODES: readonly FollowMode[]; /** A mode from anything: `action` and `puck` are themselves, everything else is `off`. */ export declare const followMode: (value: unknown) => FollowMode; /** A rectangle in the drawing's own feet. */ export interface FollowBox { x: number; y: number; w: number; h: number; } /** Where the camera looks: the middle of the frame, in the drawing's feet, and how much it magnifies the surface (1 is the whole of it: the frame is the surface's size over `zoom`). */ export interface FollowShot { x: number; y: number; zoom: number; } /** How the camera frames and moves. Shares are of the surface's length (its longer side). */ export interface FollowLimits { /** The closest the camera comes: the frame is never smaller than the surface over this. */ maxZoom: number; /** The zoom of `puck`. */ puckZoom: number; /** How many of the players nearest the puck the action is framed round. */ near: number; /** The room left round the action, a share of the surface's length on each side. */ pad: number; /** A move of the shot smaller than this share of the frame does not move the camera, and a zoom that changes by less than this share does not zoom it. */ dead: number; /** How quickly the spring follows, in radians a second: about 4.7 over this many seconds settles it. */ omega: number; /** The room kept between the puck and the edge of the frame, a share of the frame. */ leash: number; } /** The camera's limits by default: no closer than two and a half times, the puck followed at twice, the five nearest players, settling in about a second and a half. */ export declare const FOLLOW_LIMITS: Readonly; /** What the shot is worked out from at a moment: the objects in the drawing's feet, the surface, and the faceoff dot when the play is stopped. */ export interface FollowInput { objects: readonly Pick[]; box: FollowBox; /** The faceoff dot while the play is stopped (see `followStop`): the camera goes there. */ stop?: readonly [number, number]; } /** The whole surface: the shot of `off`. */ export declare const wholeShot: (box: FollowBox) => FollowShot; /** A shot held to the limits: its zoom from 1 to `maxZoom`, and its frame on the surface (the middle moved in until no side of the frame is off it). */ export declare function clampShot(shot: FollowShot, box: FollowBox, maxZoom?: number): FollowShot; /** The frame a shot shows: the surface's size over the zoom, round the middle. */ export declare const frameOf: (shot: FollowShot, box: FollowBox) => FollowBox; /** * The shot the play asks for at a moment. `action` frames the puck (or the ball) and the `near` players nearest it, with `pad` round them, never closer than `maxZoom`: when they bunch at one end * it closes in, and when they spread it pulls back. `puck` puts the puck in the middle at `puckZoom`. A stopped play (`stop`) frames the faceoff dot as closely as the limits allow. The frame is * always on the surface and always holds the puck. Without a puck the action is the players' middle; with nothing at all it is the whole surface. * @example * ```ts * import { followShot } from "@johnmorrisdotca/kyogijo-stadiums/replay"; * const box = { x: 0, y: 0, w: 200, h: 85 }; * const objects = [{ team: "puck" as const, x: 170, y: 40 }, { team: "home" as const, x: 165, y: 30 }, { team: "away" as const, x: 175, y: 50 }]; * const action = followShot("action", { objects, box }); * console.log(Math.round(action.x), action.y, Math.round(action.zoom * 100) / 100); * console.log(followShot("puck", { objects, box })); * // 148 40 1.93 * // { x: 150, y: 40, zoom: 2 } * ``` */ export declare function followShot(mode: FollowMode, input: FollowInput, limits?: Partial): FollowShot; /** * One step of a critically damped spring toward `goal`: where it is and how fast it goes after `dt` seconds. It never overshoots and never rings, and a long step lands nearer, never past. * @example * ```ts * import { springStep } from "@johnmorrisdotca/kyogijo-stadiums/replay"; * let [x, v] = [0, 0]; * for (let i = 0; i < 60; i += 1) [x, v] = springStep(x, v, 10, 1 / 60, 4); * console.log(Math.round(x * 100) / 100, x < 10); * // 9.08 true * ``` */ export declare function springStep(at: number, speed: number, goal: number, dt: number, omega: number): [number, number]; /** What `followCamera` gives back. */ export interface FollowCamera { /** Move toward the shot the play asks for: by `dt` seconds of the spring, or at once (`dt` undefined). Gives where it is now. */ update(mode: FollowMode, input: FollowInput, dt?: number): FollowShot; /** Where it is now. */ shot(): FollowShot | undefined; /** Whether it is at rest on the whole surface: `off`, and nothing left to ease back. */ resting(): boolean; /** Forget where it was: the next update starts from the whole surface. */ reset(): void; } /** * The camera that follows the play: it eases toward `followShot` with a critically damped spring on the middle and on the zoom (the zoom eased as its logarithm, so a zoom in and a zoom out * take the same time), holds still while the shot moves less than a dead zone, and is kept on the surface, never closer than the limit, with the puck inside the frame. When the play is still * it comes to rest and stays exactly there. * @example * ```ts * import { followCamera } from "@johnmorrisdotca/kyogijo-stadiums/replay"; * const camera = followCamera(); * const input = { box: { x: 0, y: 0, w: 200, h: 85 }, objects: [{ team: "puck" as const, x: 180, y: 40 }] }; * const first = camera.update("puck", input, 1 / 60); * let shot = first; * for (let i = 0; i < 600; i += 1) shot = camera.update("puck", input, 1 / 60); * console.log(first.zoom < 1.01, shot); * // true { x: 150, y: 40, zoom: 2 } * ``` */ export declare function followCamera(limits?: Partial): FollowCamera; /** * How much a view magnifies for a shot's zoom, when the view at 1 shows more than the surface (`room` times it: the margin round a flat drawing, the stands round a 3D one). At a zoom of 1 the * view is as it was; at `maxZoom` the frame fills it; in between the two are joined smoothly, and the view never shows less than the frame. */ export declare function zoomFor(zoom: number, room: number, maxZoom?: number): number; /** * The part of a flat drawing to show for a shot: a rectangle in the drawing's `viewBox` units, of the viewBox's shape, round the shot's middle, inside the viewBox, and never smaller than the * shot's frame. `map` takes a point of the surface's frame to the viewBox's (a surface laid tall is turned a quarter in its drawing). * @example * ```ts * import { followWindow } from "@johnmorrisdotca/kyogijo-stadiums/replay"; * const box = { x: 0, y: 0, w: 200, h: 85 }; * const view = { x: -8, y: -8, w: 216, h: 101 }; * console.log(followWindow({ x: 100, y: 42.5, zoom: 1 }, box, view)); * console.log(followWindow({ x: 160, y: 42.5, zoom: 2.5 }, box, view)); * // { x: -8, y: -8, w: 216, h: 101 } * // { x: 120, y: 23.8, w: 80, h: 37.41 } * ``` */ export declare function followWindow(shot: FollowShot, box: FollowBox, view: FollowBox, map?: (p: [number, number]) => [number, number], maxZoom?: number): FollowBox; /** * The faceoff dot, in the timeline's frame, while the play is stopped at `t`: from a whistle or a goal until the next `faceoff` event that has a place (`x` and `y`), the place of that faceoff. * `undefined` while the play goes on, and always for a timeline with no `faceoff` events: the camera then follows the puck through the stoppage as at any other time. * @example * ```ts * import { followStop } from "@johnmorrisdotca/kyogijo-stadiums/replay"; * const timeline = { frames: [{ t: 0, objects: [] }, { t: 30, objects: [] }], events: [{ t: 10, kind: "whistle" }, { t: 20, kind: "faceoff", x: 69, y: 22 }] }; * console.log(followStop(timeline, 5), followStop(timeline, 15), followStop(timeline, 25)); * // undefined [ 69, 22 ] undefined * ``` */ export declare function followStop(timeline: ReplayTimeline, t: number): [number, number] | undefined; /** What a runner is given: the timeline, where its objects are in the drawing at a time, the surface, a clock in milliseconds, and how to show a shot (`undefined` gives back the whole drawing). */ export interface FollowSource { timeline: ReplayTimeline; /** The objects at a time and the faceoff dot of a stoppage, in the drawing's feet. */ at(t: number, stop: readonly [number, number] | undefined): FollowInput; now(): number; show(shot: FollowShot | undefined): void; limits?: Partial; } /** What `followRunner` gives back. */ export interface FollowRunner { /** The replay's clock changed: move the camera for it. */ paint(change: ReplayChange): void; /** Show the shot again (the drawing was written again). */ again(): void; /** Forget the shot: the camera starts from the whole surface. */ reset(): void; } /** * The camera of a replay in a page: on each tick of the clock the spring moves by the seconds that went by; a seek, a step, or a change of mode while paused puts the camera where it should be at * once (a reader who prefers reduced motion gets only steps); a play, a pause, a change of speed or loop moves nothing. Nothing runs between changes, and off and at rest it does nothing at all. */ export declare function followRunner(source: FollowSource): FollowRunner;