All files / player-skin-sdk/src dom.ts

0% Statements 0/0
0% Branches 0/0
0% Functions 0/0
0% Lines 0/0

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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132                                                                                                                                                                                                                                                                       
import type { CourseView, PlayOptions, PlayState } from '@be-music/player-scene-model';
import type { LibraryEntry, LibraryChart } from './chart.ts';
import type { BeMusicResultData } from './result-data.ts';
import type { BeMusicSkinSettingValues } from './settings.ts';
import type {
  BeMusicEffectLevel,
  BeMusicGameplayFrame,
  BeMusicGameplayLayout,
  BeMusicGameplayRuntime,
  BeMusicPlayOptionChoices,
} from './types.ts';
 
/** A native DOM screen. Mount once, update without replacing focused elements, dispose once. */
export interface BeMusicDOMScreen<Frame> {
  update(frame: Frame): void;
  dispose(): void;
  /** Select screens may expose their native search field to host search shortcuts. */
  focusSearch?(): void;
}
 
/** The host owns the mount element; the skin owns its children and event listeners. No Pixi object crosses here. */
export type BeMusicDOMFactory<Frame, Actions, Screen extends BeMusicDOMScreen<Frame> = BeMusicDOMScreen<Frame>> = (
  container: HTMLElement,
  actions: Actions,
) => Screen;
 
/**
 * A gameplay screen. For a skin that sets `gameplay.drawsOnDOM`, the host hands it every frame's playfield through
 * {@link drawPlayfield} instead of drawing the skin on a Canvas surface, and allocates no surface for gameplay.
 */
export interface BeMusicDOMGameplayScreen extends BeMusicDOMScreen<BeMusicDOMGameplayFrame> {
  /** Called once per frame, before the player renders, with the lanes, notes and hit effects collected for it. */
  drawPlayfield?(frame: BeMusicGameplayFrame): void;
}
 
export interface BeMusicDOMPresentation {
  readonly settings: BeMusicSkinSettingValues;
  readonly effects: BeMusicEffectLevel;
}
 
export interface BeMusicDOMSelectFrame extends BeMusicDOMPresentation {
  readonly revision: number;
  readonly entries: readonly LibraryEntry[];
  readonly selectedIndex: number;
  readonly folderLabel: string | undefined;
  readonly searchQuery: string;
  /** Why the chart filter expression searched for (`?…`) does not parse; the list is not filtered meanwhile. */
  readonly searchError?: string;
  readonly playOptions: Readonly<PlayOptions>;
  readonly playOptionChoices: BeMusicPlayOptionChoices;
  /** Whether the chart under the cursor has a README (a `.txt` file beside it); the host shows it in its own dialog. */
  readonly hasReadme: boolean;
  readonly launching: boolean;
}
 
export interface BeMusicDOMSelectActions {
  focus(index: number): void;
  activate(): void;
  back(): void;
  search(query: string): void;
  play(autoPlay?: boolean): void;
  setPlayOption<K extends keyof PlayOptions>(key: K, value: PlayOptions[K]): void;
  /** Opens the README of the chart under the cursor, or closes the one shown. */
  readText(): void;
  gesture(): void;
}
 
/** Small HUD state: note arrays, textures and rendering caches stay with the Canvas renderer. */
export interface BeMusicDOMGameplayFrame extends BeMusicDOMPresentation {
  /** Design stage, layout mode, lanes, lane bounds and BGA rect, for placing DOM controls clear of the playfield. */
  readonly layout: Pick<BeMusicGameplayLayout, 'mode' | 'stage' | 'orientation' | 'lanes' | 'playfield' | 'bga'>;
  readonly chart: LibraryChart | undefined;
  readonly state: Readonly<PlayState>;
  /** The 2P player's play state of a two-player play (LR2 BATTLE); `runtime.secondPlayer` has its figures. */
  readonly state2P?: Readonly<PlayState>;
  /** The same resource-free HUD values available to Canvas skins. */
  readonly runtime: Readonly<BeMusicGameplayRuntime>;
  readonly playOptions: Readonly<PlayOptions>;
  readonly emptyPoor: number;
  readonly course?: CourseView;
  readonly seconds: number;
  readonly bpm: number | undefined;
  readonly progress: number | undefined;
  readonly stage: 'loading' | 'intro' | 'playing' | 'paused' | 'ending';
  readonly autoPlay: boolean;
  readonly replay: boolean;
  /** Whether {@link BeMusicDOMGameplayActions.seek} moves the play now: an AUTO play, replay or opted-in manual practice play. */
  readonly seekable: boolean;
}
 
export interface BeMusicDOMGameplayActions {
  pause(): void;
  restart(): void;
  quit(): void;
  /** Moves the play to chart second `seconds` and plays on from there; ignored unless the frame is `seekable`. */
  seek(seconds: number): void;
}
 
export interface BeMusicDOMResultFrame extends BeMusicDOMPresentation {
  readonly result: BeMusicResultData;
  readonly inputReady: boolean;
}
 
export interface BeMusicDOMResultActions {
  continue(): void;
  retry(): void;
}
 
export interface BeMusicDOMDecideFrame extends BeMusicDOMPresentation {
  readonly chart: LibraryChart;
  /** Validated pre-play title artwork URL, owned by the host. Missing/undecodable images use the title text. */
  readonly titleImage?: string;
  readonly progress: number | undefined;
  readonly inputReady: boolean;
}
 
export interface BeMusicDOMDecideActions {
  continue(): void;
  cancel(): void;
}
 
/**
 * DOM replaces select/decide/result drawing when provided. Gameplay DOM accompanies the Canvas playfield, or replaces
 * it for a skin that sets `gameplay.drawsOnDOM`.
 */
export interface BeMusicDOMSkin {
  readonly select?: BeMusicDOMFactory<BeMusicDOMSelectFrame, BeMusicDOMSelectActions>;
  readonly decide?: BeMusicDOMFactory<BeMusicDOMDecideFrame, BeMusicDOMDecideActions>;
  readonly result?: BeMusicDOMFactory<BeMusicDOMResultFrame, BeMusicDOMResultActions>;
  readonly gameplay?: BeMusicDOMFactory<BeMusicDOMGameplayFrame, BeMusicDOMGameplayActions, BeMusicDOMGameplayScreen>;
}