Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | import type { SceneKind } from '../host/family-kit.ts';
import type { ControlButton } from './controls/control-buttons.ts';
/** A key going down or up, as plain data so a session reads it without the DOM. */
export interface SessionKeyEvent {
readonly type: 'down' | 'up';
/** The physical key (`KeyboardEvent.code`, e.g. `'KeyZ'`, `'Escape'`). */
readonly code: string;
/** The key's value under the current layout (`KeyboardEvent.key`). */
readonly key: string;
/** An auto-repeat of a key held down. */
readonly repeat: boolean;
/** When the event happened (`KeyboardEvent.timeStamp`), on the host clock. */
readonly timeStamp: number;
readonly shiftKey: boolean;
readonly ctrlKey: boolean;
readonly altKey: boolean;
readonly metaKey: boolean;
/**
* The control buttons the key is under the player's keys (`controls/control-buttons.ts`): a lane key, a turntable
* key, START or SELECT. Absent from an event built without them; a screen then reads the default keys.
*/
readonly buttons?: readonly ControlButton[];
}
/** A screen's behaviour, whatever family draws it: it reads keys and intents and answers each tick with a frame. */
export interface SceneSession<Frame, Intent> {
readonly kind: SceneKind;
/** The scene is on the stage from `nowMs`: start (or restart) the session's timers and sounds. */
enter(nowMs: number): void;
/** The scene left the stage: stop the session's timers and sounds, keeping its state for the next `enter`. */
exit(): void;
/** The scene ends. */
dispose(): void;
/** A key went down or up; returns whether the session used it, so the browser does not act on it too. */
handleKey(event: SessionKeyEvent): boolean;
/** Something the player asked for on the view. */
dispatch(intent: Intent): void;
/** Advances the session to `nowMs` and returns what the view draws. */
frame(nowMs: number): Frame;
}
|