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 | 29x 19x 7x 7x 5x 19x 19x 7x 7x 3x 7x 7x 2x 5x 5x 2x 19x 19x 19x 5x 19x 19x | /**
* The host API for the decide screen: `createDecideScene(kit, options)` pairs the decide session with the view of the
* kit's family and returns the scene to show with `PixiSceneHost.setScene`.
*/
import { DOMDecideView } from '../view/built-in/dom-view.ts';
import type { ResolvedPlayChart } from '@be-music/player-engine';
import type { CourseView, LibraryChart, PlayOptions, SystemSoundSet } from '@be-music/player-scene-model';
import type { BrowserAssetSource } from '../collection/types.ts';
import type { AudioService } from '../runtime/audio-service.ts';
import { DecideSession, type DecideSessionEvents } from '../session/decide/decide-session.ts';
import { resolveFamilyControlActions } from '../session/controls/control-actions.ts';
import { SessionScene, type SessionSceneOptions } from '../session/session-scene.ts';
import { logger } from '../logger.ts';
import { BeatorajaDecideView, resolveBeatorajaDecideTiming } from '../view/beatoraja/decide-view.ts';
import { BuiltInDecideView, resolveBuiltInDecideTiming } from '../view/built-in/decide-view.ts';
import { LR2DecideView, resolveLR2DecideTiming } from '../view/lr2/decide-view.ts';
import type { DecideFrame, DecideIntent, DecideView, SceneViewTiming } from '../view/types.ts';
import type { DecideKit } from './family-kit.ts';
const log = logger('decide');
/**
* The kits the decide scene takes: a Be-Music Skin, an LR2 decide skin, or a beatoraja theme's decide entry
* (`{ family: 'beatoraja', kit }`, loaded with `loadBeatorajaSceneKit`).
*/
export type DecideSceneKit = DecideKit;
export interface DecideSceneOptions extends SessionSceneOptions {
/** The chart about to be played. */
readonly chart: LibraryChart;
/** The course and the stage about to be played, for a course stage. */
readonly course?: CourseView;
/** The options the play will run with, as the skin shows them. Defaults to `DEFAULT_PLAY_OPTIONS`. */
readonly playOptions?: PlayOptions;
/** Where the chart's files are, for the images a skin shows. */
readonly source?: BrowserAssetSource;
/** The theme's sounds: the screen plays `decideBGM`, its jingle, and stops it as it leaves. */
readonly sounds: SystemSoundSet;
/**
* The host's audio service: the jingle plays through it, and so do a beatoraja skin's Lua sounds (`skinSounds`,
* resolved against the theme's files set with `setTheme`), which stop as the screen leaves.
*/
readonly audio: AudioService;
/**
* How far the play prepared behind the screen has loaded, 0..1, read every frame. Without it the screen shows how
* much of its auto advance has gone by.
*/
readonly progress?: () => number | undefined;
/** The random source the chart's `#RANDOM` / `#SWITCH` branches are drawn with. Defaults to `Math.random`. */
readonly random?: () => number;
/**
* The chart with its `#RANDOM` / `#SWITCH` branches drawn already (`resolvePlayChart`), when the host drew them before
* making the screen, so it could start loading the play as the chart was picked. The screen shows these draws, and
* `resolved` is this chart.
*/
readonly resolved?: ResolvedPlayChart;
/** Where the screen leads: the play (`continue`) or back to select (`cancel`); each fires once per entry. */
readonly on: DecideSessionEvents;
}
/** The decide screen as a scene. */
export interface DecideScene extends SessionScene<DecideFrame, DecideIntent> {
/**
* The chart as the play will play it: its `#RANDOM` / `#SWITCH` branches drawn once, when the scene was made, with the
* draws. The screen shows these branches; hand it to the play (`preResolved`) so the play plays them too.
*/
readonly resolved: ResolvedPlayChart;
/**
* Takes the player's new settings for the kit's skin; the next frame draws with them. The scene keeps its family and
* its skin: a kit of another family or skin is ignored.
*/
updateKit(kit: DecideSceneKit): void;
}
/** A family's decide view, and how it takes a new kit. */
interface FamilyDecideView {
readonly view: DecideView;
updateKit(kit: DecideSceneKit): void;
}
/** The skin timing of `kit`'s decide view, which the session times the screen from. */
function decideTimingOf(kit: DecideSceneKit): SceneViewTiming {
switch (kit.family) {
case 'lr2':
return resolveLR2DecideTiming(kit.skin);
case 'beatoraja':
return resolveBeatorajaDecideTiming(kit.kit.skin);
case 'built-in':
return resolveBuiltInDecideTiming(kit);
}
}
/**
* The decide view of `kit`'s family, reading the chart's files from `options.source`. A beatoraja skin's Lua sounds
* play through the audio service as the session's, so they stop as the screen leaves.
*/
function createDecideView(
kit: DecideSceneKit,
session: DecideSession,
options: Pick<DecideSceneOptions, 'chart' | 'source' | 'audio'>,
): FamilyDecideView {
const source = options.source !== undefined ? { source: options.source } : {};
switch (kit.family) {
case 'lr2': {
const view = new LR2DecideView(kit, source);
return {
view,
updateKit: (next) => (next.family === 'lr2' ? view.updateKit(next) : ignoreKit(next, 'lr2')),
};
}
case 'beatoraja': {
const view = new BeatorajaDecideView(kit, {
chart: options.chart,
...source,
skinSounds: options.audio.skinSounds.owned(session),
});
return {
view,
updateKit: (next) => (next.family === 'beatoraja' ? view.updateKit(next) : ignoreKit(next, 'beatoraja')),
};
}
case 'built-in': {
const view = kit.skin.dom?.decide ? new DOMDecideView(kit, source) : new BuiltInDecideView(kit, source);
return {
view,
updateKit: (next) => (next.family === 'built-in' ? view.updateKit(next) : ignoreKit(next, 'built-in')),
};
}
}
}
function ignoreKit(kit: DecideSceneKit, family: DecideSceneKit['family']): void {
log.warn(`a ${family} decide scene keeps its family; ignoring a ${kit.family} kit`);
}
class FamilyDecideScene extends SessionScene<DecideFrame, DecideIntent> implements DecideScene {
public readonly resolved: ResolvedPlayChart;
private readonly familyView: FamilyDecideView;
public constructor(session: DecideSession, familyView: FamilyDecideView, options: SessionSceneOptions) {
super(session, familyView.view, options);
this.resolved = session.resolved;
this.familyView = familyView;
}
public updateKit(kit: DecideSceneKit): void {
this.familyView.updateKit(kit);
}
}
/**
* The decide screen for `kit`: the session times it, plays the decide jingle and says where it leads; the kit's family
* view draws it. Show it with `PixiSceneHost.setScene`, and dispose it once it is gone.
*/
export function createDecideScene(kit: DecideSceneKit, options: DecideSceneOptions): DecideScene {
const session = new DecideSession({
chart: options.chart,
actions: resolveFamilyControlActions(kit.family, options.controls),
...(options.course !== undefined ? { course: options.course } : {}),
...(options.playOptions !== undefined ? { playOptions: options.playOptions } : {}),
sounds: options.sounds,
audio: options.audio,
timing: decideTimingOf(kit),
...(options.progress !== undefined ? { progress: options.progress } : {}),
...(options.random !== undefined ? { random: options.random } : {}),
...(options.resolved !== undefined ? { resolved: options.resolved } : {}),
on: options.on,
});
return new FamilyDecideScene(session, createDecideView(kit, session, options), {
...(options.keyTarget !== undefined ? { keyTarget: options.keyTarget } : {}),
...(options.controls !== undefined ? { controls: options.controls } : {}),
...(options.now !== undefined ? { now: options.now } : {}),
});
}
|