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 | 29x 29x 29x 29x 29x 69x 69x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 3x 2x 2x 2x 2x 2x 2x 2x 2x 16x 16x 16x 16x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x 53x 53x 53x 53x 53x 53x 53x 53x 53x 25x 53x 53x 53x 53x 53x 53x 53x 53x 53x 53x 3x 53x 19x 19x 19x 19x 19x 19x 19x 19x 19x 16x 16x 16x 16x 16x 16x 16x 16x 16x 53x 53x 9x 9x 9x 44x 12x 4x 4x 4x 53x 53x 5x 5x 53x 53x 53x 53x 53x 48x 5x 53x 53x 53x 53x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 28x 28x 28x 28x 28x 28x 28x 3x 3x 2x 3x 3x 2x 2x 1x 1x 1x 1x 5x 28x 5x 5x 5x 5x 28x 5x 5x 5x 4x 4x 2x 2x 5x 5x 5x 5x 5x 7x 5x 4x 4x 4x 4x 4x 3x 3x 7x 7x 7x 7x 17x 1630x 138x 494x 1595x 110x 212x 109x 112x 224x 224x 56x 23x 23x 23x 23x 62x 54x 19x 7x 10x | /**
* The beatoraja family's select view: a beatoraja select skin (`header.type` 5, `select.json` / `selectmain.lua`) drawn
* by `BeatorajaPlaySkinView`, its canvas fitted into the window, with the bar list (`select/rows.ts`) drawn into the
* skin at its `songlist` anchor and the README dialog over it. It draws the select session's frames: what the skin reads
* of the screen comes from the scene mapping of `@be-music/skin-beatoraja/scene` (`select/skin-state.ts`: the bar ops,
* numbers, texts and image-set values over the focused bar, the list options and the records), the focused chart's
* images and graphs from `select/chart-images.ts`, the search prompt from `select/search.ts`, and beatoraja's scene
* timers from the frames: the scene (0) from the entry, the bar change (11) whenever the bar under the cursor changes.
* The list glides to the cursor, the short way round a wrap.
*
* A click on a bar moves the cursor onto it, or takes it when it is the focused one. The skin's buttons come back as
* intents: PLAY / AUTO / PRACTICE, READ TEXT, the song and chart favourites, the MODE and SORT buttons, which step
* the key-mode filter and the sort of the browse position (Shift steps back), and the option buttons (RANDOM 1P / 2P,
* LNMODE, DP option, gauge auto shift, …), which step the play options as beatoraja's select screen does
* (`resolveBeatorajaOptionButton`; RANDOM through the lane options of the focused chart's play mode); the JUDGE TIMING
* button steps the skin's timing offset and hands the options to the host.
*/
import { LR2_OP, LR2_TIMER } from '@be-music/skin-lr2/ids';
import {
BEATORAJA_BUTTON,
parseBeatorajaSongList,
TIMER_SCENE_START,
TIMER_SONGBAR_CHANGE,
type BeatorajaSkinConfig,
} from '@be-music/skin-beatoraja';
import {
BEATORAJA_KEYS_FILTERS,
BEATORAJA_SORTS,
beatorajaClearLampOp,
beatorajaKeysFilterIndex,
beatorajaReplayButtonSlot,
beatorajaSortIndex,
resolveBeatorajaOptionButton,
resolveBeatorajaSelectSliderValue,
} from '@be-music/skin-beatoraja/scene';
import {
resolveLibraryChartPlayVariant,
type BrowseListOptions,
type LibraryChart,
type LibraryEntry,
type PlayOptions,
} from '@be-music/player-scene-model';
import { Container } from 'pixi.js';
import { resolveChartSource } from '../../collection/collection.ts';
import type { BrowserChartCollection } from '../../collection/types.ts';
import type { BeatorajaKit } from '../../host/family-kit.ts';
import { logger } from '../../logger.ts';
import { BeatorajaPlaySkinView } from './skin-view.ts';
import type { PixiSceneHost } from '../../host/scene-host.ts';
import type { BeatorajaSkinAudio } from '../../skin/beatoraja/audio.ts';
import { loadBeatorajaChartImages, type BeatorajaChartImages } from '../../skin/beatoraja/chart-images.ts';
import { SelectReadmeDialog } from '../shared/readme-dialog.ts';
import type { IntentSink, SelectFrame, SelectIntent, SelectView } from '../types.ts';
import { beatorajaSceneNowMs, BeatorajaSkinStage } from './scene-frame.ts';
import { BeatorajaSelectChartImages, type BeatorajaSelectChartImagesContext } from './select/chart-images.ts';
import { BeatorajaSelectRows, type BeatorajaSelectRowsContext } from './select/rows.ts';
import { BeatorajaSelectSearch, type BeatorajaSelectSearchContext } from './select/search.ts';
import { BeatorajaSelectSkinState, type BeatorajaSelectSkinStateContext } from './select/skin-state.ts';
const log = logger('beatoraja-select');
/**
* Fraction of the gap between the list's glide and the cursor closed each 60 Hz frame: `0.25` lands inside ~150 ms,
* responsive without looking jumpy. The glide snaps to the cursor once the gap drops below
* {@link SCROLL_SNAP_THRESHOLD}, so it does not wander towards it forever.
*/
const SCROLL_TWEEN_RATE = 0.25;
const SCROLL_SNAP_THRESHOLD = 0.005;
/** One frame at 60 Hz, in ms: the glide's step. */
const FRAME_MS = 1000 / 60;
/** The JUDGE TIMING button's range (ms), as beatoraja's judge-offset slider. */
const JUDGE_TIMING_LIMIT_MS = 500;
/** What the view's parts read and drive on it. */
type BeatorajaSelectViewContext = BeatorajaSelectRowsContext &
BeatorajaSelectSearchContext &
BeatorajaSelectChartImagesContext &
BeatorajaSelectSkinStateContext;
export interface BeatorajaSelectViewOptions {
/** Where the skin's Lua sounds play (`main_state.audio_*`); they are silent without it. */
readonly skinSounds?: BeatorajaSkinAudio;
/**
* The skin's JUDGE TIMING button (act 74) changed its options (`offset`): the host keeps them. The view draws with
* them at once.
*/
readonly onSkinConfigChange?: (config: BeatorajaSkinConfig) => void;
/**
* Decodes a chart's own images for the skin's synthetic slots; `loadBeatorajaChartImages` over the library's files
* by default.
*/
readonly loadChartImages?: (
chartEntry: LibraryChart,
library: BrowserChartCollection,
) => Promise<BeatorajaChartImages>;
}
/** The bar's own object (its chart, folder or course), which stays the same across the lists that show it. */
function barTarget(entry: LibraryEntry | undefined): object | undefined {
Iif (entry === undefined) return undefined;
return entry.kind === 'chart' ? entry.chart : entry.kind === 'folder' ? entry.folder : entry.course;
}
/** The beatoraja select view. See the module comment. */
export class BeatorajaSelectView implements SelectView {
public readonly family = 'beatoraja' as const;
/** A beatoraja skin has no launch outro: a started chart is handed on at once. */
public readonly launchOutroMs = 0;
public readonly root: Container = new Container();
private kit: BeatorajaKit;
private readonly options: BeatorajaSelectViewOptions;
/** The bar list, inside the skin's container at its `songlist` anchor. */
private readonly listLayer: Container = new Container();
private readonly readme: SelectReadmeDialog = new SelectReadmeDialog();
/** This view as its parts read and drive it (see {@link createContext}). */
private readonly context: BeatorajaSelectViewContext = BeatorajaSelectView.createContext(this);
private readonly rows: BeatorajaSelectRows = new BeatorajaSelectRows(this.context);
private readonly search: BeatorajaSelectSearch = new BeatorajaSelectSearch(this.context);
private readonly chartImages: BeatorajaSelectChartImages = new BeatorajaSelectChartImages(this.context);
private readonly skinState: BeatorajaSelectSkinState = new BeatorajaSelectSkinState(this.context);
private stage: BeatorajaSkinStage;
private host: PixiSceneHost | undefined;
private emit: IntentSink<SelectIntent> | undefined;
private disposed = false;
/** The frame being drawn, or the last one: what the parts, the clicks and the buttons read. */
private frame: SelectFrame | undefined;
/** The option panel shown, for its timers and ops. */
private shownPanel: number | undefined;
/** When the scene was last entered, on the host clock: the scene timers count from it. */
private enteredAtMs = Number.NaN;
private lastDrawMs: number | undefined;
/**
* The list's glide: a fractional cursor chasing the frame's cursor, which the rows are laid out around, so a jump
* glides instead of teleporting. Shifted by the list's length on a wrap, so the glide takes the short way round.
*/
private scrollPosition = 0;
/** The list the glide follows; a new one (a folder opened, a filter changed) snaps the glide to the cursor. */
private shownEntries: readonly LibraryEntry[] | undefined;
/** The focused bar's own object, to start the bar-change timer when it changes. */
private focusedTarget: object | undefined;
/** The scene timers started, on the screen's own clock (ms since the entry); a timer not in it has not started. */
private readonly timerStartedAt = new Map<number, number>();
/**
* The key filter and sort the MODE and SORT buttons step from: the frame's, or what the view last asked for until the
* next frame shows the session's, so a second press before that frame steps on rather than asking for the same again.
*/
private listAsked: Pick<BrowseListOptions, 'keysFilter' | 'sort'> | undefined;
public constructor(kit: BeatorajaKit, options: BeatorajaSelectViewOptions = {}) {
this.kit = kit;
this.options = options;
// `passive`, not `static`: Pixi hit-tests the children of an interactive container as interactive too, so the row
// label above a row's hit sprite would take a click on the title text and hand it to this (listener-less) layer.
// Passive leaves each child to its own mode: only the row hit sprites are hit.
this.listLayer.eventMode = 'passive';
this.stage = this.buildStage();
this.root.addChild(this.stage.root);
}
/**
* Takes another kit: the player's new options for the skin, or another select skin. The skin view, the bar list and
* the search prompt are built again for it; the place in the list, the chart images and the LNMODE choice stay.
*/
public updateKit(kit: BeatorajaKit): void {
// The entry as loaded before (the host hands it again on every return to the screen): nothing to build.
if (this.disposed || kit.kit === this.kit.kit) return;
this.kit = kit;
this.search.destroySearchPrompt();
this.skinState.cachedBaseOps = undefined;
this.rows.forgetSkin();
// The old skin view's container lets go of its children as it is destroyed: the list layer moves into the new one.
this.stage.dispose();
this.stage = this.buildStage();
this.root.addChild(this.stage.root);
if (this.host !== undefined) this.stage.fitTo(this.host);
}
public attach(host: PixiSceneHost, emit: IntentSink<SelectIntent>): void {
Iif (this.disposed) return;
this.host = host;
this.emit = emit;
this.readme.attach(
() => host.domRoot,
() => this.emit?.({ type: 'readtext' }),
(index) => this.emit?.({ type: 'readtext-tab', index }),
);
}
public detach(): void {
this.readme.detach();
this.host = undefined;
this.emit = undefined;
}
public dispose(): void {
Iif (this.disposed) return;
this.detach();
this.disposed = true;
this.search.destroySearchPrompt();
this.rows.destroyRowVisuals();
this.listLayer.parent?.removeChild(this.listLayer);
Eif (!this.listLayer.destroyed) this.listLayer.destroy({ children: true });
this.stage.dispose();
this.chartImages.dispose();
this.root.parent?.removeChild(this.root);
Eif (!this.root.destroyed) this.root.destroy({ children: false });
}
public getStageInfo(): { container: Container; width: number; height: number } {
return this.stage.getStageInfo();
}
/** A beatoraja skin's search word is drawn by the skin: the host's text field is not laid over it. */
public searchFieldRect(): undefined {
return undefined;
}
public draw(frame: SelectFrame): void {
const host = this.host;
Iif (host === undefined || this.disposed) return;
this.stage.fitTo(host);
if (frame.clock.enteredAtMs !== this.enteredAtMs) this.startScene(frame);
this.followList(frame);
this.followPanel(frame);
this.frame = frame;
this.listAsked = undefined;
for (const event of frame.events) {
Iif (event.kind === 'readtext-scroll') this.readme.scrollBy(event.delta);
}
this.readme.show(frame.readText);
const view = this.stage.view;
this.skinState.frameInput = undefined;
this.skinState.frameInput = this.skinState.selectInput();
const focused = frame.entries[frame.cursor];
this.chartImages.refreshChartImagesForFocus(focused?.kind === 'chart' ? focused.chart : undefined);
this.rows.refreshRowVisuals();
this.search.refreshSearchPrompt();
const skinSounds = this.options.skinSounds;
view.update({
activeOps: this.withPanelOps(this.skinState.computeActiveOps()),
// A timer that has not started reads `undefined`, which hides what is gated on it (the fade-out's black cover).
getTimerStart: (timerId) => this.timerStartedAt.get(timerId),
nowMs: beatorajaSceneNowMs(frame.clock),
audioPlay: skinSounds === undefined ? undefined : (path, volume) => skinSounds.play(path, volume),
audioLoop: skinSounds === undefined ? undefined : (path, volume) => skinSounds.loop(path, volume),
audioStop: skinSounds === undefined ? undefined : (path) => skinSounds.stop(path),
});
this.skinState.frameInput = undefined;
}
// ---------------------------------------------------------------------------------------------------------------------
// The skin
// ---------------------------------------------------------------------------------------------------------------------
/** The skin view of the kit on its stage, with the bar list built for its `songlist`. */
private buildStage(): BeatorajaSkinStage {
const { skin, textures, fonts } = this.kit.kit;
const view = new BeatorajaPlaySkinView({
skin,
textures,
// The skin options' ops pick the layout variants of a select skin's destinations (ModernChic's per-option rects).
skinConfigOps: this.skinState.baseOps(),
// The texts and numbers follow the focused bar, as beatoraja's select screen does.
resolveTextContent: (ref) => this.skinState.resolveSelectionText(ref),
resolveNumberValue: (ref) => this.skinState.resolveSelectionNumber(ref),
// The image sets with a `ref`: the MODE, SORT and LNMODE buttons' labels, the lamp.
resolveRefValue: (ref) => this.skinState.resolveSelectionRefValue(ref),
resolveSliderValue: (type) => resolveBeatorajaSelectSliderValue(type),
onButtonAction: (act, modifiers) => this.handleButtonAction(act, modifiers?.shift === true),
resolveFontFamily: fonts !== undefined ? (id) => fonts.family(id) : undefined,
resolveFontKind: fonts !== undefined ? (id) => fonts.kind(id) : undefined,
// The focused chart's `#STAGEFILE` / `#BACKBMP` / `#BANNER` (-100 / -101 / -102), its BPM and notes graphs.
chartImageProvider: (id) => this.chartImages.resolveChartImageForFocus(id),
resolveBPMGraphData: () => this.chartImages.resolveBPMGraphDataForFocus(),
resolveNoteDistribution: () => this.chartImages.resolveNoteDistributionForFocus(),
});
const stage = new BeatorajaSkinStage(view);
// The rows lay themselves out on the stage's canvas.
this.stage = stage;
// At the skin's `songlist` anchor in its destinations: what the skin declares before it draws behind the bars,
// what it declares after on top.
view.container.addChildAt(this.listLayer, view.songListLayerInsertIndex);
// Another skin can lay the bars out otherwise (another `liston[]` length): the rows are built again for it.
this.rows.songList = parseBeatorajaSongList(skin);
this.rows.applySongListGeometry();
this.rows.buildRowVisuals(fonts);
return stage;
}
/** The screen entered: its timers start, and the list shows the cursor at once. */
private startScene(frame: SelectFrame): void {
this.enteredAtMs = frame.clock.enteredAtMs;
this.timerStartedAt.clear();
this.timerStartedAt.set(TIMER_SCENE_START, 0);
this.timerStartedAt.set(TIMER_SONGBAR_CHANGE, 0);
this.shownPanel = undefined;
this.scrollPosition = frame.cursor;
this.shownEntries = frame.entries;
this.focusedTarget = barTarget(frame.entries[frame.cursor]);
this.lastDrawMs = undefined;
}
/**
* Follows the frame's list: a new list snaps the glide to the cursor; a cursor move keeps the list where it shows now
* relative to the bar left, so the glide takes the move's own steps to the new bar (the short way round a wrap). The
* bar-change timer starts whenever the bar under the cursor changes or the list moves. Then the glide closes on the
* cursor, at the same speed whatever the frame rate.
*/
private followList(frame: SelectFrame): void {
let moved = false;
if (frame.entries !== this.shownEntries) {
this.shownEntries = frame.entries;
this.scrollPosition = frame.cursor;
moved = true;
} else {
for (const event of frame.events) {
if (event.kind !== 'browse' || event.event.kind !== 'cursor') continue;
const { from, to, delta } = event.event;
this.scrollPosition += to - delta - from;
moved = true;
}
}
const target = barTarget(frame.entries[frame.cursor]);
if (target !== this.focusedTarget) {
this.focusedTarget = target;
moved = true;
}
if (moved) this.timerStartedAt.set(TIMER_SONGBAR_CHANGE, beatorajaSceneNowMs(frame.clock));
const steps = this.lastDrawMs === undefined ? 1 : Math.max(0, frame.clock.nowMs - this.lastDrawMs) / FRAME_MS;
this.lastDrawMs = frame.clock.nowMs;
const gap = frame.cursor - this.scrollPosition;
if (Math.abs(gap) < SCROLL_SNAP_THRESHOLD) {
this.scrollPosition = frame.cursor;
} else {
this.scrollPosition += gap * (1 - Math.pow(1 - SCROLL_TWEEN_RATE, steps));
}
}
/**
* The option panel the session has open (START, SELECT, or both, held), as beatoraja's `MusicSelector` shows it: the
* panel's open timer (21-23) starts as it opens and its close timer (31-33) as it closes, which the skin's panel
* images animate on.
*/
private followPanel(frame: SelectFrame): void {
Eif (frame.panel === this.shownPanel) return;
const nowMs = beatorajaSceneNowMs(frame.clock);
const previous = this.shownPanel;
if (previous !== undefined) {
this.timerStartedAt.delete(LR2_TIMER.PANEL1_OPEN + previous - 1);
this.timerStartedAt.set(LR2_TIMER.PANEL1_CLOSE + previous - 1, nowMs);
}
if (frame.panel !== undefined) {
this.timerStartedAt.delete(LR2_TIMER.PANEL1_CLOSE + frame.panel - 1);
this.timerStartedAt.set(LR2_TIMER.PANEL1_OPEN + frame.panel - 1, nowMs);
}
this.shownPanel = frame.panel;
}
/** The skin's ops with the open panel's (`OPTION_PANEL1`-`3`), or no panel's (20). */
private withPanelOps(ops: ReadonlySet<number>): ReadonlySet<number> {
const withPanel = new Set(ops);
withPanel.add(this.shownPanel === undefined ? LR2_OP.NO_PANEL : LR2_OP.PANEL1 + this.shownPanel - 1);
return withPanel;
}
// ---------------------------------------------------------------------------------------------------------------------
// Input
// ---------------------------------------------------------------------------------------------------------------------
/**
* A click on visible row `rowOffset`: the bar shown there (around the glide, wrapped) is taken when it is the focused
* one, else the cursor moves onto it by the rows between, so the list glides the way the player clicked.
*/
private handleRowPointerTap(rowOffset: number): void {
const frame = this.frame;
Iif (frame === undefined || this.disposed) return;
const total = frame.entries.length;
Iif (total === 0) return;
const shown = Math.round(this.scrollPosition);
const raw = shown + (rowOffset - this.rows.centreRowIndex);
const index = ((raw % total) + total) % total;
if (index === frame.cursor) {
this.emit?.({ type: 'activate' });
return;
}
this.emit?.({ type: 'browse', command: { type: 'move', delta: raw - frame.cursor } });
}
/**
* A click on one of the skin's buttons (`image[].act`), as an intent. The press lights the button's op for a moment
* whatever it does. `back` is Shift held: the MODE, SORT, LNMODE and JUDGE TIMING buttons step back.
*/
private handleButtonAction(act: number, back: boolean): void {
Iif (this.disposed) return;
this.skinState.buttonPressedAt.set(act, this.context.nowMs());
const emit = this.emit;
const frame = this.frame;
Iif (emit === undefined || frame === undefined) return;
const step = back ? -1 : 1;
switch (act) {
// PLAY and PRACTICE pick the mode they start in, as beatoraja's do (`BMSPlayerMode.PLAY` / `PRACTICE`).
case BEATORAJA_BUTTON.PLAY:
case BEATORAJA_BUTTON.PRACTICE: {
const practice = act === BEATORAJA_BUTTON.PRACTICE;
if ((frame.playOptions.practice ?? false) !== practice)
emit({ type: 'set-play-option', key: 'practice', value: practice });
emit({ type: 'start', autoPlay: false });
return;
}
case BEATORAJA_BUTTON.AUTOPLAY:
emit({ type: 'start', autoPlay: true });
return;
case BEATORAJA_BUTTON.READTEXT:
emit({ type: 'readtext' });
return;
case BEATORAJA_BUTTON.FAVORITTE_SONG:
emit({ type: 'browse', command: { type: 'favorite', list: 'music' } });
return;
case BEATORAJA_BUTTON.FAVORITTE_CHART:
emit({ type: 'browse', command: { type: 'favorite', list: 'charts' } });
return;
case BEATORAJA_BUTTON.MODE: {
const list = this.listAsked ?? frame.browse.list;
const keysFilter =
BEATORAJA_KEYS_FILTERS[
stepIndex(beatorajaKeysFilterIndex(list.keysFilter), step, BEATORAJA_KEYS_FILTERS.length)
]!;
this.listAsked = { keysFilter, sort: list.sort };
emit({ type: 'browse', command: { type: 'list', options: { keysFilter } } });
return;
}
case BEATORAJA_BUTTON.SORT: {
const list = this.listAsked ?? frame.browse.list;
const sort = BEATORAJA_SORTS[stepIndex(beatorajaSortIndex(list.sort), step, BEATORAJA_SORTS.length)]!;
this.listAsked = { keysFilter: list.keysFilter, sort };
emit({ type: 'browse', command: { type: 'list', options: { sort } } });
return;
}
case BEATORAJA_BUTTON.JUDGE_TIMING:
this.stepJudgeTiming(step);
return;
case BEATORAJA_BUTTON.OPEN_IR_WEBSITE:
openIRWebsite();
return;
// beatoraja's replay1-4 buttons replay the bar from their slot (`getReplayEventConsumer`).
case BEATORAJA_BUTTON.REPLAY:
case BEATORAJA_BUTTON.REPLAY2:
case BEATORAJA_BUTTON.REPLAY3:
case BEATORAJA_BUTTON.REPLAY4:
emit({ type: 'replay', slot: beatorajaReplayButtonSlot(act)! });
return;
default: {
const focused = frame.entries[frame.cursor];
const pms = focused?.kind === 'chart' && resolveLibraryChartPlayVariant(focused.chart) === '9';
const changed = resolveBeatorajaOptionButton(act, frame.playOptions, back, { pms });
Eif (changed !== undefined) {
for (const [key, value] of Object.entries(changed))
emit({ type: 'set-play-option', key: key as keyof PlayOptions, value });
return;
}
// The key config, skin select and the community extensions (GdbG's volume, 900) do nothing yet.
log.debug('button not implemented', { act });
return;
}
}
}
/**
* Steps the skin's judge timing offset (number 12) by 1 ms within ±500 ms, and hands the options to the host to keep.
* The view draws with them at once.
*/
private judgeTimingAsked: { revision: number; value: number } | undefined;
private stepJudgeTiming(step: number): void {
const frame = this.frame;
Iif (!frame) return;
const current =
this.judgeTimingAsked?.revision === frame.revision
? this.judgeTimingAsked.value
: frame.playOptions.judgeTimingMs;
const next = Math.max(-JUDGE_TIMING_LIMIT_MS, Math.min(JUDGE_TIMING_LIMIT_MS, current + step));
if (next === current) return;
this.judgeTimingAsked = { revision: frame.revision, value: next };
this.emit?.({ type: 'set-play-option', key: 'judgeTimingMs', value: next });
}
/** Decodes a chart's own images, over the files of the library drawn. */
private decodeChartImages(chartEntry: LibraryChart): Promise<BeatorajaChartImages> {
const library = this.frame?.library;
Iif (library === undefined) return Promise.resolve({});
const load = this.options.loadChartImages;
return load !== undefined
? load(chartEntry, library)
: loadBeatorajaChartImages(chartEntry, resolveChartSource(library, chartEntry));
}
/**
* The view as its parts read and drive it: getters over its state and the frame drawn, and arrow methods over its
* own, so the parts reach what they need while it stays private to the view.
*/
private static createContext(view: BeatorajaSelectView): BeatorajaSelectViewContext {
return {
get view(): BeatorajaPlaySkinView {
return view.stage.view;
},
get options() {
return view.kit.kit;
},
get listLayer(): Container {
return view.listLayer;
},
get entries(): ReadonlyArray<LibraryEntry> {
return view.frame?.entries ?? [];
},
get currentIndex(): number {
return view.frame?.cursor ?? 0;
},
get scrollPosition(): number {
return view.scrollPosition;
},
handleRowPointerTap: (rowOffset) => view.handleRowPointerTap(rowOffset),
get searchQuery(): string {
return view.frame?.browse.searchText ?? '';
},
get list() {
return view.frame?.browse.list ?? { keysFilter: 'ALL' as const, sort: 'OFF' as const };
},
get playOptions() {
const options = view.frame?.playOptions;
return options && view.judgeTimingAsked && view.judgeTimingAsked.revision === view.frame?.revision
? { ...options, judgeTimingMs: view.judgeTimingAsked.value }
: options;
},
currentFolderLabel: () => view.frame?.browse.path.at(-1)?.label ?? '',
lampOpOf: (entry) => {
const records = view.frame?.records;
Iif (records === undefined) return undefined;
const record =
entry.kind === 'chart'
? records.chart(entry.chart)
: entry.kind === 'course'
? records.course(entry.course)
: undefined;
return record !== undefined ? beatorajaClearLampOp(record.lamp) : undefined;
},
get replaySlots() {
return view.frame?.replaySlots;
},
nowMs: () => view.frame?.clock.nowMs ?? 0,
get decodeChartImages() {
return (chartEntry: LibraryChart) => view.decodeChartImages(chartEntry);
},
get disposed(): boolean {
return view.disposed;
},
};
}
}
/** `index` stepped by `step` round `count` choices. */
function stepIndex(index: number, step: number, count: number): number {
return (((index + step) % count) + count) % count;
}
/**
* Opens the IR (Internet Ranking) website in a new tab (OPEN_IR_WEBSITE, act 210): the LR2IR-compatible ranking most
* beatoraja players use. The chart's MD5 is not worked out, so it opens the site's ranking page for the player to
* search; `noopener` keeps the site from reaching back into the player.
*/
function openIRWebsite(): void {
if (typeof window === 'undefined') return;
window.open('http://www.dream-pro.info/~lavalse/LR2IR/search.cgi?mode=ranking', '_blank', 'noopener,noreferrer');
}
|