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 | 199x 199x 199x 199x 199x 199x 199x 199x 199x 327x 18x 17x 17x 275x 3x 327x 199x 2724x 2864x 716x 438x 238x 238x 23x 23x 402x 199x 199x 199x 199x 120x 29x 28x 28x 199x 14x 13x 199x 5x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 7x 6x 7x 7x 6x 10509x 10507x 10272x 10131x 10018x 309x 9709x 9706x 7x 9699x 9699x 3049x 3049x 310x 22x 19x 19x 19x 19x 4x 19x 23x 23x 22x 27x 46x 40x 46x 199x 23x 199x 337x 337x 38418x 20973x 20973x 723x 723x 337x 1x 1x 336x 2x 2x 2x 334x 1x 1x 337x | import { clampScoreTargetRate, DEFAULT_SCORE_TARGET_RATE, SCORE_TARGET_IDS } from './score-target.ts';
import { clampExtraNoteDepth, isOnePlayerBattleMode } from '@be-music/player-engine/lanes';
import { clampScrollSection, clampScrollRate } from '@be-music/player-engine/lanes';
import { clampFloatingHiSpeed } from './floating-hi-speed.ts';
import { clampLongNoteRate, clampHRandomThresholdBPM, parseLaneRandomSeed } from '@be-music/player-engine/lanes';
import { resolveConstantVisibility } from './constant-visibility.ts';
import { clampJudgeTimingMs } from './judge-timing.ts';
import { JUDGE_TIMING_AUTO_ADJUST_MODES } from '@be-music/player-engine/display';
import { clamp } from '@be-music/shared-utils/core';
import {
GAUGE_AUTO_SHIFTS,
LR2_GAUGE_TYPES,
PRACTICE_GAUGE_TYPES,
canonicalOptionValue,
clampCustomJudgeRate,
gaugePickType,
isGaugePick,
isPracticeGaugePick,
resolveGaugeTypes,
splitGaugePick,
type GaugePick,
isQualifiedOptionName,
splitOptionSource,
type RulesetId,
} from '@be-music/player-engine/ruleset';
import type { BrowseSort, DifficultyFilter, KeysFilter } from '../browse/list-options.ts';
import { DEFAULT_HISPEED, snapHiSpeed, snapClassicHiSpeed } from './hi-speed.ts';
import type {
BGAMode,
BGASize,
HiddenSuddenMode,
HSFix,
PlayOptionChoices,
PlayOptions,
RandomMode,
} from './options.ts';
/** The lane cover height a play starts with: a quarter of the lane. */
export const SHUTTER_DEFAULT = 0.25;
/**
* Cycle order for {@link PlayOptions.bga}. Matches the LR2 default-skin cell order on the `#SRC_BUTTON,type=72` sprite —
* `divx*divy` produces 3 cells (`OFF` / `ON` / `AUTOPLAY ONLY`) and clicks advance through them in this order.
*/
export const BGA_CYCLE: readonly BGAMode[] = ['OFF', 'ON', 'AUTOPLAY_ONLY'];
/** Cycle order for {@link PlayOptions.bgaSize}. LR2 button cell order on `#SRC_BUTTON,type=73`: NORMAL, EXTEND. */
export const BGA_SIZE_CYCLE: readonly BGASize[] = ['NORMAL', 'EXTEND'];
/**
* Cycle order for {@link PlayOptions.difficultyFilter}. Matches the LR2 `#SRC_BUTTON,type=10` cell order (off / easy /
* normal / hard / expert / insane).
*/
export const DIFFICULTY_FILTER_CYCLE: readonly DifficultyFilter[] = [
'ALL',
'BEGINNER',
'NORMAL',
'HYPER',
'ANOTHER',
'INSANE',
];
/**
* Cycle order for {@link PlayOptions.keysFilter}. Matches the LR2 `#SRC_BUTTON,type=11` cell order (off / 5keys / 7keys
* / 10keys / 14keys / 9keys).
*/
export const KEYS_FILTER_CYCLE: readonly KeysFilter[] = ['ALL', 'KEYS_5', 'KEYS_7', 'KEYS_10', 'KEYS_14', 'KEYS_9'];
/** Cycle order for {@link PlayOptions.sort}. LR2 button cells 0 / 1 / 2 / 3 = off / level / title / clear. */
export const SORT_CYCLE: readonly BrowseSort[] = ['OFF', 'LEVEL', 'TITLE', 'CLEAR'];
/**
* Cycle order for {@link PlayOptions.hsFix}. LR2 button cells 0..4 on `#SRC_BUTTON,type=55`: off / maxbpm / minbpm /
* average / constant.
*/
export const HS_FIX_CYCLE: readonly HSFix[] = ['OFF', 'MAXBPM', 'MINBPM', 'AVERAGE', 'CONSTANT'];
/**
* Cycle order for {@link PlayOptions.hiddenSudden1P} / `hiddenSudden2P`. LR2 button cells 0..3 on `#SRC_BUTTON,type=50`
* (1P) and `type=51` (2P): off / hidden / sudden / hid+sud.
*/
export const HIDDEN_SUDDEN_CYCLE: readonly HiddenSuddenMode[] = ['OFF', 'HIDDEN', 'SUDDEN', 'HID+SUD'];
/** Cycle for boolean OFF/ON LR2 buttons (e.g. autoscratch). */
export const BOOLEAN_CYCLE: readonly boolean[] = [false, true];
/**
* Source display spelling, without changing the recorded gauge identifier. A source-qualified pick reads as its gauge
* type (`lr2:P-ATTACK` as P.ATTACK), as ADR 0019 has a skin label it.
*/
export function formatGaugeLabel(pick: string | undefined): string | undefined {
switch (pick) {
case 'P-ATTACK':
return 'P.ATTACK';
case 'G-ATTACK':
return 'G.ATTACK';
case 'DEATH-CORRECTED':
return 'DEATH corrected';
}
// Only a source-qualified pick needs splitting; a bare one reads as it is.
if (pick === undefined || !pick.includes(':')) return pick;
const type = splitGaugePick(pick)?.type;
return type === undefined ? pick : formatGaugeLabel(type);
}
/**
* LR2's own lane options, in its RANDOM button order: cells 0..5 on `#SRC_BUTTON,type=42 / 43` (OpenLR2 `random` 0-5):
* off / mirror / random / s-random / scatter / converge. An LR2 button steps only these, LR2's own S-RANDOM and CONVERGE
* (ADR 0019); its label reads the bare name of any value. Every source's choices are in resolveRandomModes.
*/
export const RANDOM_CYCLE: readonly RandomMode[] = [
'OFF',
'MIRROR',
'RANDOM',
'lr2:S-RANDOM',
'SCATTER',
'lr2:CONVERGE',
];
/** The sources of each colliding lane option, the judge ruleset's own first. */
function sourcesFirst<Name extends 'S-RANDOM' | 'CONVERGE'>(
name: Name,
sources: readonly RulesetId[],
ruleset: RulesetId,
): RandomMode[] {
const ordered = sources.includes(ruleset) ? [ruleset, ...sources.filter((source) => source !== ruleset)] : sources;
return ordered.map((source) => `${source}:${name}` as RandomMode);
}
/**
* The lane options offered under `ruleset`; LR2's sprite cycle stays separate. Every lane option is offered under every
* ruleset and runs its own source's algorithm (#774). RANDOM is one option: every source shuffles the keys alike. S-RANDOM
* and CONVERGE name a different algorithm in LR2 and beatoraja, so they are offered once per source, qualified
* (`lr2:S-RANDOM`, which AC's matches, and `beatoraja:S-RANDOM`), with the judge ruleset's own first (ADR 0019). `duplicatedBattle1P` is the 1P side of a chart
* copied onto both sides (BATTLE, BATTLE AS, D-BATTLE), which also takes SYNCHRONIZE RANDOM and SYMMETRY RANDOM.
*/
export function resolveRandomModes(ruleset: RulesetId, duplicatedBattle1P = false): readonly RandomMode[] {
return [
'OFF',
'MIRROR',
'RANDOM',
'R-RANDOM',
...sourcesFirst('S-RANDOM', ['lr2', 'beatoraja'], ruleset),
'S-RANDOM-CORRECTED',
'SPIRAL',
'H-RANDOM',
'ALL-SCR',
'RANDOM-EX',
'S-RANDOM-EX',
'RANDOM_PLAYABLE',
'S_RANDOM_PLAYABLE',
'SCATTER',
'SCATTER-CORRECTED',
...sourcesFirst('CONVERGE', ['lr2', 'beatoraja'], ruleset),
'CONVERGE-CORRECTED',
...(duplicatedBattle1P ? (['SYNCHRONIZE-RANDOM', 'SYMMETRY-RANDOM'] as const) : []),
];
}
/**
* Whether `mode` is one of {@link resolveRandomModes}'s choices, a bare colliding name (S-RANDOM, CONVERGE) that stored
* settings and replays from before ADR 0019 hold, read as the judge ruleset's own, or a value since merged into one
* (`lr2:RANDOM` is RANDOM, `____:S-RANDOM` is `lr2:S-RANDOM`; `canonicalOptionValue` reads it).
*/
export function isRandomModeChoice(mode: unknown, duplicatedBattle1P = false): mode is RandomMode {
if (typeof mode !== 'string') return false;
const current = canonicalOptionValue(mode);
if (resolveRandomModes('lr2', duplicatedBattle1P).includes(current as RandomMode)) return true;
const parts = splitOptionSource(current);
return parts.source === undefined && isQualifiedOptionName(parts.name) && parts.name !== 'BATTLE';
}
/** The battle modes that copy one SP chart onto both sides, whose 1P side takes the battle arrangements. */
export function isDuplicatedBattleChoice(mode: PlayOptions['battleMode'] | undefined): boolean {
return isOnePlayerBattleMode(mode) || mode === 'BATTLE-AS' || mode === 'D-BATTLE';
}
/** The play options a player starts with. */
export const DEFAULT_PLAY_OPTIONS: Readonly<PlayOptions> = {
hiSpeed: DEFAULT_HISPEED,
classicHiSpeed: false,
floatingHiSpeed: false,
fixedDisplayArea: false,
normalHiSpeedLevel: 0,
judgeTimingMs: 0,
visualConstant: false,
noteDurationMs: 500,
constantFadeMs: 100,
bpmGuide: false,
bpmChangeWarning: false,
guideSE: false,
windowHold: false,
judgeCounts: true,
judgeDetailSplit: false,
judgeDetail: 'OFF',
scoreTargetRate: DEFAULT_SCORE_TARGET_RATE,
judgePosition: 0,
judgeDisplay: 'SKIN',
laneBrightness: 100,
scoreTarget: 'RATE_AAA',
markProcessedNotes: false,
showJudgeArea: false,
lr2AddMines: 0,
lr2AddLongNotes: 0,
lr2Loudness: 0,
lr2AddNotes: 0,
lr2Gambol: 0,
lr2SideJump: 0,
lr2SpiralEffect: 0,
lr2Wave: 0,
lr2SinCurve: 0,
lr2Nabeatsu: 0,
lr2Heartbeat: 0,
lr2Char: 0,
lr2SuperLoop: 0,
lr2Tornado: 0,
lr2Earthquake: 0,
lr2Acceleration: 'OFF',
autoScratchNotes: 'SHOW',
judgeTimingAutoAdjust: 'OFF',
autoPlay: false,
bga: 'ON',
// BGA renders at LR2's `#DST_BGA,...,30` rect (NORMAL) at `'NORMAL'` — a 256×256 window squeezed in beside the lane
// chrome. `'EXTEND'` uses the larger `op 31` rect (392×392) which fills more of the playfield and is the default LR2
// experience players expect.
bgaSize: 'EXTEND',
// Score graph (the per-judge prediction line gated on op 39) on by default: ship with the richer LR2 chrome visible
// up-front rather than hidden behind a panel toggle.
scoreGraph: true,
difficultyFilter: 'ALL',
keysFilter: 'ALL',
sort: 'OFF',
hsFix: 'OFF',
displayAreaInfo: 'OFF',
hiddenSudden1P: 'OFF',
hiddenSudden2P: 'OFF',
shutter: SHUTTER_DEFAULT,
laneCover: false,
lift1P: 0.1,
lift2P: 0.1,
liftOn1P: false,
liftOn2P: false,
judgeAlgorithm: 'combo',
longNoteModifier: 'OFF',
longNoteRate: 1,
extraNoteDepth: 0,
extraNoteScratch: false,
sevenToNinePattern: 0,
sevenToNineType: 0,
battleMode: 'OFF',
dBattleScratch: false,
mRan1P: false,
mRan2P: false,
longNoteMode: 'LN',
customJudge: false,
practice: false,
practiceGauge: 'NORMAL',
practiceGaugeCategory: 'MODE',
practiceStartGauge: 20,
practiceJudgeRank: 0,
practiceTotal: 0,
practiceRestBefore: 1,
practiceRestAfter: 1,
practiceCarriedLongNotes: true,
customJudgeKeyPerfectGreat: 400,
customJudgeKeyGreat: 400,
customJudgeKeyGood: 100,
customJudgeScratchPerfectGreat: 400,
customJudgeScratchGreat: 400,
customJudgeScratchGood: 100,
customJudgeLongNoteMargin: 100,
lr2ExtraMode: false,
lr2ExtraLevel: 0,
mineModifier: 'OFF',
crazyJudge: 'OFF',
crazyHellJudge: false,
crazyAddMine: false,
crazyNotes: 'OFF',
scrollModifier: 'OFF',
scrollSection: 4,
scrollRate: 0.5,
gaugeAutoShift: 'NONE',
bmsonTotalMode: 'beatoraja',
bottomShiftableGauge: 'ASSIST-EASY',
autoScratch1P: false,
autoScratch2P: false,
dpFlip: false,
random1P: 'OFF',
hRandomThresholdBPM: 120,
randomSeed1P: '-1',
randomSeed2P: '-1',
randomFixedLane1P: 0,
randomFixedLane2P: 0,
lr2RandomScratch1P: false,
lr2RandomScratch2P: false,
random2P: 'OFF',
gauge1P: 'GROOVE',
gauge2P: 'GROOVE',
};
/**
* Choices of every enum / on-off play option, in their LR2 button cycle order: what a skin can pick from. `hiSpeed` and
* `shutter` are numbers, without a fixed set of choices.
*/
/** LR2's mania options run from OFF (0) to 100 in steps of 10. */
const LR2_MANIA_LEVELS = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100] as const;
/** The lane brightness steps, in percent: 100 leaves the lanes as the skin draws them. */
const LANE_BRIGHTNESS_LEVELS = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100] as const;
export const PLAY_OPTION_CHOICES: PlayOptionChoices = {
autoPlay: BOOLEAN_CYCLE,
bga: BGA_CYCLE,
bgaSize: BGA_SIZE_CYCLE,
scoreGraph: BOOLEAN_CYCLE,
difficultyFilter: DIFFICULTY_FILTER_CYCLE,
keysFilter: KEYS_FILTER_CYCLE,
sort: SORT_CYCLE,
hsFix: [...HS_FIX_CYCLE, 'STARTBPM'],
displayAreaInfo: ['OFF', 'ON', 'SUDDEN_ONLY', 'HIDDEN_LIFT_ONLY'],
hiddenSudden1P: HIDDEN_SUDDEN_CYCLE,
hiddenSudden2P: HIDDEN_SUDDEN_CYCLE,
laneCover: BOOLEAN_CYCLE,
liftOn1P: BOOLEAN_CYCLE,
liftOn2P: BOOLEAN_CYCLE,
judgeAlgorithm: ['combo', 'duration', 'lowest'],
longNoteModifier: ['OFF', 'LEGACY', 'REMOVE', 'ADD_LN', 'ADD_CN', 'ADD_HCN', 'ADD_ALL'],
mineModifier: ['OFF', 'REMOVE', 'ADD_RANDOM', 'ADD_NEAR', 'ADD_BLANK'],
crazyJudge: ['OFF', 'GOOD2BAD', 'GREAT2BAD'],
crazyHellJudge: BOOLEAN_CYCLE,
crazyAddMine: BOOLEAN_CYCLE,
crazyNotes: ['OFF', 'DOUBLE', 'COPY', 'DBLCOPY'],
scrollModifier: ['OFF', 'REMOVE', 'ADD', 'SOFTLANDING-1', 'SOFTLANDING-2'],
gaugeAutoShift: GAUGE_AUTO_SHIFTS,
bmsonTotalMode: ['beatoraja', 'spec'],
bottomShiftableGauge: ['ASSIST-EASY', 'EASY', 'GROOVE'],
classicHiSpeed: BOOLEAN_CYCLE,
floatingHiSpeed: BOOLEAN_CYCLE,
fixedDisplayArea: BOOLEAN_CYCLE,
bpmGuide: BOOLEAN_CYCLE,
bpmChangeWarning: BOOLEAN_CYCLE,
guideSE: BOOLEAN_CYCLE,
windowHold: BOOLEAN_CYCLE,
judgeCounts: BOOLEAN_CYCLE,
judgeDetailSplit: BOOLEAN_CYCLE,
judgeDetail: ['OFF', 'FAST_SLOW', 'MS'],
judgeDisplay: ['SKIN', 'OFF'],
laneBrightness: LANE_BRIGHTNESS_LEVELS,
scoreTarget: SCORE_TARGET_IDS,
markProcessedNotes: BOOLEAN_CYCLE,
showJudgeArea: BOOLEAN_CYCLE,
lr2AddMines: LR2_MANIA_LEVELS,
lr2AddLongNotes: LR2_MANIA_LEVELS,
lr2Loudness: LR2_MANIA_LEVELS,
lr2AddNotes: LR2_MANIA_LEVELS,
lr2Gambol: [0, 1, 2],
lr2SideJump: LR2_MANIA_LEVELS,
lr2SpiralEffect: LR2_MANIA_LEVELS,
lr2Wave: LR2_MANIA_LEVELS,
lr2SinCurve: LR2_MANIA_LEVELS,
lr2Nabeatsu: LR2_MANIA_LEVELS,
lr2Heartbeat: LR2_MANIA_LEVELS,
lr2Char: LR2_MANIA_LEVELS,
lr2SuperLoop: LR2_MANIA_LEVELS,
lr2Tornado: LR2_MANIA_LEVELS,
lr2Earthquake: LR2_MANIA_LEVELS,
lr2Acceleration: ['OFF', 'ACCELERATION', 'DECELERATION', 'RANDOM'],
autoScratchNotes: ['SHOW', 'HIDE'],
judgeTimingAutoAdjust: JUDGE_TIMING_AUTO_ADJUST_MODES,
visualConstant: BOOLEAN_CYCLE,
extraNoteScratch: BOOLEAN_CYCLE,
sevenToNinePattern: [0, 1, 2, 3, 4, 5, 6],
sevenToNineType: [0, 1, 2],
battleMode: [
'OFF',
'AUTO',
'COUPLE',
'SP-TO-DP',
'SP-TO-DP-CORRECTED',
'D-BATTLE',
'beatoraja:BATTLE',
'____:BATTLE',
'BATTLE-AS',
'TWO-PLAYER',
],
dBattleScratch: BOOLEAN_CYCLE,
mRan1P: BOOLEAN_CYCLE,
mRan2P: BOOLEAN_CYCLE,
longNoteMode: ['LN', 'CN', 'HCN'],
customJudge: BOOLEAN_CYCLE,
practice: BOOLEAN_CYCLE,
// Every ruleset's PRACTICE gauges; a menu offers the judge ruleset's own (`resolvePracticeGaugeTypes`).
practiceGauge: PRACTICE_GAUGE_TYPES,
practiceGaugeCategory: ['MODE', 'FIVEKEYS', 'SEVENKEYS', 'PMS', 'KEYBOARD', 'LR2'],
practiceCarriedLongNotes: BOOLEAN_CYCLE,
lr2ExtraMode: BOOLEAN_CYCLE,
lr2ExtraLevel: [0, 1, 2],
autoScratch1P: BOOLEAN_CYCLE,
autoScratch2P: BOOLEAN_CYCLE,
dpFlip: BOOLEAN_CYCLE,
lr2RandomScratch1P: BOOLEAN_CYCLE,
lr2RandomScratch2P: BOOLEAN_CYCLE,
random1P: resolveRandomModes('lr2', true),
random2P: resolveRandomModes('lr2'),
gauge1P: LR2_GAUGE_TYPES,
gauge2P: LR2_GAUGE_TYPES,
};
/**
* Snaps a hi-speed to the 1/1000 grid and clamps it to the hi-speed range (`snapHiSpeed`), falling back to the default
* for non-finite input.
*/
export function clampHiSpeed(value: number): number {
return snapHiSpeed(value) ?? DEFAULT_PLAY_OPTIONS.hiSpeed;
}
/**
* Clamps a lane cover height to [0, 1] and snaps it to the 1/100 grid, so repeated +0.05 nudges land on round values
* rather than drifting through float rounding. Non-finite input falls back to {@link SHUTTER_DEFAULT}.
*/
export function clampShutter(value: number): number {
if (!Number.isFinite(value)) return SHUTTER_DEFAULT;
const snapped = Math.round(value * 100) / 100;
return clamp(snapped, 0, 1);
}
/** How far the judgment position goes either way, in percent of the lanes' height. */
export const JUDGE_POSITION_LIMIT = 30;
/** A judgment position as a whole percentage within ±{@link JUDGE_POSITION_LIMIT}; 0 for a value that is not finite. */
export function clampJudgePosition(value: number): number {
if (!Number.isFinite(value)) return 0;
return clamp(Math.round(value), -JUDGE_POSITION_LIMIT, JUDGE_POSITION_LIMIT);
}
/** Numeric play options, each with the clamp applied to a value set for it. */
const NUMERIC_PLAY_OPTION_CLAMPS: { readonly [K in keyof PlayOptions]?: (value: number) => number } = {
hRandomThresholdBPM: clampHRandomThresholdBPM,
judgePosition: clampJudgePosition,
scoreTargetRate: clampScoreTargetRate,
longNoteRate: clampLongNoteRate,
practiceStartGauge: (value) => clamp(Math.trunc(value), 1, 120),
practiceJudgeRank: (value) => (value <= 0 ? 0 : clamp(Math.trunc(value), 1, 400)),
practiceTotal: (value) => (value <= 0 ? 0 : clamp(Math.trunc(value), 10, 5000)),
practiceRestBefore: (value) => clamp(Math.trunc(value), 0, 8),
practiceRestAfter: (value) => clamp(Math.trunc(value), 0, 8),
customJudgeKeyPerfectGreat: (value) => clampCustomJudgeRate('keyPerfectGreat', value),
customJudgeKeyGreat: (value) => clampCustomJudgeRate('keyGreat', value),
customJudgeKeyGood: (value) => clampCustomJudgeRate('keyGood', value),
customJudgeScratchPerfectGreat: (value) => clampCustomJudgeRate('scratchPerfectGreat', value),
customJudgeScratchGreat: (value) => clampCustomJudgeRate('scratchGreat', value),
customJudgeScratchGood: (value) => clampCustomJudgeRate('scratchGood', value),
customJudgeLongNoteMargin: (value) => clampCustomJudgeRate('longNoteMargin', value),
extraNoteDepth: clampExtraNoteDepth,
scrollSection: clampScrollSection,
scrollRate: clampScrollRate,
randomFixedLane1P: (value) => (Number.isFinite(value) ? Math.max(0, Math.min(9, Math.trunc(value))) : 0),
randomFixedLane2P: (value) => (Number.isFinite(value) ? Math.max(0, Math.min(9, Math.trunc(value))) : 0),
hiSpeed: clampHiSpeed,
judgeTimingMs: clampJudgeTimingMs,
noteDurationMs: (value) => resolveConstantVisibility({ durationMs: value }).durationMs,
constantFadeMs: (value) => resolveConstantVisibility({ fadeMs: value }).fadeMs,
normalHiSpeedLevel: (value) => Math.max(0, Math.min(20, Math.round(value))),
shutter: clampShutter,
lift1P: clampShutter,
lift2P: clampShutter,
};
/**
* Validates a value set for a play option from untyped input (a Be-Music Skin's `setPlayOption`, stored settings).
* Returns the value to store — clamped for the numeric options (`hiSpeed`, `shutter`) — or `undefined` when the change
* must be ignored: an unknown key, a value outside the option's choices, or a non-finite / non-numeric value for a
* numeric option.
*/
export function resolvePlayOptionValue<K extends keyof PlayOptions>(
key: K,
value: unknown,
): PlayOptions[K] | undefined {
if (!Object.hasOwn(DEFAULT_PLAY_OPTIONS, key)) return undefined;
if (key === 'randomSeed1P' || key === 'randomSeed2P') return parseLaneRandomSeed(value) as PlayOptions[K] | undefined;
// A gauge is a bare type or one qualified with a source that defines it (`lr2:HARD`; `lr2:EX-HARD` is refused).
if (key === 'gauge1P' || key === 'gauge2P') return isGaugePick(value) ? (value as PlayOptions[K]) : undefined;
// PRACTICE's GAUGE TYPE may name another source's gauge (`beatoraja:ASSIST-EASY`), as a gauge pick does.
if (key === 'practiceGauge') return isPracticeGaugePick(value) ? (value as PlayOptions[K]) : undefined;
// A bare colliding name from before ADR 0019 stays valid: it is the judge ruleset's own. A merged value reads as the
// option it was merged into.
if (key === 'random1P' || key === 'random2P')
return isRandomModeChoice(value, true) ? (canonicalOptionValue(value) as PlayOptions[K]) : undefined;
if (key === 'battleMode' && value === 'BATTLE') return value as PlayOptions[K];
// Settings and replays from before the modes store beatoraja's switch as a boolean.
if (key === 'judgeTimingAutoAdjust' && typeof value === 'boolean')
return (value ? 'BEATORAJA' : 'OFF') as PlayOptions[K];
const choices = PLAY_OPTION_CHOICES[key] as readonly unknown[] | undefined;
if (choices) return choices.includes(value) ? (value as PlayOptions[K]) : undefined;
const clamp = NUMERIC_PLAY_OPTION_CLAMPS[key];
if (!clamp || typeof value !== 'number' || !Number.isFinite(value)) return undefined;
return clamp(value) as PlayOptions[K];
}
/**
* The choice `step` places after `current` in `key`'s choices, wrapping around either end — what a skin's
* `cyclePlayOption(key, step)` moves to. Any negative `step` goes back one and anything else forward one. A value
* outside the choices lands on the first choice; options without a fixed set of choices (`hiSpeed`, `shutter`, or an
* unknown key) return `undefined`.
*/
export function cyclePlayOptionValue<K extends keyof PlayOptions>(
key: K,
current: PlayOptions[K],
step: number = 1,
): PlayOptions[K] | undefined {
if (!Object.hasOwn(PLAY_OPTION_CHOICES, key)) return undefined;
const choices = PLAY_OPTION_CHOICES[key] as readonly PlayOptions[K][] | undefined;
Iif (!choices || choices.length === 0) return undefined;
let index = choices.indexOf(current);
// A gauge button steps LR2's own cells: a qualified pick steps on from its gauge type, to a bare gauge.
if (index < 0 && (key === 'gauge1P' || key === 'gauge2P'))
index = choices.indexOf(gaugePickType(current as GaugePick) as PlayOptions[K]);
return stepChoice(choices, index, step);
}
/**
* The gauge pick to keep when the judge ruleset becomes `ruleset` (ADR 0019, #1171). A source-qualified pick stays as it
* is: it names its source's gauge, which no ruleset change touches. A bare pick is the judge ruleset's own gauge of that
* name, so it stays while `ruleset` offers it (`resolveGaugeTypes`) and falls back to GROOVE otherwise, as LR2's
* P.ATTACK does under beatoraja.
*/
export function keepGaugePick(pick: GaugePick, ruleset: RulesetId): GaugePick {
const parts = splitGaugePick(pick);
if (parts === undefined) return 'GROOVE';
return parts.source !== undefined || resolveGaugeTypes(ruleset).includes(parts.type) ? pick : 'GROOVE';
}
/**
* The value after `current` in `choices` (before it for a negative `step`), wrapping around either end; the first
* choice when `current` is not one of them. What a cycling button (LR2's `#SRC_BUTTON` types 40, 42, 50, 72, 73, …)
* moves to on a click.
*/
export function nextChoice<T>(choices: readonly T[], current: T, step: number = 1): T {
return stepChoice(choices, choices.indexOf(current), step);
}
/** The choice one `step` direction from `index`, wrapping around either end; the first when `index` is -1. */
function stepChoice<T>(choices: readonly T[], index: number, step: number): T {
if (index < 0) return choices[0]!;
const delta = step < 0 ? -1 : 1;
return choices[(index + delta + choices.length) % choices.length]!;
}
/** The play options that filter or reorder the bar list: changing one changes the list ({@link BrowseListOptions}). */
const LIST_PLAY_OPTIONS: ReadonlySet<keyof PlayOptions> = new Set(['difficultyFilter', 'keysFilter', 'sort']);
/** Whether changing play option `key` changes the bar list (its sort or a filter). */
export function isListPlayOption(key: keyof PlayOptions): boolean {
return LIST_PLAY_OPTIONS.has(key);
}
/** Every play option's key, listed once: the options resolve on every scene and every settings change. */
const PLAY_OPTION_KEYS = Object.keys(DEFAULT_PLAY_OPTIONS) as readonly (keyof PlayOptions)[];
/**
* Play options as stored by a host, made whole and valid: each field of `stored` that {@link resolvePlayOptionValue}
* accepts (clamped for the numeric ones) over {@link DEFAULT_PLAY_OPTIONS}; anything else is dropped.
*/
export function resolvePlayOptions(stored: Readonly<Partial<Record<keyof PlayOptions, unknown>>> = {}): PlayOptions {
const options: PlayOptions = { ...DEFAULT_PLAY_OPTIONS };
for (const key of PLAY_OPTION_KEYS) {
if (!Object.hasOwn(stored, key)) continue;
const raw = stored[key];
// A default is valid as it stands and already in place: most stored options are their default, so skip them.
if (raw === options[key]) continue;
const value = resolvePlayOptionValue(key, raw);
if (value !== undefined) (options as Record<keyof PlayOptions, unknown>)[key] = value;
}
if (options.floatingHiSpeed) {
options.hsFix = 'OFF';
options.hiSpeed =
clampFloatingHiSpeed(typeof stored.hiSpeed === 'number' ? stored.hiSpeed : options.hiSpeed) ?? options.hiSpeed;
} else if (options.classicHiSpeed) {
options.normalHiSpeedLevel = 0;
options.hsFix = 'OFF';
options.hiSpeed = snapClassicHiSpeed(options.hiSpeed)!;
} else if (options.normalHiSpeedLevel > 0) {
options.hsFix = 'OFF';
Iif (typeof stored.hiSpeed === 'number' && Number.isFinite(stored.hiSpeed) && stored.hiSpeed > 0)
options.hiSpeed = stored.hiSpeed;
}
return options;
}
|