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 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 | 2x 3x 2x 2x 2x 2x 2x 2x 1x 1x 1x | // The player's Options dialog: its tabs and folders, the controllers the app reaches after building them, and the locks
// a play puts on them. The tabs, folders and pages, and where each option goes among them, are `options-layout.json`'s
// (`layout.ts`); each option is built in a module of its own (`play-options.ts`, `tempo.ts`, …) with the dialog as
// `this`, which places it by its id (`place`). The dialog reaches the app only through `OptionsDialogDeps`, which the
// app (`app/app.ts`) builds.
import { pickLiveDisplayPlayOptions } from '@be-music/player-scene-model';
import type { BeatorajaSkinConfig, BeatorajaSkinHeader } from '@be-music/skin-beatoraja';
import type { LR2DiscoveredTheme } from '@be-music/skin-lr2';
import type { TunableCompressor } from '@be-music/player-browser/audio';
import { getBrowserWorkerCount } from '@be-music/player-browser/compute';
import type { PixiSceneHost, PlayScene, SelectScene } from '@be-music/player-browser/host';
import type { BeatorajaThemeBundle } from '@be-music/player-browser/skin';
import {
formatGaugeLabel,
isDuplicatedBattleChoice,
keepGaugePick,
keepPracticeGauge,
practiceGaugeSource,
type PlayOptions,
} from '@be-music/player-scene-model';
import type { BeMusicSkin } from '@be-music/player-skin-sdk';
import {
OptionFolder,
type OptionBinding,
type OptionButton,
type OptionContainer,
type OptionRow,
} from '../options-controls.ts';
import { paneOptions, type PaneBinding } from '../../pane-controls.ts';
import { migrateOptionValue, practiceReadsJudgeRankAndTotal, type GaugePick } from '@be-music/player-engine/ruleset';
import { readStoredCompressorTunings, type CompressorTuning } from '../../compressor-tuning.ts';
import { readStoredCourseTableURLs, removedDefaultCourseTableURLs } from '../../course-table-import.ts';
import { readStoredBemuseServerURLs } from '../../bemuse-server.ts';
import { captureOptionSettings } from '../../option-settings.ts';
import { optionSettingsSync } from '../../option-settings-sync.ts';
import type { FamilyDispatchState } from '../../family-dispatch.ts';
import type { LeaderboardPanel } from '../../leaderboard-ui.ts';
import type { CourseMakerService } from '../../services/course-maker.ts';
import {
resolveGhostStatus,
type GhostBarFacts,
type GhostModeSetting,
type GhostReplayFile,
type GhostSourceSetting,
} from '../../services/ghost.ts';
import type { LibraryService } from '../../services/library.ts';
import type { RecordsService } from '../../services/records.ts';
import type { BGACameraService } from '../../services/bga-camera.ts';
import type { SilentModeSetting } from '../../services/silent-mode.ts';
import type { StoredSkinSettings } from '../../skin-settings.ts';
import type { PlayerGUIState, SkinFamilyOverride } from '../../types.ts';
import type { ActiveBeatorajaPlay } from '../beatoraja-skin-options.ts';
import type { SkinDropFamily } from '../skin-drop-prompt.ts';
import { buildAudioFolder } from './audio.ts';
import { buildBGACameraFolder } from './bga-camera.ts';
import { buildCaptureFolder } from './capture.ts';
import {
buildCompressorTuningGUI,
refreshCompressorStageVisibility,
resolveCompressorParamOverrides,
} from './compressor.ts';
import { buildCourseFolder } from './course.ts';
import { buildDeveloperFolder } from './developer.ts';
import { OPTIONS_LAYOUT } from './folders.ts';
import { OptionLayout, type OptionPlacement } from './layout.ts';
import { runtimeOptionDefaults } from './runtime-defaults.ts';
import { buildLibraryFolder } from './library.ts';
import { PlayLock } from './play-lock.ts';
import {
battleModeItems,
crazyNotesItems,
bottomShiftableGaugeItems,
gaugeItems,
laneOptionItems,
menuLaneCovers,
practiceGaugeItems,
} from './play-option-items.ts';
import { buildPlayOptionsFolder, buildReplayViewFolder } from './play-options.ts';
import { buildQuickOptionsPanel, QUICK_OPTIONS_ENABLED } from './quick-options.ts';
import { detectRenderResolution, scheduleFirstRunResolutionDetect } from './render-resolution.ts';
import { applyBeatorajaSkinSwitchIfActive, rebuildBeatorajaSkinPickers } from './skin-pickers.ts';
import { buildSkinFolder, rebuildLR2ThemePicker, rebuildSkinFamilyPicker, rebuildSkinSettingsFolder } from './skin.ts';
import { OptionHelp } from './help.ts';
import { OptionSearch } from './search.ts';
import { buildKeyConfigFolder } from './keys.ts';
import { relabelOptions } from './labels.ts';
import { buildTempoFolder } from './tempo.ts';
import { onPlayerLangChange, playerLang, playerText } from '../../player-copy.ts';
import { describeRecordConsequence } from '../../services/record-consequence.ts';
import { releaseFocusOnClose } from '../dialog-focus.ts';
/** The options of `options-layout.json` only some browsers or builds have, which the code may leave unbuilt. */
const OPTIONAL_OPTIONS: ReadonlySet<string> = new Set([
'playInSilentMode',
'silentModeNote',
'addSkinURL',
'addSkinFromURL',
'lr2Theme',
]);
/**
* What the Options dialog needs from the app: the settings and stores its controllers change, readers of what the app has
* loaded and shows, and the app's actions its controllers start. The actions keep the names of the app's methods.
*/
export interface OptionsDialogDeps {
/** The settings the controllers read and write (`createPlayerGUIState`), read by the app as each play starts. */
readonly settings: PlayerGUIState;
/** The replay file "Ghost replay file…" picks as a ghost. */
readonly ghostReplayFile: GhostReplayFile;
/** The scene host: "Render resolution" sets its resolution, and the Developer folder reads its frame rate. */
readonly sceneHost: PixiSceneHost;
readonly showFPSOverlay: (shown: boolean) => void;
/** "Play in silent mode": the Audio folder's checkbox and the start card's option drive it. */
readonly silentMode: SilentModeSetting;
/** The Leaderboard panel, which fills its own folder. */
readonly leaderboard: Pick<LeaderboardPanel, 'buildFolder'>;
/**
* The library service: the difficulty tables, "Load from URLs" and the Bemuse music servers add to the library through
* it, a removed table leaves it, and "Reload folders" reads it again.
*/
readonly library: Pick<
LibraryService,
| 'importCourseTables'
| 'removeCourseTable'
| 'courseTableLabel'
| 'onCourseTablesChange'
| 'loadFromURL'
| 'loadBemuseServers'
| 'refreshBemuseReplayGain'
| 'reloadCharts'
>;
/** The records service, whose best records "Clear best records" empties. */
readonly records: Pick<RecordsService, 'chartBestRecords'>;
/** The course-maker service, whose card "My courses…" opens. */
readonly courseMaker: Pick<CourseMakerService, 'panel'>;
/** Each Be-Music Skin's stored settings by skin id, which the "Skin settings" folder edits. */
readonly skinSettings: StoredSkinSettings;
/** The beatoraja skin entry picked for each scene type (`SkinType`), which the "Beatoraja skins" pickers write. */
readonly beatorajaSkinOverridesByType: Map<number, string>;
/** The compressor architecture every play mounts with (`?compressor=`), read once at boot. */
readonly compressorMode: 'split' | 'legacy';
/**
* The player shell. "Toggle fullscreen" covers the play surface inside it (`#main`), where this menu is mounted, so
* the site header and the site footer stay outside fullscreen.
*/
readonly shell: HTMLElement;
/** The camera the play can show in its BGA frame, which the Camera tab sets up. */
readonly bgaCamera: BGACameraService;
/** The play: loading behind a decide screen, or on the stage. */
gameplayView(): PlayScene | undefined;
/** The select screen, on the stage or kept off it. */
selectView(): SelectScene | undefined;
/** The loaded skins and the skin family pick, which say whether an LR2 skin is loaded. */
familyDispatchState(): FamilyDispatchState;
hasPendingSkin?(family: 'lr2' | 'beatoraja'): boolean;
/** The loaded beatoraja theme. */
beatorajaTheme(): BeatorajaThemeBundle | undefined;
/** The LR2 themes the drops so far discovered, by name. */
availableLR2Themes(): ReadonlyArray<LR2DiscoveredTheme<File>>;
/** The name of the LR2 theme mounted. */
activeLR2ThemeName(): string | undefined;
/** The Be-Music Skin the built-in scenes draw with. */
beMusicSkin(): BeMusicSkin;
/** The beatoraja play entry the play on the stage is drawn with, when it plays on a beatoraja theme. */
activeBeatorajaPlay(): ActiveBeatorajaPlay | undefined;
/** The player's options for a beatoraja entry, or its header's defaults. */
beatorajaSkinConfig(entryPath: string, header: BeatorajaSkinHeader): BeatorajaSkinConfig;
/** Shows a status line. */
setStatus(text: string): void;
/** Keeps play options set from the menu for every screen and play, and hands them to the select screen. */
reusePreviousArrangement?(): Partial<PlayOptions> | undefined;
clearArrangement?(): void;
setPlayOptions(changes: Partial<PlayOptions>): void;
/** Remembers a hi-speed set on the menu's slider, and hands it to the running play. */
rememberHiSpeed(value: number, source: 'menu'): void;
/**
* Has the select screen draw its records again, as they read now: those of the judge ruleset or the NONSTOP placement
* just picked.
*/
refreshSelectRecords(): void;
/** Switches the scenes to another skin system (or the same one with other effects), making the select screen again. */
handleSkinFamilyOverrideChange(value: SkinFamilyOverride): void;
/** Switches the built-in scenes to another Be-Music Skin. */
handleBuiltInSkinChange(id: string): void;
/** Adds a Be-Music Skin and switches to it. */
addBeMusicSkin(skin: BeMusicSkin): void;
/** Imports a Be-Music Skin module from a URL and adds it. */
addBeMusicSkinFromURL(url: string): Promise<void>;
/** Hands the Be-Music Skin's settings, as stored, to the scenes drawing with it. */
applyBeMusicSkinSettings(): void;
/** Mounts another of the discovered LR2 themes. */
applyLR2ThemeByName(name: string): Promise<void>;
/** Asks for a drop of a skin of a skin system with none loaded (`promptSkinDrop`). */
promptSkinDrop(family: SkinDropFamily): void;
/** Loads the select entry again with other options and hands it to the beatoraja select screen. */
applyBeatorajaSelectSkinConfig(entryPath: string, config: BeatorajaSkinConfig): Promise<void>;
/** Loads a play entry again with other options and hands it to the beatoraja play on the stage. */
applyBeatorajaPlaySkinConfig(entryPath: string, config: BeatorajaSkinConfig): Promise<void>;
}
/**
* The Options dialog, opened from the header's Settings button. {@link buildGUI} makes it; then the app reaches it
* through the methods it calls on a change of its own: a theme load rebuilds the pickers, a status line repaints the
* status row, a play locks the options it latched ({@link lockForPlay}) and its end unlocks them ({@link unlockAfterPlay}).
*
* The folders are built by functions in modules of their own, which run with the dialog as `this`, so the controllers
* and helpers they reach are public members.
*/
export class OptionsDialog {
/** What the menu reaches of the app. */
public readonly deps: OptionsDialogDeps;
/** The settings the controllers read and write ({@link OptionsDialogDeps.settings}). */
public readonly guiState: PlayerGUIState;
public readonly sceneHost: PixiSceneHost;
public readonly silentMode: SilentModeSetting;
public readonly library: Pick<
LibraryService,
| 'importCourseTables'
| 'removeCourseTable'
| 'courseTableLabel'
| 'onCourseTablesChange'
| 'loadFromURL'
| 'loadBemuseServers'
| 'refreshBemuseReplayGain'
| 'reloadCharts'
>;
public readonly records: Pick<RecordsService, 'chartBestRecords'>;
public readonly courseMaker: Pick<CourseMakerService, 'panel'>;
public readonly skinSettings: StoredSkinSettings;
public readonly beatorajaSkinOverridesByType: Map<number, string>;
public readonly compressorMode: 'split' | 'legacy';
/**
* Options folder hosting one dropdown per skin scene type (Play 5K / 7K / 9K / 10K / 14K /
* 24K / 24Kdp / Music Select / Decide / Result / etc.). Empty until a beatoraja theme is
* dropped — `rebuildBeatorajaSkinPickers` (re-)populates it from `beatorajaTheme.entries`.
*/
public beatorajaSkinPickerFolder: OptionContainer | undefined;
/**
* Active controllers inside {@link beatorajaSkinPickerFolder}, keyed by scene type. Cleared
* and rebuilt on each `rebuildBeatorajaSkinPickers` call so dropdown options stay in sync with
* the latest theme drop.
*/
public readonly beatorajaSkinPickerControllers: Map<number, PaneBinding> = new Map();
/** The skin system the scenes run on, so a pick of one that is not loaded can be undone. */
public activeSkinSystem: SkinFamilyOverride = 'auto';
/** The Options dialog's "Render resolution" dropdown and "Auto-detect resolution" button. */
public resolutionPicker: PaneBinding | undefined;
public autoDetectResolutionControl: OptionButton | undefined;
/** Whether a render resolution benchmark is running. */
public detectingResolution = false;
/** Whether this visit already scheduled the first-run benchmark. */
public firstRunResolutionScheduled = false;
/**
* Handles for controllers we need to address by name after construction — toggling the per-stage controls
* visibility, renaming the record button, and reflecting URL-driven compressor changes in the dialog.
*/
public gui: OptionFolder | undefined;
public readonly compressorStageControllers: OptionRow[] = [];
/** Compressor tuning in slider units, restored from the last visit; seeds every gameplay mount. */
public readonly compressorTunings: Record<TunableCompressor, CompressorTuning> = readStoredCompressorTunings();
public recordController: OptionButton | undefined;
/** The Capture folder's Video format and Video quality, locked while a recording runs. */
public recordingSettingControllers: PaneBinding[] = [];
/**
* "Auto-save replays" checkbox controller. Held so the play-start path sets `disabled` for the duration
* of a play — the replay options are latched when a song starts and cannot change mid-song — and the result /
* select paths enable it again.
*/
public replaySaveController: PaneBinding | undefined;
public fpsOverlayController: OptionBinding<boolean> | undefined;
/**
* Every "Play options" folder controller (auto play / judge / gauge / random / DP flip / auto scratch). Disabled
* together while a song is playing (`lockReplayOptionsForPlay`) and refreshed when the LR2 select panel pushes
* a change (`refreshPlayOptionControllers`).
*/
public readonly playOptionControllers: { disabled: boolean; refresh?: () => void }[] = [];
/** The "Hi-speed" slider — left enabled during a play (it applies live) and repainted by {@link refreshHiSpeed}. */
public hiSpeedController: PaneBinding | undefined;
public judgeTimingController: PaneBinding | undefined;
public judgeTimingAutoAdjustController: PaneBinding | undefined;
public hsFixController: OptionBinding<PlayOptions['hsFix']> | undefined;
public fixedDisplayAreaController: PaneBinding | undefined;
public floatingHiSpeedController: PaneBinding | undefined;
public floatingSpeedController: PaneBinding | undefined;
public classicHiSpeedController: PaneBinding | undefined;
public normalHiSpeedController: PaneBinding | undefined;
public normalHiSpeedLevelController: PaneBinding | undefined;
public classicSpeedController: PaneBinding | undefined;
public randomSeed1PController: PaneBinding | undefined;
public randomSeed2PController: PaneBinding | undefined;
public random1PController: OptionBinding<PlayOptions['random1P']> | undefined;
public random2PController: OptionBinding<PlayOptions['random2P']> | undefined;
public gaugeController: OptionBinding<GaugePick> | undefined;
/** The quick options panel (`quick-options.ts`), and the controls on it whose choices or visibility follow others. */
public quickOptionsPanel: OptionFolder | undefined;
public quickRandom1PController: OptionBinding<PlayOptions['random1P']> | undefined;
public quickGaugeController: OptionBinding<GaugePick> | undefined;
public quickHsFixController: OptionBinding<PlayOptions['hsFix']> | undefined;
public quickHiSpeedController: PaneBinding | undefined;
public bottomShiftableGaugeController: OptionBinding<PlayOptions['bottomShiftableGauge']> | undefined;
public gaugeAutoShiftController: OptionBinding<PlayOptions['gaugeAutoShift']> | undefined;
public longNoteModifierController: OptionBinding<PlayOptions['longNoteModifier']> | undefined;
public longNoteRateController: PaneBinding | undefined;
public sevenToNinePatternController: OptionBinding<PlayOptions['sevenToNinePattern']> | undefined;
public sevenToNineTypeController: OptionBinding<PlayOptions['sevenToNineType']> | undefined;
public battleModeController: OptionBinding<PlayOptions['battleMode']> | undefined;
public dBattleScratchController: PaneBinding | undefined;
public gauge2PController: OptionBinding<PlayOptions['gauge2P']> | undefined;
public mRanControllers: PaneBinding[] = [];
public lr2ExtraModeController: PaneBinding | undefined;
public anyKeyController: PaneBinding | undefined;
public lr2ExtraLevelController: OptionBinding<PlayOptions['lr2ExtraLevel']> | undefined;
public extraNoteDepthController: PaneBinding | undefined;
public customJudgeController: PaneBinding | undefined;
public lr2GambolController: PaneBinding | undefined;
/** PRACTICE toggle first, then its settings. */
public practiceControllers: PaneBinding[] = [];
/** PRACTICE's GAUGE TYPE: the judge ruleset's own gauges. */
public practiceGaugeController: OptionBinding<PlayOptions['practiceGauge']> | undefined;
/** PRACTICE's GAUGE CATEGORY, which only beatoraja has. */
public practiceGaugeCategoryController: PaneBinding | undefined;
/** PRACTICE's JUDGERANK and TOTAL, which That-Which-Must-Not-Be-Named does not read. */
public practiceJudgeRankAndTotalControllers: PaneBinding[] = [];
public longNoteModeController: OptionBinding<PlayOptions['longNoteMode']> | undefined;
public customJudgeRateControllers: PaneBinding[] = [];
public extraNoteScratchController: PaneBinding | undefined;
public mineModifierController: OptionBinding<PlayOptions['mineModifier']> | undefined;
public scrollModifierController: OptionBinding<PlayOptions['scrollModifier']> | undefined;
public scrollSectionController: PaneBinding | undefined;
public scrollRateController: PaneBinding | undefined;
public judgeAlgorithmController: OptionBinding<PlayOptions['judgeAlgorithm']> | undefined;
/** "Ghost" (Replay / ghost): which replay a ghost plays. Disabled during a play, and on a course bar. */
public ghostController: OptionBinding<GhostSourceSetting> | undefined;
/** "Ghost mode": how the ghost shows. Disabled with "Ghost". */
public ghostModeController: OptionBinding<GhostModeSetting> | undefined;
/** nanasigroove's NOTES, whose COPY and DBLCOPY a course bar dims. */
public crazyNotesController: OptionBinding<PlayOptions['crazyNotes']> | undefined;
/** "Ghost status": whether the bar under the cursor would show the picked ghost, or why not. */
public ghostStatusController: PaneBinding | undefined;
/** What "Ghost status" shows. */
public readonly ghostStatus = { text: '-' };
/** Whether a play runs, which disables "Ghost" with the other play options. */
public ghostLocked = false;
/** What the select screen knows of the bar under the cursor ({@link setGhostAvailability}). */
private ghostBar: GhostBarFacts | undefined;
/** The "Tempo (%)" slider — left enabled during a play whose tempo can change live (`allowsLiveTempo`). */
public tempoController: PaneBinding | undefined;
/** Rows created for the active Be-Music Skin's settings. */
public readonly skinSettingRows: OptionRow[] = [];
/** Native list whose options follow loaded theme families without replacing its event handlers. */
public confirmDroppedSkinController: OptionBinding<boolean> | undefined;
public skinFamilyController: OptionBinding<SkinFamilyOverride> | undefined;
/** Native theme list, refreshed as drops discover new themes. */
public lr2ThemeController: OptionBinding<string> | undefined;
/**
* The Options dialog's skin controls that make the select screen again: Built-in skin, Skin effects, the Add skin
* buttons and the LR2 theme picker. They are disabled during a play ({@link playLock}), since going back to the
* select screen would end it. Skin system stays enabled: it swaps the play's family without leaving the chart.
*/
public readonly skinControllers: OptionRow[] = [];
/** The locks a play puts on the options it latched and on the skin controls, and whether one runs. */
public readonly playLock: PlayLock = new PlayLock(() => ({
replaySave: this.replaySaveController,
playOptions: this.playOptionControllers,
tempo: this.tempoController,
skin: [this.lr2ThemeController, ...this.skinControllers],
}));
/** Read-only multiline monitor, refreshed immediately when the app posts status. */
// The folders and the controls that follow what is loaded, each built in its own module with the dialog as `this`.
private readonly buildCaptureFolder = buildCaptureFolder;
private readonly buildBGACameraFolder = buildBGACameraFolder;
private readonly buildPlayOptionsFolder = buildPlayOptionsFolder;
private readonly buildReplayViewFolder = buildReplayViewFolder;
private readonly buildKeyConfigFolder = buildKeyConfigFolder;
private readonly buildTempoFolder = buildTempoFolder;
private readonly buildCourseFolder = buildCourseFolder;
private readonly buildAudioFolder = buildAudioFolder;
private readonly buildSkinFolder = buildSkinFolder;
private readonly buildLibraryFolder = buildLibraryFolder;
private readonly buildDeveloperFolder = buildDeveloperFolder;
public readonly buildCompressorTuningGUI = buildCompressorTuningGUI;
public readonly refreshCompressorStageVisibility = refreshCompressorStageVisibility;
/** Bus `CompressorParams` for every compressor, from the tuning: what each play mounts with. */
public readonly resolveCompressorParamOverrides = resolveCompressorParamOverrides;
/** Rebuilds the Skin system picker's options: on every theme load. */
public readonly rebuildSkinFamilyPicker = rebuildSkinFamilyPicker;
/** Refills the "Skin settings" folder: when the Be-Music Skin changes. */
public readonly rebuildSkinSettingsFolder = rebuildSkinSettingsFolder;
/** Rebuilds the LR2 theme picker: on every LR2 theme load. */
public readonly rebuildLR2ThemePicker = rebuildLR2ThemePicker;
/** Rebuilds the "Beatoraja skins" pickers: on every beatoraja theme load. */
public readonly rebuildBeatorajaSkinPickers = rebuildBeatorajaSkinPickers;
public readonly applyBeatorajaSkinSwitchIfActive = applyBeatorajaSkinSwitchIfActive;
/** Benchmarks the render resolution once, the first time the select screen shows. */
public readonly scheduleFirstRunResolutionDetect = scheduleFirstRunResolutionDetect;
public readonly detectRenderResolution = detectRenderResolution;
public constructor(deps: OptionsDialogDeps) {
this.deps = deps;
this.guiState = deps.settings;
this.sceneHost = deps.sceneHost;
this.silentMode = deps.silentMode;
this.library = deps.library;
this.records = deps.records;
this.courseMaker = deps.courseMaker;
this.skinSettings = deps.skinSettings;
this.beatorajaSkinOverridesByType = deps.beatorajaSkinOverridesByType;
this.compressorMode = deps.compressorMode;
}
/** The play: loading behind a decide screen, or on the stage. */
public get gameplayView(): PlayScene | undefined {
return this.deps.gameplayView();
}
/** The select screen, on the stage or kept off it. */
public get selectView(): SelectScene | undefined {
return this.deps.selectView();
}
/** Shows a status line ({@link OptionsDialogDeps.setStatus}). */
public setStatus(text: string): void {
this.deps.setStatus(text);
}
/**
* SUDDEN+ / HIDDEN+ set from the menu (the Effect, Lane cover and Cover height of the View tab and the quick options
* panel): stored, and handed to a running play as its covers.
*/
public setCoverOptions(changes: Partial<PlayOptions>): void {
this.setPlayOptions(changes);
this.gameplayView?.controller.dispatch({
type: 'cover',
command: { type: 'cover-set', covers: menuLaneCovers(this.guiState) },
});
}
/** Shows the quick options panel (on the select and play screens) or hides it. */
public setQuickOptionsShown(shown: boolean): void {
const dock = this.quickOptionsPanel?.element.parentElement;
if (dock) dock.hidden = !shown;
if (shown) this.quickOptionsPanel?.refresh();
}
/** A play option set from the menu ({@link OptionsDialogDeps.setPlayOptions}). */
public setPlayOptions(changes: Partial<PlayOptions>): void {
this.deps.setPlayOptions(changes);
// A running play follows its display options at once; the rest it read when it started.
const live = pickLiveDisplayPlayOptions(changes);
if (live !== undefined) this.gameplayView?.controller.dispatch({ type: 'display-options', values: live });
}
/** Where each option goes: the dialog's tabs, folders and pages, made from `options-layout.json` by {@link buildGUI}. */
public layout: OptionLayout<OptionContainer> | undefined;
/** Where the option or group `id` of `options-layout.json` goes: rows made through it land there. */
public place(id: string): OptionPlacement {
if (this.layout === undefined) throw new Error('The Options dialog is not built yet');
return this.layout.place(id);
}
/** The header gear follows the Options dialog: open, closed with its close button, Escape or a backdrop click. */
private reportExpanded: ((open: boolean) => void) | undefined;
/** Reports when the Options dialog opens or closes. */
public watchExpanded(report: (open: boolean) => void): void {
this.reportExpanded = report;
}
/** Opens the Options dialog when it is closed, and closes it when it is open. */
public toggle(): void {
if (this.gui !== undefined) this.gui.expanded = !this.gui.expanded;
}
/** Opens and scrolls to the LR2 mania section at its current location in the layout. */
public openLR2ManiaOptions(): void {
const { gui, layout } = this;
Iif (gui === undefined || layout === undefined) return;
const path = layout.path('lr2Mania');
Iif (path.length === 0) return;
const folder = layout.folder('lr2Mania').element;
if (folder.closest('[data-option-omitted]') !== null) return;
gui.expanded = true;
for (const step of path) layout.tabs(step.tabs).select(step.page);
folder.scrollIntoView({ block: 'start' });
}
/**
* Builds the Options dialog (`#options-modal`) and wires every controller to the gameplay / scene state. Centralizing
* this in one method lets us bind handles to specific controllers (`recordController`, `compressorStageControllers`)
* up-front, so runtime code can address them by name (renaming the record button when capture starts, hiding the
* per-stage controls on compressor mode change) without re-querying the DOM.
*
* Layout: `options-layout.json` (`OPTIONS_LAYOUT`) makes the tabs, folders and pages; each build function then makes
* its options, placing each by its id. An option the layout hides is still made, so its value and behaviour stay.
*/
public buildGUI(): void {
const dialog = document.querySelector<HTMLDialogElement>('#options-modal');
const body = document.querySelector<HTMLElement>('#options-modal-body');
if (dialog === null || body === null) return;
const gui = OptionFolder.dialog(dialog, body, 'Options');
this.gui = gui;
// Help's own text for each control, beside it; rows made since the last opening (a theme's pickers) get theirs too.
const help = new OptionHelp(dialog, playerLang);
const search = new OptionSearch(
dialog,
body,
(row) => help.text(row),
() => playerText().shell.optionsSearchEmpty,
);
gui.on('fold', (event) => {
if (event.expanded) {
help.attach();
relabelOptions(gui, playerLang());
// The search field is the dialog's first control, so opening focuses it: type to find an option. A touch
// screen would raise its keyboard over the dialog, so there the focus goes to the selected tab.
if (matchMedia('(pointer: coarse)').matches) {
dialog.querySelector<HTMLElement>('[role="tab"][aria-selected="true"]')?.focus();
}
} else {
search.clear();
}
// The select screen's keys change options too, so the row is read again as the dialog opens.
if (event.expanded) this.refreshRecordConsequence();
this.reportExpanded?.(event.expanded);
});
// Closed, the keys go back to the play: left on the gear, Enter (meant to start the chart) would open it again.
releaseFocusOnClose(dialog);
dialog.querySelector('#options-modal-close')?.addEventListener('click', () => (gui.expanded = false));
// Fullscreen covers the play surface and leaves the header out, so the surface has its own Options button then.
document.querySelector('#options-open')?.addEventListener('click', () => (gui.expanded = true));
// A click on the backdrop lands on the dialog itself.
dialog.addEventListener('click', (event) => {
if (event.target === dialog) gui.expanded = false;
});
// Keys stay in the dialog, so the play behind it does not take them.
dialog.addEventListener('keydown', (event) => event.stopPropagation());
const layout = new OptionLayout(OPTIONS_LAYOUT, gui, (id, expected, actual) =>
console.error(`Options layout: "${id}" is a ${expected} in options-layout.json, but is built as a ${actual}`),
);
this.layout = layout;
// The options, area by area. Where each goes is the layout's, so the order here is only the order their side effects
// run in: the Play options read the settings the Library made, and the skin pickers follow what is loaded.
this.buildLibraryFolder();
this.buildCourseFolder();
this.buildCaptureFolder();
this.buildPlayOptionsFolder();
this.buildTempoFolder();
this.buildReplayViewFolder();
this.buildKeyConfigFolder();
this.buildSkinFolder();
this.buildAudioFolder();
this.buildBGACameraFolder(this.deps.bgaCamera);
this.deps.leaderboard.buildFolder((id) => layout.place(id));
this.buildDeveloperFolder();
layout.installSectionResets(runtimeOptionDefaults(() => this.deps.availableLR2Themes()[0]?.name));
// An option of the layout no code made is one this browser lacks (Play in silent mode), or a mistake.
const unclaimed = layout.unclaimed().filter((id) => !OPTIONAL_OPTIONS.has(id));
if (unclaimed.length > 0) console.error(`Options layout: no code builds ${unclaimed.join(', ')}`);
this.refreshCompressorStageVisibility();
gui.on('change', () => {
this.scheduleSettingsSave();
this.refreshRecordConsequence();
// The quick options panel reads the same values.
this.quickOptionsPanel?.refresh();
});
const quickDock = document.querySelector<HTMLElement>('#quick-options');
if (quickDock !== null && QUICK_OPTIONS_ENABLED) {
this.quickOptionsPanel = buildQuickOptionsPanel.call(this, quickDock);
}
help.attach();
// The labels in the player's language, and again when it changes (Help's language switch, the header's menu).
relabelOptions(gui, playerLang());
onPlayerLangChange(() => {
relabelOptions(gui, playerLang());
this.refreshRecordConsequence();
});
this.refreshRecordConsequence();
}
/** Locks the Video format and Video quality while a recording runs: they apply when the next one starts. */
public setRecordingSettingsLocked(locked: boolean): void {
for (const controller of this.recordingSettingControllers) controller.disabled = locked;
}
/**
* Writes every Options dialog setting locally immediately; remote publishing is debounced for slider changes.
* Status and the FPS graph are not settings and do not come through here.
*/
public scheduleSettingsSave(): void {
const courseTableURLs = readStoredCourseTableURLs();
const document = captureOptionSettings(this.guiState, {
compressorTuning: this.compressorTunings,
skinSettings: this.skinSettings,
courseTableURLs,
removedDefaultCourseTableURLs: removedDefaultCourseTableURLs(courseTableURLs),
bemuseServerURLs: readStoredBemuseServerURLs(),
workerCount: getBrowserWorkerCount(),
});
optionSettingsSync.save(document);
}
/**
* Options read when a play starts, which are disabled while one runs (`lockReplayOptionsForPlay`); returns the
* controller.
*/
public trackPlayOption<T extends { disabled: boolean; refresh?: () => void }>(controller: T): T {
this.playOptionControllers.push(controller);
return controller;
}
/**
* Tells the menu about the bar under the cursor: "Ghost status" says whether a play of it would show the picked ghost
* (`resolveGhostStatus`), and a course bar disables "Ghost" and "Ghost mode", their choices kept for the charts. A
* course bar also dims NOTES COPY and DBLCOPY, which a course stage leaves out (`refreshCourseBarChoices`).
*/
public setGhostAvailability(facts: GhostBarFacts | undefined): void {
this.ghostBar = facts;
this.refreshGhostAvailability();
this.refreshCourseBarChoices();
}
/** Offers NOTES COPY and DBLCOPY on a chart bar and dims them on a course bar, keeping the pick for the charts. */
public refreshCourseBarChoices(): void {
if (this.crazyNotesController) this.crazyNotesController.options = crazyNotesItems(this.ghostBar?.course === true);
}
/** The "Record" row: what the options picked do to a play's record, before it is played. */
public recordConsequenceController: PaneBinding | undefined;
public readonly recordConsequence = { text: '-' };
/** Rewrites the "Record" row from the settings as they stand, and returns its line. */
public refreshRecordConsequence(): string {
this.recordConsequence.text = describeRecordConsequence(this.guiState);
this.recordConsequenceController?.refresh();
return this.recordConsequence.text;
}
/** Repaints "Ghost", "Ghost mode" and "Ghost status": disabled during a play and on a course bar. */
public refreshGhostAvailability(): void {
const disabled = this.ghostLocked || this.ghostBar?.course === true;
if (this.ghostController) this.ghostController.disabled = disabled;
if (this.ghostModeController) this.ghostModeController.disabled = disabled;
this.ghostStatus.text = resolveGhostStatus(
this.guiState.ghost,
this.guiState.ghostMode,
this.ghostBar,
this.deps.ghostReplayFile,
);
this.ghostStatusController?.refresh();
}
/** Repaints the status row with the status line just set. */
public refreshStatus(): void {}
/** Repaints the "Hi-speed" slider with a hi-speed set elsewhere (the select screen, the play's keys). */
public refreshJudgeTiming(): void {
this.judgeTimingController?.refresh();
}
public refreshHiSpeed(): void {
this.hiSpeedController?.refresh();
this.quickHiSpeedController?.refresh();
this.floatingSpeedController?.refresh();
this.floatingHiSpeedController?.refresh();
this.refreshRulesetChoices();
this.classicSpeedController?.refresh();
this.normalHiSpeedLevelController?.refresh();
}
/** Shows `value` as the skin system the scenes run on, which a pick of one with no skin loaded goes back to. */
public showSkinSystem(value: SkinFamilyOverride): void {
this.activeSkinSystem = value;
this.skinFamilyController?.refresh();
}
/**
* Disables the options a play latches as it starts, so mid-song changes are rejected until {@link unlockAfterPlay}
* runs (result mounted or back at select), and the skin controls with them ({@link playLock}). With `liveTempo`, the
* tempo slider stays enabled and changes the play's tempo live.
*/
public lockForPlay(liveTempo = false): void {
this.playLock.lock(liveTempo);
}
/** Re-enables the replay option controllers, and the skin controls, once no play is in flight. */
public unlockAfterPlay(): void {
this.playLock.unlock();
}
/** Clears the local document and the server copy, then reloads. Best records stay. */
public async resetSettings(): Promise<void> {
if (
!window.confirm(
'Reset every Options dialog setting to its default and reload? This includes the copy kept for this browser. Best records are kept.',
)
) {
return;
}
await optionSettingsSync.reset();
window.location.reload();
}
/**
* `value` when it is one of `choices`; a bare colliding value from before ADR 0019 as the judge ruleset's own
* qualified one; `OFF` otherwise.
*/
private keepChoice<T extends string>(value: T, choices: readonly T[]): T {
if (choices.includes(value)) return value;
const migrated = migrateOptionValue(value, this.guiState.judgeRuleset) as T;
return choices.includes(migrated) ? migrated : ('OFF' as T);
}
/** Repaints the "Play options" controllers after an external write (the LR2 select panel's edits). */
public refreshRulesetChoices(): void {
// Options that only transform the chart or the view are offered under every judge ruleset (#774): HS-FIX CONSTANT,
// the measured hi-speed modes, automatic display timing, scroll and mine modifiers, both EXTRAs, 7-to-9, the battle
// chart constructions and the source-specific lane options.
if (this.hsFixController)
this.hsFixController.options = paneOptions([
'OFF',
'MAXBPM',
'MINBPM',
'AVERAGE',
'CONSTANT',
'STARTBPM',
] as const);
const floating = this.guiState.floatingHiSpeed;
// A hi-speed mode's own controls stay in place while another mode is on, disabled rather than hidden.
if (this.floatingSpeedController) this.floatingSpeedController.unavailable = !floating;
const normal = this.guiState.normalHiSpeedLevel > 0;
if (this.normalHiSpeedLevelController) this.normalHiSpeedLevelController.unavailable = !normal || floating;
if (this.hiSpeedController) this.hiSpeedController.unavailable = this.guiState.classicHiSpeed || normal || floating;
if (this.hsFixController) this.hsFixController.unavailable = this.guiState.classicHiSpeed || normal || floating;
// The quick panel offers only the regular hi-speed and HS-FIX; a measured or classic mode is set in the dialog.
if (this.quickHiSpeedController)
this.quickHiSpeedController.unavailable = this.guiState.classicHiSpeed || normal || floating;
if (this.quickHsFixController)
this.quickHsFixController.unavailable = this.guiState.classicHiSpeed || normal || floating;
if (this.classicSpeedController)
this.classicSpeedController.unavailable = !this.guiState.classicHiSpeed || floating;
if (this.anyKeyController) this.anyKeyController.hidden = this.guiState.judgeRuleset !== '____';
const ruleset = this.guiState.judgeRuleset;
const beatoraja = ruleset === 'beatoraja';
// Long-note addition is offered under every ruleset (#774): the added long notes are judged as the ruleset's long
// notes, so ADD CN / ADD HCN differ from ADD LN only under beatoraja rules.
// BATTLE names LR2's two-player play and the beatoraja / ???? one-player copy, so each carries its source
// (ADR 0019); the choices are grouped by source, the judge ruleset's own first.
const battleChoices = battleModeItems(ruleset);
const battleMode = this.keepChoice(
this.guiState.battleMode,
battleChoices.map((item) => item.value),
);
if (battleMode !== this.guiState.battleMode) {
this.guiState.battleMode = battleMode;
this.setPlayOptions({ battleMode });
}
if (this.battleModeController) {
this.battleModeController.options = battleChoices;
this.battleModeController.refresh();
}
if (this.dBattleScratchController) this.dBattleScratchController.hidden = this.guiState.battleMode !== 'D-BATTLE';
const twoPlayer = ['TWO-PLAYER', 'COUPLE', 'AUTO'].includes(this.guiState.battleMode);
if (this.gauge2PController) this.gauge2PController.hidden = !twoPlayer;
for (const controller of this.mRanControllers) controller.hidden = !twoPlayer;
if (this.lr2ExtraLevelController) this.lr2ExtraLevelController.unavailable = !this.guiState.lr2ExtraMode;
// nanasigroove's ADDMINE replaces the beatoraja mine option while it is on.
if (this.mineModifierController) this.mineModifierController.unavailable = this.guiState.crazyAddMine;
if (!beatoraja && this.guiState.longNoteMode !== 'LN') {
this.guiState.longNoteMode = 'LN';
this.setPlayOptions({ longNoteMode: 'LN' });
}
if (this.longNoteModeController) this.longNoteModeController.hidden = !beatoraja;
// PRACTICE is offered under every ruleset (#933): its gauge list is the judge ruleset's own gauges, then the other
// sources' (ADR 0019), GAUGE CATEGORY is beatoraja's alone, and AC reads neither JUDGERANK nor TOTAL.
const practice = this.guiState.practice;
this.practiceControllers.forEach((controller, index) => {
controller.hidden = index > 0 && !practice;
});
const practiceGauge = keepPracticeGauge(this.guiState.practiceGauge, ruleset);
if (practiceGauge !== this.guiState.practiceGauge) {
this.guiState.practiceGauge = practiceGauge;
this.setPlayOptions({ practiceGauge });
}
if (this.practiceGaugeController) {
this.practiceGaugeController.options = practiceGaugeItems(ruleset, this.guiState.practiceGauge);
this.practiceGaugeController.refresh();
}
if (this.practiceGaugeCategoryController)
this.practiceGaugeCategoryController.hidden =
!practice || practiceGaugeSource(this.guiState.practiceGauge, ruleset) !== 'beatoraja';
for (const controller of this.practiceJudgeRankAndTotalControllers)
controller.hidden = !practice || !practiceReadsJudgeRankAndTotal(ruleset);
if (!beatoraja && this.guiState.customJudge) {
this.guiState.customJudge = false;
this.setPlayOptions({ customJudge: false });
}
if (this.customJudgeController) this.customJudgeController.hidden = !beatoraja;
// GAMBOL is part of LR2's judge rules.
if (ruleset !== 'lr2' && this.guiState.lr2Gambol !== 0) {
this.guiState.lr2Gambol = 0;
this.setPlayOptions({ lr2Gambol: 0 });
}
if (this.lr2GambolController) this.lr2GambolController.hidden = ruleset !== 'lr2';
// The rates belong to beatoraja's rules; under them they stay in place, disabled while CUSTOM JUDGE is off.
for (const controller of this.customJudgeRateControllers) {
controller.hidden = !beatoraja;
controller.unavailable = !this.guiState.customJudge;
}
if (this.longNoteRateController)
this.longNoteRateController.unavailable = !this.guiState.longNoteModifier.startsWith('ADD_');
// Every ruleset seeds its lane randoms (#933); only the PMS playable randomizer ignores its seed, as in the source.
for (const side of ['1P', '2P'] as const) {
const controller = side === '1P' ? this.randomSeed1PController : this.randomSeed2PController;
if (controller) controller.hidden = this.guiState[`random${side}`] === 'RANDOM_PLAYABLE';
}
// Gauge auto-shift is offered under every ruleset, along its own gauge ladder (#933). LR2 has no ASSIST EASY, so
// its lowest auto-shift gauge starts at EASY.
const bottomChoices = bottomShiftableGaugeItems(ruleset);
if (!bottomChoices.some((item) => item.value === this.guiState.bottomShiftableGauge)) {
this.guiState.bottomShiftableGauge = bottomChoices[0]!.value;
this.setPlayOptions({ bottomShiftableGauge: this.guiState.bottomShiftableGauge });
}
if (this.bottomShiftableGaugeController) {
this.bottomShiftableGaugeController.options = bottomChoices;
this.bottomShiftableGaugeController.refresh();
}
if (this.scrollSectionController) this.scrollSectionController.unavailable = this.guiState.scrollModifier !== 'ADD';
if (this.scrollRateController) this.scrollRateController.unavailable = this.guiState.scrollModifier !== 'ADD';
if (!beatoraja && this.guiState.judgeAlgorithm !== 'combo') {
this.guiState.judgeAlgorithm = 'combo';
this.setPlayOptions({ judgeAlgorithm: 'combo' });
}
if (this.judgeAlgorithmController) {
this.judgeAlgorithmController.options = beatoraja
? paneOptions({ Combo: 'combo' as const, Duration: 'duration' as const, Lowest: 'lowest' as const })
: paneOptions({ 'Source default': 'combo' as const });
this.judgeAlgorithmController.refresh();
}
// Every lane option is offered under every ruleset, grouped by source; S-RANDOM and CONVERGE once per source, and
// RANDOM once for all (ADR 0019).
for (const side of ['1P', '2P'] as const) {
const items = laneOptionItems(ruleset, side === '1P' && isDuplicatedBattleChoice(this.guiState.battleMode));
const key = `random${side}` as const;
const mode = this.keepChoice(
this.guiState[key],
items.map((item) => item.value),
);
if (mode !== this.guiState[key]) {
this.guiState[key] = mode;
this.setPlayOptions({ [key]: mode });
}
const controllers =
side === '1P' ? [this.random1PController, this.quickRandom1PController] : [this.random2PController];
for (const controller of controllers) {
if (!controller) continue;
controller.options = items;
controller.refresh();
}
}
// The judge ruleset's own gauges, then the other sources' as qualified picks (ADR 0019, #1171). A qualified pick
// survives a ruleset change; a bare one the new ruleset does not offer falls back to GROOVE (keepGaugePick).
const gauge = keepGaugePick(this.guiState.gauge, ruleset);
if (gauge !== this.guiState.gauge) {
this.guiState.gauge = gauge;
this.setPlayOptions({ gauge1P: gauge });
}
const gauge2P = keepGaugePick(this.guiState.gauge2P, ruleset);
if (gauge2P !== this.guiState.gauge2P) {
this.guiState.gauge2P = gauge2P;
this.setPlayOptions({ gauge2P });
}
const gauges = gaugeItems(ruleset, [gauge, gauge2P]);
for (const controller of [this.gaugeController, this.gauge2PController, this.quickGaugeController]) {
if (!controller) continue;
controller.options = gauges;
controller.refresh();
}
}
public refreshPlayOptionControllers(): void {
for (const controller of this.playOptionControllers) {
controller.refresh?.();
}
this.quickOptionsPanel?.refresh();
this.scheduleSettingsSave();
}
}
|