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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | 28x 4x 1x 1x 1x 1x 1x 2x 2x 2x 1x 3x 4x 4x 4x 3x 1x 2x 2x 1x 2x 4x 4x 4x 4x 4x 4x | /**
* The host API for the select screen: `createSelectScene(kit, options)` pairs the select session with the view of the
* kit's family and returns the scene to show with `PixiSceneHost.setScene`.
*/
import { DOMSelectView } from '../view/built-in/dom-view.ts';
import type { BeatorajaSkinConfig } from '@be-music/skin-beatoraja';
import type { BrowseSnapshot, LibraryEntry, PlayOptions, SystemSoundSet } from '@be-music/player-scene-model';
import type { BrowserChartCollection } from '../collection/types.ts';
import { logger } from '../logger.ts';
import type { AudioService } from '../runtime/audio-service.ts';
import { SELECT_POLICIES } from '../session/select/select-policy.ts';
import { SelectSession, type SelectCourseMaker, type SelectSessionEvents } from '../session/select/select-session.ts';
import { SessionScene, type SessionSceneOptions } from '../session/session-scene.ts';
import { BeatorajaSelectView } from '../view/beatoraja/select-view.ts';
import { BuiltInSelectView } from '../view/built-in/select-view.ts';
import { LR2SelectView } from '../view/lr2/select-view.ts';
import type { SelectFrame, SelectIntent, SelectRecords, SelectView } from '../view/types.ts';
import type { SelectKit } from './family-kit.ts';
import { resolveControlScheme } from '../session/controls/control-buttons.ts';
import { resolveFamilyControlActions } from '../session/controls/control-actions.ts';
import { BEATORAJA_KEYS_FILTERS, BEATORAJA_SORTS } from '@be-music/skin-beatoraja/scene';
const log = logger('select');
/**
* The kits the select scene takes: a Be-Music Skin, an LR2 select skin (the theme's, with its bar list), or a beatoraja
* theme's select entry, loaded with `loadBeatorajaSceneKit`.
*/
export type SelectSceneKit = SelectKit;
/** What the select screen tells the host: what its session reports, and what a beatoraja skin changes of itself. */
export interface SelectSceneEvents extends SelectSessionEvents {
/**
* A beatoraja skin's JUDGE TIMING button changed the skin's options (their `offset`): keep them for the next load of
* the entry. The screen draws with them already.
*/
skinConfigChange?(config: BeatorajaSkinConfig): void;
}
export interface SelectSceneOptions extends SessionSceneOptions {
/** The library to browse, with its charts' files (the preview's samples, the images, the text files). */
readonly library: BrowserChartCollection;
/** Where to open it: a browse position saved with `snapshot()`. Without one, a library of one chart folder opens it. */
readonly browse?: BrowseSnapshot;
/** The play options to start from, over `DEFAULT_PLAY_OPTIONS`; their sort and filters shape the list. */
readonly playOptions?: Partial<PlayOptions>;
/** The player's best records, for the bars and panels. */
readonly records?: SelectRecords;
/**
* The theme's sounds: the select BGM (`selectBGM`, ducked under the chart preview), the cues, and the decide jingle
* (`decideBGM`), which plays out through the screens that follow.
*/
readonly sounds: SystemSoundSet;
readonly audio: AudioService;
/**
* The player's own courses and the course being made (LR2's course maker): an LR2 skin shows it and its finish,
* cancel and connection buttons run on it.
*/
readonly courseMaker?: SelectCourseMaker;
/** What the screen tells the host: a chart or a course started, the play options changed, and the rest. */
readonly on: SelectSceneEvents;
}
/** The select screen as a scene. */
export interface SelectScene extends SessionScene<SelectFrame, SelectIntent> {
/** The skin owns a native search input, so the host can hide its overlay input. */
readonly ownsSearchInput: boolean;
focusSearch(): boolean;
/** The browse position as plain data (`captureBrowse`): hand it back as `browse`, or to `restore`, later. */
snapshot(): BrowseSnapshot;
/** The bar under the cursor, or `undefined` when the list is empty. */
focused(): LibraryEntry | undefined;
/**
* Whether a chart was picked and the skin's launch outro is playing, before the screen hands the chart on: the host can
* make way for the screens that follow (the decide screen and the play) from here.
*/
launching(): boolean;
/** The play options in force. */
getPlayOptions(): PlayOptions;
/** Takes play options from the host; the screen does not report them back through `on.playOptions`. */
setPlayOptions(partial: Partial<PlayOptions>): void;
/**
* Takes a library: the same one again only redraws; a new one keeps the player's place over it (by folder label and
* bar key).
*/
setLibrary(library: BrowserChartCollection): void;
/** Puts the player back where a snapshot says, over the library as it is now. */
restore(snapshot: BrowseSnapshot): void;
/** The records changed (another judge ruleset, a new best, a replay slot saved): the bars and panels draw them again. */
refreshRecords(): void;
/**
* Replays the chart or course under the cursor from replay slot `slot` (0-3), as a skin's replay button does: it is
* handed on through `on.start` with `replaySlot`, with the decide cue and jingle. A slot holding no replay (by
* `records.replaySlots`) starts nothing.
*/
replay(slot: number): void;
/**
* Searches for `text`; a changed query puts the cursor on the top of the new list. A text that starts with `?` is a
* chart filter expression (the SQL `WHERE` clause of beatoraja's random courses) instead of a text search.
*/
setSearch(text: string): void;
/** Why the chart filter expression searched for does not parse, or `undefined` when it does (or is a text search). */
searchError(): string | undefined;
/** The host's text field is over the skin's search box (`true`) or has left it. */
setSearchEditing(editing: boolean): void;
/** Where the skin's search box is on the canvas, in CSS pixels, or `undefined` when it has none. */
searchFieldRect(): { x: number; y: number; width: number; height: number } | undefined;
/** Takes the theme's new sounds; a BGM playing changes to the new one. */
setSounds(sounds: SystemSoundSet): void;
/**
* Takes a new kit of the scene's family: the player's new settings for a Be-Music Skin (the scene keeps its skin),
* another LR2 select skin (a theme dropped), or a beatoraja select entry loaded again (the player's options for it,
* or another entry). The next frame draws with it. A kit of another family is ignored.
*/
updateKit(kit: SelectSceneKit): void;
}
/** A family's select view, and how it takes a new kit. */
interface FamilySelectView {
readonly view: SelectView;
updateKit(kit: SelectSceneKit): void;
}
/**
* The select view of `kit`'s family. A beatoraja skin's Lua sounds play through the audio service as the session's, so
* they stop as the screen leaves.
*/
function createSelectView(
kit: SelectSceneKit,
session: SelectSession,
options: Pick<SelectSceneOptions, 'audio' | 'on'>,
): FamilySelectView {
switch (kit.family) {
case 'lr2': {
const view = new LR2SelectView(kit);
return { view, updateKit: (next) => (next.family === 'lr2' ? view.updateKit(next) : ignoreKit(next, 'lr2')) };
}
case 'beatoraja': {
const { on } = options;
const view = new BeatorajaSelectView(kit, {
skinSounds: options.audio.skinSounds.owned(session),
...(on.skinConfigChange !== undefined ? { onSkinConfigChange: (config) => on.skinConfigChange?.(config) } : {}),
});
return {
view,
updateKit: (next) => (next.family === 'beatoraja' ? view.updateKit(next) : ignoreKit(next, 'beatoraja')),
};
}
case 'built-in': {
const view = kit.skin.dom?.select ? new DOMSelectView(kit) : new BuiltInSelectView(kit);
return {
view,
updateKit: (next) => (next.family === 'built-in' ? view.updateKit(next) : ignoreKit(next, 'built-in')),
};
}
}
}
function ignoreKit(kit: SelectSceneKit, family: SelectSceneKit['family']): void {
log.warn(`a ${family} select scene keeps its family; ignoring a ${kit.family} kit`);
}
class FamilySelectScene extends SessionScene<SelectFrame, SelectIntent> implements SelectScene {
private readonly selectSession: SelectSession;
private readonly familyView: FamilySelectView;
public constructor(session: SelectSession, familyView: FamilySelectView, options: SessionSceneOptions) {
super(session, familyView.view, options);
this.selectSession = session;
this.familyView = familyView;
}
public get ownsSearchInput(): boolean {
return this.familyView.view.ownsSearchInput === true;
}
public focusSearch(): boolean {
return this.familyView.view.focusSearch?.() ?? false;
}
public snapshot(): BrowseSnapshot {
return this.selectSession.snapshot();
}
public focused(): LibraryEntry | undefined {
return this.selectSession.focused();
}
public launching(): boolean {
return this.selectSession.launching();
}
public getPlayOptions(): PlayOptions {
return this.selectSession.getPlayOptions();
}
public setPlayOptions(partial: Partial<PlayOptions>): void {
this.selectSession.setPlayOptions(partial);
}
public setLibrary(library: BrowserChartCollection): void {
this.selectSession.setLibrary(library);
}
public restore(snapshot: BrowseSnapshot): void {
this.selectSession.restore(snapshot);
}
public refreshRecords(): void {
this.selectSession.refreshRecords();
}
public replay(slot: number): void {
this.selectSession.dispatch({ type: 'replay', slot });
}
public setSearch(text: string): void {
this.selectSession.setSearch(text);
}
public searchError(): string | undefined {
return this.selectSession.searchError();
}
public setSearchEditing(editing: boolean): void {
this.selectSession.setSearchEditing(editing);
}
public searchFieldRect(): { x: number; y: number; width: number; height: number } | undefined {
return this.familyView.view.searchFieldRect();
}
public setSounds(sounds: SystemSoundSet): void {
this.selectSession.setSounds(sounds);
}
public updateKit(kit: SelectSceneKit): void {
this.familyView.updateKit(kit);
// The view builds its skin again from the next frame.
this.selectSession.refreshRecords();
}
}
/**
* The select screen for `kit`: the session browses the library, plays the BGM, the cues, the chart preview and the
* decide jingle, and says what the player started; the kit's family view draws it. Show it with
* `PixiSceneHost.setScene`; it can leave the stage and come back (its place, its BGM's decode and its preview's focus
* are kept). Dispose it once it is gone.
*/
export function createSelectScene(kit: SelectSceneKit, options: SelectSceneOptions): SelectScene {
// The session asks the view for its skin's launch outro, and a beatoraja view's skin sounds belong to the session.
let familyView: FamilySelectView | undefined;
const scheme = resolveControlScheme(kit.family, options.controls?.builtInScheme);
const session = new SelectSession({
library: options.library,
...(options.browse !== undefined ? { browse: options.browse } : {}),
...(options.playOptions !== undefined ? { playOptions: options.playOptions } : {}),
...(options.records !== undefined ? { records: options.records } : {}),
sounds: options.sounds,
audio: options.audio,
...(options.courseMaker !== undefined ? { courseMaker: options.courseMaker } : {}),
policy: {
...SELECT_POLICIES[kit.family],
keys: scheme,
...(kit.family === 'beatoraja'
? { listCycles: { sort: BEATORAJA_SORTS, keysFilter: BEATORAJA_KEYS_FILTERS } }
: {}),
},
actions: resolveFamilyControlActions(kit.family, options.controls),
launchOutroMs: () => familyView?.view.launchOutroMs ?? 0,
...(options.now !== undefined ? { now: options.now } : {}),
on: options.on,
});
familyView = createSelectView(kit, session, options);
return new FamilySelectScene(session, familyView, {
...(options.keyTarget !== undefined ? { keyTarget: options.keyTarget } : {}),
...(options.controls !== undefined ? { controls: options.controls } : {}),
...(options.now !== undefined ? { now: options.now } : {}),
});
}
|