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 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 | 21x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 22x 6x 13x 13x 13x 13x 13x 13x 13x 5x 5x 5x 2x 2x 2x 2x 2x 2x 2x 3x 5x 5x 3x 3x 3x 3x 10x 10x 10x 10x 10x 7x 7x 7x 10x 10x 10x 10x 10x 10x 1x 1x 1x 10x 2x 2x 1x 10x 10x 7x 7x 10x 10x 10x 14x 14x 14x 14x 2x 2x 1x 14x 14x 14x 14x 14x 14x 14x 1x 14x 14x 14x 2x 1x 1x 1x 14x 2x 14x 14x 14x 14x 14x 14x 14x 13x 13x 13x 14x 14x 14x 14x 14x 13x 14x 8x 8x 14x 21x 21x 9x 9x 3x 2x 1x | import { isBmsonRecoveryDisabled } from '@be-music/player-engine/ruleset';
// The result route: the result screen (`createResultScene`) of a play, a course stage, a course run or a NONSTOP run,
// on the LR2 theme's result (or course-result) skin, the Be-Music Skin's, or the beatoraja theme's. The play behind it
// exits as it enters and goes once it shows, its last samples ringing out. It keeps the play's record, saves its play
// log and ranks it, and leads on: the next stage of a course, R's retry, or back to the select screen.
import type { ResolvedPlayChart } from '@be-music/player-engine';
import type { AudioService } from '@be-music/player-browser/audio';
import { resolveChartSource } from '@be-music/player-browser/collection';
import {
createResultScene,
type PlayScene,
type ResultSceneKit,
type SelectScene,
type ControlSettings,
} from '@be-music/player-browser/host';
import {
computeCourseReplayFingerprint,
type BeMusicCourseReplay,
type BeMusicReplay,
type ReplayCourseResult,
} from '@be-music/player-engine/replay';
import {
courseStageRecordPlayFromResult,
recordPlayFromResult,
type BestRecord,
type RecordPlay,
resolveReplayRecordPolicy,
} from '@be-music/player-engine/records';
import {
resolveResultJingle,
resolveResultJingles,
systemSoundSetFromBeatoraja,
type CourseView,
type LibraryChart,
type PlayResult,
type PlayRunKind,
type ReplaySlotState,
} from '@be-music/player-scene-model';
import { activeCourseInfo, recordCourseStage, resolveResultRetry, type ActiveCourse } from '../../course-flow.ts';
import { resolveResultPresentation } from '../../course-result.ts';
import { pickActiveFamilyForScene } from '../../family-dispatch.ts';
import type { LeaderboardPanel } from '../../leaderboard-ui.ts';
import { resolveResultSoundSet, resolveResultViewJingles } from '../../result-jingles.ts';
import type { CourseRunService } from '../../services/courses.ts';
import type { LibraryService } from '../../services/library.ts';
import type { ReplayAutoSave } from '../../services/replays.ts';
import {
replaySlotTargetOfReplay,
type ReplayAutoSaveRule,
type ReplaySlotStore,
} from '../../services/replay-slots.ts';
import { ResultReplaySlots } from '../../services/replay-slot-service.ts';
import { describeResultRecord } from '../../services/record-consequence.ts';
import { resolveResultGaugeGraphs } from '../../services/gauge-graphs.ts';
import type { ReplaySlotsPanel } from '../../replay-slots-panel.ts';
import type { RecordsService } from '../../services/records.ts';
import type { BeatorajaThemeService } from '../../services/themes/beatoraja.ts';
import type { BuiltInThemeService } from '../../services/themes/built-in.ts';
import type { LR2ThemeService } from '../../services/themes/lr2.ts';
import { resultFromCourseLog, resultFromData, type TestHookRecorder } from '../../test-hook.ts';
import type { PlayerScene } from '../../types.ts';
import type { FamilyKits } from '../family-kits.ts';
import type { PlayDispose, SceneRouter } from '../scene-router.ts';
import type { CourseRoute } from './course.ts';
import type { LastPlay } from './play.ts';
/** Ends a play whose result shows: it exited as the result entered, and its last samples ring out. */
export const disposeKeepingAudioTail: PlayDispose<PlayScene> = (play) => play.dispose({ preserveAudioTail: true });
export interface ResultRouteDeps {
/** The player's keys the screen reads its control buttons by (`ControlSettings`), as it opens. */
readonly controls: () => ControlSettings;
/** The scene router: the result takes the stage from the play, and leaves it before the next stage or a retry. */
readonly router: Pick<SceneRouter<PlayerScene, PlayScene, SelectScene>, 'show' | 'leave'>;
/** The library: the chart's asset source. */
readonly library: Pick<LibraryService, 'collection'>;
/**
* The replay slots a result saves into: the store, the rule each slot auto-saves by, and the card that shows them on
* the skins without a replay-slot UI of their own.
*/
readonly replaySlots: {
readonly store: ReplaySlotStore;
readonly rules: () => readonly ReplayAutoSaveRule[];
readonly panel: Pick<ReplaySlotsPanel, 'showResult'>;
};
/** Reports a replay slot save. */
readonly setStatus: (text: string) => void;
/** The best records the play, or the course stage, is kept in. */
readonly records: Pick<RecordsService, 'recordActivePlay' | 'recordActiveCourseStage'>;
/** The course run in progress: a stage's result records the stage on it. */
readonly courses: Pick<CourseRunService, 'active'>;
/** Plays a course's next stage, or shows its course result, once a stage's result is dismissed. */
readonly courseRoute: Pick<CourseRoute, 'continueCourse'>;
/** The family the result is drawn by. */
readonly familyKits: Pick<FamilyKits, 'familyDispatchState'>;
/** The LR2 theme's result and course-result skins, and its jingles. */
readonly lr2: Pick<LR2ThemeService, 'resultSkin' | 'courseResultSkin' | 'courseLR2Skin' | 'resultJingles'>;
/** The beatoraja theme's result entries, loaded as kits, and its jingles. */
readonly beatoraja: Pick<BeatorajaThemeService, 'loadBeatorajaResultKit' | 'beatorajaThemeBGM'>;
/** The Be-Music Skin the built-in family draws with. */
readonly builtIn: Pick<BuiltInThemeService, 'builtInKit'>;
/** A single play's replay auto-save, by the setting latched at the play's start. */
readonly replayAutoSave: Pick<ReplayAutoSave, 'savePlay'>;
/** Ranks a single play. */
readonly leaderboard: Pick<LeaderboardPanel, 'maybeSubmit'>;
readonly audio: AudioService;
/** `window.__beMusicTest`, when installed: every result screen shown, and the replay it shows. */
readonly testHook: Pick<TestHookRecorder, 'recordReplay' | 'recordResult'> | undefined;
/** The play last started: the chart R plays again. */
readonly lastPlay: () => LastPlay | undefined;
/** Which theme slot a result jingle came from, for the test hook. */
readonly nameResultJingle: (bytes: Uint8Array | undefined) => string | undefined;
/** Shows a status about the result, which the select screen replaces when it comes back. */
readonly setPlayStatus: (text: string) => void;
readonly showSelect: () => Promise<void>;
/** Plays a chart again (R on the result). */
readonly playChart: (
chartEntry: LibraryChart,
overrides: {
autoPlay: boolean;
replay?: BeMusicReplay;
/** The play whose note arrangement the chart is played on again. */
fixedArrangement?: Pick<BeMusicReplay, 'chart' | 'play'>;
},
) => Promise<void>;
/** Re-enables the options a play latched, once its result shows. */
readonly unlockReplayOptions: () => void;
}
/** A play's, a course's or a NONSTOP run's result screen, and where it leads. */
export class ResultRoute {
/**
* The most recently resolved chart for a beatoraja run, paired with the song's `chartPath` so
* subsequent stages can verify the cached chart still matches the song they're handling.
*
* A play on the beatoraja play screen stamps it from the chart it played (`PlayScene.resolved`, the decide screen's
* draws when it went through one) as it finishes, so the result screen's bpmgraph plots the same branches.
*
* `resolved` holds the chart together with the `#RANDOM` / `#SWITCH` draws it was resolved with; both are plain
* JSON, so retaining them is cheap.
*/
public lastBeatorajaChart: { resolved: ResolvedPlayChart; chartPath: string } | undefined;
private readonly router: ResultRouteDeps['router'];
private readonly controls: ResultRouteDeps['controls'];
private readonly library: ResultRouteDeps['library'];
private readonly records: ResultRouteDeps['records'];
private readonly courses: ResultRouteDeps['courses'];
private readonly courseRoute: ResultRouteDeps['courseRoute'];
private readonly familyKits: ResultRouteDeps['familyKits'];
private readonly lr2: ResultRouteDeps['lr2'];
private readonly beatoraja: ResultRouteDeps['beatoraja'];
private readonly builtIn: ResultRouteDeps['builtIn'];
private readonly replayAutoSave: ResultRouteDeps['replayAutoSave'];
private readonly leaderboard: ResultRouteDeps['leaderboard'];
private readonly audio: ResultRouteDeps['audio'];
private readonly testHook: ResultRouteDeps['testHook'];
private readonly lastPlay: ResultRouteDeps['lastPlay'];
private readonly nameResultJingle: ResultRouteDeps['nameResultJingle'];
private readonly setPlayStatus: ResultRouteDeps['setPlayStatus'];
private readonly showSelect: ResultRouteDeps['showSelect'];
private readonly playChart: ResultRouteDeps['playChart'];
private readonly unlockReplayOptions: ResultRouteDeps['unlockReplayOptions'];
private readonly replaySlots: ResultRouteDeps['replaySlots'];
private readonly setStatus: ResultRouteDeps['setStatus'];
public constructor(deps: ResultRouteDeps) {
this.replaySlots = deps.replaySlots;
this.setStatus = deps.setStatus;
this.router = deps.router;
this.controls = deps.controls;
this.library = deps.library;
this.records = deps.records;
this.courses = deps.courses;
this.courseRoute = deps.courseRoute;
this.familyKits = deps.familyKits;
this.lr2 = deps.lr2;
this.beatoraja = deps.beatoraja;
this.builtIn = deps.builtIn;
this.replayAutoSave = deps.replayAutoSave;
this.leaderboard = deps.leaderboard;
this.audio = deps.audio;
this.testHook = deps.testHook;
this.lastPlay = deps.lastPlay;
this.nameResultJingle = deps.nameResultJingle;
this.setPlayStatus = deps.setPlayStatus;
this.showSelect = deps.showSelect;
this.playChart = deps.playChart;
this.unlockReplayOptions = deps.unlockReplayOptions;
}
/** The EXPERT / GRADE course being played, between its stages (the course run service's). */
private get activeCourse(): ActiveCourse | undefined {
return this.courses.active;
}
/**
* Takes the screen showing off the stage and disposes it (a result screen), then runs `next` (the next stage, a
* retry) unless a newer navigation has begun meanwhile. `next` may take a while to show anything, and a live screen
* would keep taking its keys and clicks meanwhile, starting it over. The result screen asks for it, so it carries
* the run on.
*/
private async leaveThen(next: () => unknown): Promise<void> {
Eif (await this.router.leave({ continuesRun: true })) next();
}
/** Keeps a finished manual replay and updates slots when the play is eligible for a record. */
private playReplaySlots(data: PlayResult, kept: { previous: BestRecord | undefined } | undefined): ResultReplaySlots {
const replay = data.replay ?? this.lastPlay()?.overrides.replay;
const target = replay !== undefined ? replaySlotTargetOfReplay(replay) : undefined;
const save =
data.replay !== undefined &&
data.practice !== true &&
data.fromReplay !== true &&
data.replay.play.mode !== 'auto'
? {
payload: { kind: 'chart' as const, replay: data.replay },
score: {
...recordPlayFromResult(data),
noteCount: data.replay.results?.native?.noteCount ?? data.score.total,
},
title: data.chart.title,
previous: kept?.previous,
...(kept === undefined ? { historyOnly: true } : {}),
}
: undefined;
return this.openReplaySlots(target, save);
}
/** Keeps a course replay as one history entry. Playback only reads the existing selections. */
public courseReplaySlots(
courseLog: BeMusicCourseReplay,
native: ReplayCourseResult,
kept: { play: RecordPlay; previous: BestRecord | undefined } | undefined,
fromReplay = false,
): ResultReplaySlots {
const fingerprint = computeCourseReplayFingerprint(courseLog);
const target = fingerprint !== undefined ? { kind: 'course' as const, id: fingerprint } : undefined;
const save =
!fromReplay && courseLog.stages.some((stage) => stage.played && stage.replay.play.mode !== 'auto')
? {
payload: { kind: 'course' as const, replay: courseLog },
score: { ...(kept?.play ?? native), noteCount: native.noteCount },
title: courseLog.course.name,
previous: kept?.previous,
...(kept === undefined ? { historyOnly: true } : {}),
}
: undefined;
return this.openReplaySlots(target, save);
}
/** A result's replay slots, saved into at once by each slot's auto-save rule. */
private openReplaySlots(
target: ResultReplaySlots['target'],
save: ConstructorParameters<typeof ResultReplaySlots>[0]['save'],
): ResultReplaySlots {
const slots = new ResultReplaySlots({ store: this.replaySlots.store, target, save, report: this.setStatus });
void slots.autoSave(this.replaySlots.rules());
return slots;
}
/**
* The result of a play on the beatoraja play screen, on the theme's result skin: a course stage is recorded on the run
* (its result shown unless the theme has no result skin, when the course goes straight on), a single play keeps its
* record, saves its replay and goes to the Leaderboard. Without a result skin a single play goes back to select.
*/
public async showBeatorajaPlayResult(data: PlayResult, courseStage: boolean): Promise<void> {
this.testHook?.recordReplay(data.replay);
const active = this.activeCourse;
if (courseStage && active !== undefined) {
recordCourseStage(active, data);
// A stage given up keeps no stage record here, as when it shows no result.
Eif (
!data.practice &&
data.replay?.play.aborted !== true &&
(data.replay === undefined || !isBmsonRecoveryDisabled(data.replay.chart, data.replay.play.bmsonTotalMode))
)
this.records.recordActiveCourseStage(courseStageRecordPlayFromResult(data), data.replay);
const mounted = await this.showBeatorajaResult(data, {
run: 'stage',
course: { info: activeCourseInfo(active) },
});
if (!mounted) this.courseRoute.continueCourse();
this.unlockReplayOptions();
return;
}
// LR2 saves no score from two-player BATTLE: its replay is kept, its record and ranking are not.
const recorded = !data.practice && data.secondPlayer === undefined;
const kept =
recorded &&
(data.replay === undefined || !isBmsonRecoveryDisabled(data.replay.chart, data.replay.play.bmsonTotalMode))
? this.records.recordActivePlay(recordPlayFromResult(data), data.replay)
: undefined;
const mounted = await this.showBeatorajaResult(data, {
run: 'single',
replaySlots: this.playReplaySlots(data, kept),
});
if (!mounted) await this.showSelect();
// Auto-save fires even when the theme ships no result skin, so going back to select costs no replay file.
if (!data.practice) this.replayAutoSave.savePlay(data.replay);
if (recorded) this.leaderboard.maybeSubmit(data.replay, data.chart, data.score.exScore);
this.unlockReplayOptions();
}
/**
* Mount the beatoraja result screen with `createResultScene`: `data`, a play's result (a single play, a replay or a
* course stage on the beatoraja play screen), a NONSTOP run's (`run: 'nonstop'`, R stitching it again through
* `options.nonstopRetry`) or, with `options.course.result`, a course run's, on the theme's result skin (its
* course-result skin for a course run). `options.playChart` is the chart its graphs plot when it is not the last
* beatoraja play's (`lastBeatorajaChart`): a NONSTOP run's stitched chart. Returns `true` when the screen actually
* mounted, or a newer navigation took the stage first — `false` falls through to the no-result fast-path (no result
* skin in the bundle, or skin load failed). The play behind it goes once the screen shows, its last samples ringing
* out.
*/
public async showBeatorajaResult(
data: PlayResult,
options: {
run: PlayRunKind;
course?: { info: CourseView; result?: { log: BeMusicCourseReplay; native: ReplayCourseResult } };
nonstopRetry?: () => void;
playChart?: ResolvedPlayChart['chart'];
/** The run's replay slots, which the skin shows and its keys and buttons save into; a course stage has none. */
replaySlots?: ResultReplaySlots;
},
): Promise<boolean> {
const chartEntry = data.chart;
const course = options.course;
// The course result (`course.result`) shows on the theme's COURSE_RESULT skin, falling back to its result skin.
const courseResult = course?.result !== undefined;
const kit = await this.beatoraja.loadBeatorajaResultKit(chartEntry, courseResult);
if (kit === undefined) return false;
const run = options.run;
const presentation = resolveResultPresentation(run);
// The skin shows the course of the result: the stage's course, or the course run.
const result: PlayResult =
course !== undefined && data.course === undefined ? { ...data, course: course.info } : data;
// The chart as the play played it, for any `bpmgraph[]` and note-kind graph of the result skin. The play is disposed
// as the result shows, so the chart is kept in `lastBeatorajaChart`; it is only handed on when it is this song's, so a
// graph never plots another chart. A course run's result plots none.
const playChart =
options.playChart ??
(!courseResult && this.lastBeatorajaChart?.chartPath === chartEntry.chartPath
? this.lastBeatorajaChart.resolved.chart
: undefined);
// R on the result plays the same chart again — only offered when the recorded play start is this chart's, and
// never in a course (beatoraja disables quick retry there); a NONSTOP run is stitched and played again.
const lastPlay = this.lastPlay();
const retryTarget = resolveResultRetry({
quickRetry: presentation.quickRetry,
...(options.nonstopRetry !== undefined ? { nonstopRetry: options.nonstopRetry } : {}),
chartId: chartEntry.id,
...(lastPlay !== undefined ? { lastPlay: { chartId: lastPlay.chart.id, play: lastPlay } } : {}),
});
// beatoraja plays every result from its theme's one set: a course run's `course_clear` / `course_fail`, falling back
// to the clear / fail ones, else the generic `result` one.
const sounds = systemSoundSetFromBeatoraja({ bgm: this.beatoraja.beatorajaThemeBGM });
const jingleBytes = resolveResultJingle(
resolveResultJingles([sounds], presentation.courseJingles),
result.cleared,
)?.bytes;
const onContinue = (): void => {
// The next stage does not show at once, and a live result screen would keep taking its keys meanwhile: it goes
// first.
void this.leaveThen(() => {
Iif (!courseResult && this.courseRoute.continueCourse()) return;
void this.showSelect();
});
};
const onRetry =
retryTarget === undefined
? undefined
: (asked?: { readonly sameArrangement?: boolean }): void => {
// Straight back into the chart, the result screen gone first.
void this.leaveThen(() => {
if (retryTarget.kind === 'nonstop') retryTarget.retry();
else
void this.playChart(
retryTarget.play.chart,
withSameArrangement(retryTarget.play.overrides, asked?.sameArrangement === true ? result : undefined),
);
});
};
const resultScene = createResultScene(kit, {
controls: this.controls(),
result,
run,
source: resolveChartSource(this.library.collection, chartEntry),
...(playChart !== undefined ? { playChart } : {}),
sounds,
audio: this.audio,
...resultSceneReplaySlots(options.replaySlots),
gaugeGraphs: () => resolveResultGaugeGraphs(result),
on: {
continue: onContinue,
...(onRetry !== undefined ? { retry: onRetry } : {}),
...resultSaveReplay(options.replaySlots),
},
});
// The play exits as the result enters; its audio tail rings on until it is disposed (`preserveAudioTail`). The play
// or the course asked for its result, so it carries the run on.
const shown = await this.router.show(resultScene, {
role: 'result',
playDispose: disposeKeepingAudioTail,
continuesRun: true,
});
Iif (!shown) return true;
this.setPlayStatus(
`Result (beatoraja): ${courseResult ? course!.info.title : chartEntry.title} · ex=${result.score.exScore} maxCombo=${result.maxCombo}`,
);
const jingle = this.nameResultJingle(jingleBytes);
this.testHook?.recordResult(
course?.result !== undefined
? resultFromCourseLog(course.result.log, course.result.native, {
family: 'beatoraja',
jingle,
...(result.fromReplay === true ? { fromReplay: true } : {}),
})
: resultFromData(result, run, 'beatoraja', jingle),
);
return true;
}
/**
* Mounts the result scene for a play, or — with `mode.course` — for a whole course (the course result, shown on the
* LR2 theme's course-result skin when it has one).
*/
public async showResult(
data: PlayResult,
mode: {
course?: CourseView;
/** The course result's replay and native result (what the test hook reports of it). */
courseLog?: { log: BeMusicCourseReplay; native: ReplayCourseResult };
nonstop?: { info: CourseView; retry: () => void };
/** A course run's replay slots ({@link courseReplaySlots}); a single play's are made here. */
replaySlots?: ResultReplaySlots;
} = {},
): Promise<void> {
// A stage of a running course: its replay carries the course on, and dismissing its result plays the next stage.
const courseStage = mode.course === undefined && mode.nonstop === undefined && this.activeCourse !== undefined;
const run =
mode.course !== undefined ? 'course' : mode.nonstop !== undefined ? 'nonstop' : courseStage ? 'stage' : 'single';
const presentation = resolveResultPresentation(run);
if (courseStage) {
recordCourseStage(this.activeCourse!, data);
// A stage given up keeps no stage record here, as when it shows no result.
if (
!data.practice &&
data.replay?.play.aborted !== true &&
(data.replay === undefined || !isBmsonRecoveryDisabled(data.replay.chart, data.replay.play.bmsonTotalMode))
)
this.records.recordActiveCourseStage(courseStageRecordPlayFromResult(data), data.replay);
}
// Family dispatch for result. Only the LR2 / default split is modelled here — a play on the beatoraja play screen
// shows its result on the beatoraja skin (`showBeatorajaPlayResult`), a NONSTOP run on a beatoraja theme too
// (`showNonstopCourseResult`), and one whose theme has no result skin falls back to the built-in result with the
// theme's jingles. Pick the LR2 result skin only when the family pick says so; defaulting strips the slot even if
// the loaded theme has a result skin.
const resultFamily = pickActiveFamilyForScene(this.familyKits.familyDispatchState(), 'result');
// A course's results show the course on the skin (LR2 ops 280-293, texts 150-170): a stage's result at its stage,
// the course result on the course-result skin, each parsed again with the course ops.
const courseInfo =
mode.course ?? mode.nonstop?.info ?? (courseStage ? activeCourseInfo(this.activeCourse!) : undefined);
const mountedResultSkin = presentation.courseResultSkin
? (this.lr2.courseResultSkin ?? this.lr2.resultSkin)
: this.lr2.resultSkin;
const lr2ResultSkin =
resultFamily !== 'lr2'
? undefined
: courseInfo === undefined
? mountedResultSkin
: this.lr2.courseLR2Skin(mountedResultSkin, courseInfo, {
kind:
presentation.courseResultSkin && this.lr2.courseResultSkin !== undefined ? 'courseResult' : 'result',
});
// R on the result plays the same chart again — only offered when the recorded play start is this chart's, and
// never in a course (LR2 and beatoraja disable quick retry there), except that a NONSTOP run is stitched and played
// again, as LR2 allows.
const lastPlay = this.lastPlay();
const retryTarget = resolveResultRetry({
quickRetry: presentation.quickRetry,
...(mode.nonstop !== undefined ? { nonstopRetry: mode.nonstop.retry } : {}),
chartId: data.chart.id,
...(lastPlay !== undefined ? { lastPlay: { chartId: lastPlay.chart.id, play: lastPlay } } : {}),
});
const retry =
retryTarget?.kind === 'nonstop'
? retryTarget.retry
: retryTarget?.kind === 'replay'
? (asked?: { readonly sameArrangement?: boolean }) =>
void this.playChart(
retryTarget.play.chart,
withSameArrangement(retryTarget.play.overrides, asked?.sameArrangement === true ? data : undefined),
)
: undefined;
// The active theme's jingles: a beatoraja theme's when its result falls back to this view (a NONSTOP course on a
// theme without a result skin).
const themeJingles = {
lr2: this.lr2.resultJingles(),
beatoraja: this.beatoraja.beatorajaThemeBGM,
};
const jingles = resolveResultViewJingles(resultFamily, presentation.courseJingles, themeJingles);
const onContinue = (): void => {
if (courseStage && this.activeCourse !== undefined) {
// The next stage does not show at once, and a live result screen would keep taking its clicks and keys (Enter /
// Space / Escape) meanwhile, starting it over: it goes first.
void this.leaveThen(() => this.courseRoute.continueCourse());
return;
}
void this.showSelect();
};
const onRetry =
retry === undefined
? undefined
: (asked?: { readonly sameArrangement?: boolean }): void => {
// Straight back into the chart, skipping select and decide: the result screen (and its jingle) goes first.
void this.leaveThen(() => retry(asked));
};
// LR2 saves no score from two-player BATTLE: its replay is kept, its record and ranking are not.
const recorded = !data.practice && data.secondPlayer === undefined;
const kept =
recorded &&
(data.replay === undefined || !isBmsonRecoveryDisabled(data.replay.chart, data.replay.play.bmsonTotalMode))
? this.records.recordActivePlay(recordPlayFromResult(data), data.replay)
: undefined;
// A single play's slots, or the course run's; a course stage has none (beatoraja saves the course as one run).
const replaySlots = run === 'single' ? this.playReplaySlots(data, kept) : mode.replaySlots;
const kit: ResultSceneKit =
lr2ResultSkin !== undefined ? { family: 'lr2', skin: lr2ResultSkin } : this.builtIn.builtInKit;
const resultScene = createResultScene(kit, {
controls: this.controls(),
// The LR2 skin shows the course of the result (`result.course`): the stage's course, or the course run.
result: lr2ResultSkin !== undefined && courseInfo !== undefined ? { ...data, course: courseInfo } : data,
run,
source: resolveChartSource(this.library.collection, data.chart),
sounds: resolveResultSoundSet(resultFamily, themeJingles),
audio: this.audio,
...resultSceneReplaySlots(replaySlots),
gaugeGraphs: () => resolveResultGaugeGraphs(data),
on: {
continue: onContinue,
...(onRetry !== undefined ? { retry: onRetry } : {}),
...resultSaveReplay(replaySlots),
},
});
// The play exits as the result enters; its audio tail rings on until it is disposed (`preserveAudioTail`). The play
// or the course asked for its result, so it carries the run on.
const shown = await this.router.show(resultScene, {
role: 'result',
playDispose: disposeKeepingAudioTail,
continuesRun: true,
});
// A newer navigation that took the stage first keeps its own status; the play is still kept, saved and ranked.
if (shown) {
// What the play did to its record, from the policy the record went through; the Leaderboard's line follows it.
const record = run === 'single' ? describeResultRecord(data, kept !== undefined) : undefined;
this.setPlayStatus(`Result: ${data.chart.title}${record !== undefined ? ` — ${record}` : ''}`);
// The built-in, Native and LR2 skins have no replay-slot UI: the card stands in for one.
if (replaySlots !== undefined) this.replaySlots.panel.showResult(replaySlots);
}
Eif (this.testHook !== undefined) {
if (mode.course === undefined) this.testHook.recordReplay(data.replay);
const family = lr2ResultSkin !== undefined ? 'lr2' : 'built-in';
const jingle = this.nameResultJingle(data.cleared ? jingles.clearBGM : jingles.failBGM);
if (shown) {
this.testHook.recordResult(
mode.courseLog !== undefined
? resultFromCourseLog(mode.courseLog.log, mode.courseLog.native, {
family,
playSeconds: data.playSeconds,
jingle,
...(data.fromReplay === true ? { fromReplay: true } : {}),
})
: resultFromData(data, run, family, jingle),
);
}
}
// A course's stages are saved and ranked as the course, not one by one (a NONSTOP run's course log already was).
if (!data.practice && presentation.quickRetry && mode.nonstop === undefined) {
this.replayAutoSave.savePlay(data.replay);
Eif (recorded) this.leaderboard.maybeSubmit(data.replay, data.chart, data.score.exScore);
}
this.unlockReplayOptions();
}
}
/** The result scene's replay slot states, when the run has slots. */
function resultSceneReplaySlots(slots: ResultReplaySlots | undefined): { replaySlots?: () => ReplaySlotState[] } {
return slots !== undefined ? { replaySlots: () => slots.states() } : {};
}
/** The result scene's save into a replay slot (keys 1-4, a beatoraja skin's buttons), when the run has slots. */
function resultSaveReplay(slots: ResultReplaySlots | undefined): { saveReplay?: (slot: number) => void } {
return slots !== undefined ? { saveReplay: (slot) => void slots.save(slot) } : {};
}
/**
* A retry's overrides on the note arrangement of the play just finished (`played`), as beatoraja's REPLAY_SAME plays
* it: only a live play's (not a replay's or an AUTO play's), and not an assisted one's, which beatoraja plays again on
* a new arrangement (`MusicResult`: "アシストモード時は同じ譜面でリプレイできません"). Otherwise the overrides as they are.
*/
export function withSameArrangement<T extends { autoPlay: boolean; replay?: BeMusicReplay }>(
overrides: T,
played: Pick<PlayResult, 'replay' | 'fromReplay' | 'autoPlay'> | undefined,
): T & { fixedArrangement?: Pick<BeMusicReplay, 'chart' | 'play'> } {
const replay = played?.replay;
if (replay === undefined || played?.fromReplay === true || played?.autoPlay === true) return overrides;
if (overrides.autoPlay || overrides.replay !== undefined) return overrides;
if (!resolveReplayRecordPolicy(replay).updatesScore) return overrides;
return { ...overrides, fixedArrangement: { chart: replay.chart, play: replay.play } };
}
|