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 | 42x 42x 6x 6x 6x 71x 71x 71x 2x 2x 2x 71x 71x 71x 71x 71x 71x 71x 5x 71x 8x 8x 8x 8x 8x 71x 39x 79x 50x 1x 1x 48x 48x 50x 4x 2x 1x 1x 14x 42x 9x 8x 1x 1x 1x 1x 2x 1x 1x 20x 20x 19x 18x 14x 13x 13x 10x 71x 71x 71x 71x 71x 20x 50x 4x 36x 42x 37x 35x 34x 33x 28x 28x 11x 9x 1x 2x 2x 1x 3x 11x 9x 8x 5x 1x 12x 11x 11x 12x 34x 9x 1x 42x 3x 3x 2x 2x 3x 7x 1x 2x 2x 2x 2x 2x 2x | import type { CourseDraft, LR2RandomMixSettings, NonstopConnection } from '@be-music/player-engine/course';
import type { ClearLamp } from '@be-music/player-engine/ruleset';
import {
resolveCourseView,
resolveLibraryChartDifficultyValue,
type CourseView,
type DifficultyFilter,
type LibraryChart,
type LibraryEntry,
type PlayOptions,
type PlaySide,
} from '@be-music/player-scene-model';
import { LR2_BUTTON, LR2_NUM, LR2_OP, LR2_SLIDER, LR2_TEXT, LR2_TIMER } from '../ids/index.ts';
import type { LR2BarBodyKind, LR2BarBodySource, LR2BarLevelKind } from '../skin.ts';
import {
lr2PlayLevel,
resolveLR2ChartFeatures,
resolveLR2ChartText,
resolveLR2DifficultyOp,
resolveLR2JudgeRankOp,
resolveLR2KeyModeOp,
} from './chart.ts';
import {
resolveLR2CourseConnectionText,
resolveLR2CourseDraftInfo,
resolveLR2CourseIRButtonState,
resolveLR2CourseIRText,
resolveLR2CourseMakerButtonState,
resolveLR2CourseMakerOps,
resolveLR2CourseMakerText,
resolveLR2RandomMixButtonState,
resolveLR2RandomMixText,
resolveLR2CourseNumber,
resolveLR2CourseOps,
resolveLR2CourseStageDifficultyOps,
resolveLR2CourseText,
} from './course.ts';
import {
LR2_DIFFICULTY_FILTER_BUTTONS,
resolveLR2OptionButton,
resolveLR2OptionNumber,
resolveLR2OptionSlider,
resolveLR2OptionText,
resolveLR2PlayOptionOps,
} from './options.ts';
import { resolveLR2LampOp } from './records.ts';
import { lr2TimerUpdate, type LR2Clock, type LR2SceneState, type LR2TimerUpdate } from './scene-state.ts';
/** The course being made on the select screen, when the player makes courses (LR2's course maker). */
export interface LR2CourseMakerInput {
/** The course being made; absent while none is. */
readonly draft?: CourseDraft;
/** The connection a new NONSTOP course gets (text 198, button 268). */
readonly defaultConnection: NonstopConnection;
/** What the course name (text 170) reads while the name being made is empty. */
readonly namePrompt?: string;
/** The RANDOM MIX settings (texts 190-196, buttons 260-266); absent from hosts without a RANDOM MIX bar. */
readonly randomMixSettings?: LR2RandomMixSettings;
}
/** What the LR2 select screen shows: the bar under the cursor, the player's options and records, the screen's state. */
export interface LR2SelectInput {
/** The bar under the cursor (a session reads it with `focusedEntry(library, browse)`); none on an empty list. */
readonly focused?: LibraryEntry;
/** The player's play options: the option ops, the option panel's labels, buttons and sliders. */
readonly options: PlayOptions;
/** The player's best record on the focused chart or course: its clear lamp (ops 100-105). */
readonly record?: { readonly lamp?: ClearLamp };
/** The option panels open (1-9): ops 21-29, or op 20 while none is. */
readonly openPanels?: Iterable<number>;
/** The skin's `#CUSTOMOPTION` choices: their ops (900-999). */
readonly customOps?: Iterable<number>;
/** Whether the focused chart's folder has a text (readme) file (ops 174 / 175). */
readonly readme?: boolean;
/** The focused chart's lowest and highest BPM over its tempo map (numbers 90 / 91). */
readonly bpmRange?: { readonly min: number; readonly max: number };
/** The search word shown (text 30). */
readonly searchText?: string;
/** The cursor's place in the list as it is drawn, 0..1 (slider 1): a sliding list lags the cursor. */
readonly listPosition?: number;
/** The course maker, when the player makes courses. */
readonly courseMaker?: LR2CourseMakerInput;
/** The time now (numbers 21-26). */
readonly clock?: LR2Clock;
/** The frame rate (number 20). */
readonly fps?: number;
}
/** The LR2 select screen's state: a {@link LR2SceneState} and the cell each button draws. */
export interface LR2SelectState extends LR2SceneState {
/** The cell a `#SRC_BUTTON` of this `type` draws (`LR2_BUTTON`); the caller clamps it to the button's cells. */
button(type: number): number | undefined;
}
/** Ops the select screen always lights: no AUTOPLAY, GHOST, internet ranking, EXTRA MODE, score saving or replay. */
const SELECT_BASE_OPS: readonly number[] = [
LR2_OP.AUTOPLAY_OFF,
LR2_OP.GHOST_OFF,
LR2_OP.OFFLINE,
LR2_OP.EXTRA_MODE_OFF,
LR2_OP.SCORE_SAVE_OFF,
LR2_OP.CLEAR_SAVE_OFF,
LR2_OP.LOADED,
LR2_OP.REPLAY_OFF,
];
/** The chart ops of a bar that is not a chart: nothing the chart ops report, an undefined 7-key chart, no lamp. */
const NO_CHART_OPS: readonly number[] = [
LR2_OP.NO_BGA,
LR2_OP.NO_LN,
LR2_OP.NO_TEXT,
LR2_OP.NO_BPM_CHANGE,
LR2_OP.NO_RANDOM,
LR2_OP.NO_STAGEFILE,
LR2_OP.NO_BANNER,
LR2_OP.NO_BACKBMP,
LR2_OP.NO_REPLAY,
LR2_OP.JUDGE_NORMAL,
LR2_OP.LAMP_NO_PLAY,
LR2_OP.DIFFICULTY_UNDEFINED,
LR2_OP.KEYS_7,
];
/** The chart ops of a focused chart: the bar, its key mode, features, judge rank, difficulty, images and lamp. */
function chartOps(chart: LibraryChart, readme: boolean, lamp: ClearLamp | undefined): number[] {
const features = resolveLR2ChartFeatures(chart.chart);
const metadata = chart.chart.metadata;
return [
LR2_OP.SONG_BAR,
LR2_OP.PLAYABLE_BAR,
resolveLR2KeyModeOp(chart),
features.bga ? LR2_OP.HAS_BGA : LR2_OP.NO_BGA,
features.longNote ? LR2_OP.HAS_LN : LR2_OP.NO_LN,
readme ? LR2_OP.HAS_TEXT : LR2_OP.NO_TEXT,
features.bpmChange ? LR2_OP.HAS_BPM_CHANGE : LR2_OP.NO_BPM_CHANGE,
features.random ? LR2_OP.HAS_RANDOM : LR2_OP.NO_RANDOM,
resolveLR2JudgeRankOp(metadata.rank),
resolveLR2DifficultyOp(resolveLibraryChartDifficultyValue(chart)),
metadata.stageFile ? LR2_OP.HAS_STAGEFILE : LR2_OP.NO_STAGEFILE,
metadata.banner ? LR2_OP.HAS_BANNER : LR2_OP.NO_BANNER,
metadata.backBMP ? LR2_OP.HAS_BACKBMP : LR2_OP.NO_BACKBMP,
LR2_OP.NO_REPLAY,
resolveLR2LampOp(lamp),
];
}
function selectOps(input: LR2SelectInput, chart: LibraryChart | undefined, course: CourseView | undefined): number[] {
const ops = [...SELECT_BASE_OPS];
// Op 20 while no option panel is open, 21-29 while panel 1-9 is.
let panelOpen = false;
for (const panel of input.openPanels ?? []) {
Iif (panel < 1 || panel > 9) continue;
ops.push(LR2_OP.PANEL1 + panel - 1);
panelOpen = true;
}
if (!panelOpen) ops.push(LR2_OP.NO_PANEL);
for (const op of input.customOps ?? []) ops.push(op);
ops.push(...resolveLR2PlayOptionOps(input.options));
ops.push(...(chart !== undefined ? chartOps(chart, input.readme === true, input.record?.lamp) : NO_CHART_OPS));
// A folder bar lights op 1 (OpenLR2 `GetOptionFlag_dst`: LR2's folder, level-folder and custom-folder bars).
if (input.focused?.kind === 'folder') ops.push(LR2_OP.FOLDER_BAR);
// Ops 700-745: the difficulty of the selected course's stages 1-5 (the `x0` ops on any other bar, as LR2 reads 0).
ops.push(...resolveLR2CourseStageDifficultyOps(course));
if (input.courseMaker !== undefined) {
ops.push(...resolveLR2CourseMakerOps(input.courseMaker.draft, course?.stages.length));
}
if (course !== undefined && input.focused?.kind === 'course') {
ops.push(LR2_OP.COURSE_BAR);
if (input.focused.course.playable) ops.push(LR2_OP.PLAYABLE_BAR);
// The course's best lamp (ops 100-105), from the player's record on it as LR2 keeps one per course.
const noPlay = ops.indexOf(LR2_OP.LAMP_NO_PLAY);
Eif (noPlay >= 0) ops.splice(noPlay, 1);
ops.push(resolveLR2LampOp(input.record?.lamp), ...resolveLR2CourseOps(course));
}
return ops;
}
/** LR2 texts 171-179 on a bar that is not a course: the connection slots read `DISABLE` (OpenLR2 L8400-L8405). */
function noCourseConnectionText(st: number): string | undefined {
return st >= LR2_TEXT.COURSE_CONNECTION1 && st <= LR2_TEXT.COURSE_CONNECTION9 ? 'DISABLE' : undefined;
}
/** The IR flag (`release`) of the course bar under the cursor; `undefined` on any other bar. */
function focusedCourseRelease(input: LR2SelectInput): boolean | undefined {
return input.focused?.kind === 'course' ? input.focused.course.definition.release : undefined;
}
function selectText(
st: number,
input: LR2SelectInput,
chart: LibraryChart | undefined,
course: CourseView | undefined,
): string | undefined {
switch (st) {
case LR2_TEXT.SEARCH_WORD:
return input.searchText ?? '';
case LR2_TEXT.RIVAL:
// No rival or internet ranking: LR2's "no target".
return 'NO TARGET';
case LR2_TEXT.PLAYER:
return 'PLAYER';
case LR2_TEXT.SKIN_NAME:
return 'LR2 SELECT';
case LR2_TEXT.SKIN_AUTHOR:
return '';
}
const maker = input.courseMaker;
// While a course is being made, its songs and name take the course texts (150-170) over from the selected bar.
const textCourse =
maker?.draft !== undefined ? resolveLR2CourseDraftInfo(maker.draft, maker.namePrompt ?? '') : course;
return (
(textCourse !== undefined ? resolveLR2CourseText(st, textCourse) : undefined) ??
(course !== undefined ? resolveLR2CourseConnectionText(st, course) : noCourseConnectionText(st)) ??
resolveLR2CourseIRText(st, focusedCourseRelease(input)) ??
(maker !== undefined ? resolveLR2CourseMakerText(st, maker.defaultConnection) : undefined) ??
(maker?.randomMixSettings !== undefined ? resolveLR2RandomMixText(st, maker.randomMixSettings) : undefined) ??
resolveLR2OptionText(st, input.options, chart !== undefined ? resolveLR2KeyModeOp(chart) : undefined) ??
(chart !== undefined ? resolveLR2ChartText(st, chart) : undefined)
);
}
function clockNumber(num: number, clock: LR2Clock | undefined): number | undefined {
switch (num) {
case LR2_NUM.YEAR:
return clock?.year;
case LR2_NUM.MONTH:
return clock?.month;
case LR2_NUM.DAY:
return clock?.day;
case LR2_NUM.HOUR:
return clock?.hour;
case LR2_NUM.MINUTE:
return clock?.minute;
case LR2_NUM.SECOND:
return clock?.second;
default:
return undefined;
}
}
/** The player's totals (30-41): no play history is kept yet, so each reads 0. */
function isPlayerTotal(num: number): boolean {
return num >= LR2_NUM.TOTAL_PLAY_COUNT && num <= LR2_NUM.TRIAL_LEVEL_PREVIOUS;
}
/** The best record's numbers (70-89) that need a score history, which is not kept yet: each reads 0. */
const BEST_RECORD_NUMBERS: ReadonlySet<number> = new Set([
LR2_NUM.BEST_SCORE,
LR2_NUM.BEST_EXSCORE,
LR2_NUM.BEST_RATE,
LR2_NUM.BEST_MAX_COMBO,
LR2_NUM.BEST_MIN_BP,
LR2_NUM.PLAY_COUNT,
LR2_NUM.CLEAR_COUNT,
LR2_NUM.FAIL_COUNT,
LR2_NUM.BEST_PERFECT,
LR2_NUM.BEST_GREAT,
LR2_NUM.BEST_GOOD,
LR2_NUM.BEST_BAD,
LR2_NUM.BEST_POOR,
LR2_NUM.BEST_PERFECT_RATE,
LR2_NUM.BEST_GREAT_RATE,
LR2_NUM.BEST_GOOD_RATE,
LR2_NUM.BEST_BAD_RATE,
LR2_NUM.BEST_POOR_RATE,
]);
function chartNumber(num: number, chart: LibraryChart, input: LR2SelectInput): number | undefined {
if (BEST_RECORD_NUMBERS.has(num)) return 0;
switch (num) {
case LR2_NUM.EXSCORE_MAX:
return chart.totalNotes * 2;
case LR2_NUM.TOTAL_NOTES:
return chart.totalNotes;
case LR2_NUM.MAX_BPM:
return input.bpmRange !== undefined ? Math.round(input.bpmRange.max) : undefined;
case LR2_NUM.MIN_BPM:
return input.bpmRange !== undefined ? Math.round(input.bpmRange.min) : undefined;
case LR2_NUM.FOLDER_LEVEL_BEGINNER:
case LR2_NUM.FOLDER_LEVEL_NORMAL:
case LR2_NUM.FOLDER_LEVEL_HYPER:
case LR2_NUM.FOLDER_LEVEL_ANOTHER:
case LR2_NUM.FOLDER_LEVEL_INSANE:
// No folder of a chart's difficulties yet: the chart's own level under its difficulty's number.
return resolveLibraryChartDifficultyValue(chart) === num - LR2_NUM.FOLDER_LEVEL_BEGINNER + 1
? lr2PlayLevel(chart)
: undefined;
case LR2_NUM.BPM:
// The chart is not playing: its start BPM.
return chart.bpm;
default:
// The internet ranking (92-94) and the rest: not bound.
return undefined;
}
}
function selectNumber(
num: number,
input: LR2SelectInput,
chart: LibraryChart | undefined,
course: CourseView | undefined,
): number | undefined {
const courseNumber = course !== undefined ? resolveLR2CourseNumber(num, course) : undefined;
if (courseNumber !== undefined) return courseNumber;
if (num === LR2_NUM.FPS) return input.fps;
if (num >= LR2_NUM.YEAR && num <= LR2_NUM.SECOND) return clockNumber(num, input.clock);
if (isPlayerTotal(num)) return 0;
const optionNumber = resolveLR2OptionNumber(num, input.options);
if (optionNumber !== undefined) return optionNumber;
return chart !== undefined ? chartNumber(num, chart, input) : undefined;
}
/**
* The LR2 select screen's state for the bar under the cursor: the select ops (the base ops, the option ops, the
* focused chart's ops, a course bar's course ops and stage difficulties, the course maker's ops, the open panels and
* the skin's custom options), the numbers (the clock, the options, the focused chart and course), the texts (the
* focused chart, the option panel, the course and the course being made, the search word) and the button cells and
* sliders.
*/
export function resolveLR2SelectState(input: LR2SelectInput): LR2SelectState {
const focused = input.focused;
const chart = focused?.kind === 'chart' ? focused.chart : undefined;
const course = focused?.kind === 'course' ? resolveCourseView(focused.course) : undefined;
const maker = input.courseMaker;
return {
ops: new Set(selectOps(input, chart, course)),
number: (num) => selectNumber(num, input, chart, course),
text: (st) => selectText(st, input, chart, course),
slider: (type) =>
type === LR2_SLIDER.SELECT_POSITION ? input.listPosition : resolveLR2OptionSlider(type, input.options),
button: (type) =>
resolveLR2CourseIRButtonState(type, focusedCourseRelease(input)) ??
(maker !== undefined ? resolveLR2CourseMakerButtonState(type, course, maker.defaultConnection) : undefined) ??
(maker?.randomMixSettings !== undefined
? resolveLR2RandomMixButtonState(type, maker.randomMixSettings)
: undefined) ??
resolveLR2OptionButton(type, input.options),
};
}
/** A play option a select button cycles through its choices (`PLAY_OPTION_CHOICES`). */
export type LR2CycledOption = Exclude<keyof PlayOptions, 'hiSpeed' | 'shutter' | 'autoPlay'>;
/** What an LR2 select button asks for (its `#SRC_BUTTON` `type`); the course maker's buttons have their own. */
export type LR2SelectButtonAction =
/** Open or close option panel 1-9. */
| { readonly kind: 'panel'; readonly panel: number }
/** Step a side's hi-speed; the button's `plusOnly` says which way. */
| { readonly kind: 'hi-speed'; readonly side: PlaySide }
/** Step the judge timing by 1 ms within ±99 (`stepLR2JudgeTiming`), up or down by the half clicked. */
| { readonly kind: 'judge-timing' }
/** Move a play option to its next choice. */
| { readonly kind: 'cycle-option'; readonly option: LR2CycledOption }
/** Set the difficulty filter. */
| { readonly kind: 'set-difficulty-filter'; readonly value: DifficultyFilter }
/** Play the selected bar, with AUTOPLAY, or its replay; show the chart's text file; open the key config or skins. */
| { readonly kind: 'play' | 'autoplay' | 'replay' | 'read-text' | 'key-config' | 'skin-select' };
/** The play option each LR2 option button cycles. */
const CYCLE_BUTTONS: Readonly<Record<number, LR2CycledOption>> = {
[LR2_BUTTON.DIFFICULTY_FILTER]: 'difficultyFilter',
[LR2_BUTTON.KEY_MODE_FILTER]: 'keysFilter',
[LR2_BUTTON.SORT]: 'sort',
[LR2_BUTTON.GAUGE_1P]: 'gauge1P',
[LR2_BUTTON.GAUGE_2P]: 'gauge2P',
[LR2_BUTTON.RANDOM_1P]: 'random1P',
[LR2_BUTTON.RANDOM_2P]: 'random2P',
[LR2_BUTTON.AUTO_SCRATCH_1P]: 'autoScratch1P',
[LR2_BUTTON.AUTO_SCRATCH_2P]: 'autoScratch2P',
[LR2_BUTTON.LANE_COVER]: 'laneCover',
[LR2_BUTTON.EFFECT_1P]: 'hiddenSudden1P',
[LR2_BUTTON.EFFECT_2P]: 'hiddenSudden2P',
[LR2_BUTTON.FLIP]: 'dpFlip',
[LR2_BUTTON.BATTLE]: 'battleMode',
[LR2_BUTTON.HS_FIX]: 'hsFix',
[LR2_BUTTON.SCORE_GRAPH]: 'scoreGraph',
[LR2_BUTTON.BGA]: 'bga',
[LR2_BUTTON.BGA_SIZE]: 'bgaSize',
[LR2_BUTTON.JUDGE_AUTO_ADJUST]: 'judgeTimingAutoAdjust',
};
/**
* What an LR2 select button does (`#SRC_BUTTON` `type`): toggle a panel (1-9), step a hi-speed (57 / 58) or the judge
* timing (74), cycle a play
* option (10-12, 40-46, 50, 51, 54, 55, 70, 72, 73, 75), set the difficulty filter (91-96), or play, play with AUTOPLAY,
* show the text file, replay, or open the key config or skin select (15, 16, 17, 19, 13, 14). `undefined` for any other
* button, the course maker's included (`resolveLR2CourseMakerAction`).
*/
export function resolveLR2SelectButton(type: number): LR2SelectButtonAction | undefined {
if (type >= LR2_BUTTON.PANEL1 && type <= LR2_BUTTON.PANEL9) return { kind: 'panel', panel: type };
if (type === LR2_BUTTON.HISPEED_1P) return { kind: 'hi-speed', side: '1P' };
if (type === LR2_BUTTON.HISPEED_2P) return { kind: 'hi-speed', side: '2P' };
if (type === LR2_BUTTON.JUDGE_TIMING) return { kind: 'judge-timing' };
const option = CYCLE_BUTTONS[type];
if (option !== undefined) return { kind: 'cycle-option', option };
const difficulty = LR2_DIFFICULTY_FILTER_BUTTONS[type];
if (difficulty !== undefined) return { kind: 'set-difficulty-filter', value: difficulty };
switch (type) {
case LR2_BUTTON.PLAY:
return { kind: 'play' };
case LR2_BUTTON.AUTOPLAY:
return { kind: 'autoplay' };
case LR2_BUTTON.REPLAY:
return { kind: 'replay' };
case LR2_BUTTON.READ_TEXT:
return { kind: 'read-text' };
case LR2_BUTTON.KEY_CONFIG:
return { kind: 'key-config' };
case LR2_BUTTON.SKIN_SELECT:
return { kind: 'skin-select' };
default:
return undefined;
}
}
/** The `#SRC_BAR_BODY` kind LR2 draws for a bar. */
function barBodyKind(entry: LibraryEntry | undefined): LR2BarBodyKind {
if (entry?.kind === 'folder') return entry.folder.courses !== undefined ? 'courseFolder' : 'folder';
if (entry?.kind !== 'course') return 'song';
// LR2's NEW COURSE bar (body 7, "make a course"), its RANDOM MIX bar and beatoraja's random course (body 9). A drawn
// RANDOM MIX is an ordinary course (body 8), as LR2 lists it.
if (entry.course.newCourse === true) return 'courseCreate';
if (entry.course.randomMix === true || entry.course.random !== undefined) return 'randomCourse';
return 'course';
}
/**
* The bar body a bar of the list draws (`#SRC_BAR_BODY`): a chart takes body 0, a folder 1, a folder of courses 6 (else
* 1), a course 8, a NEW COURSE bar 7 and a RANDOM MIX bar or random course 9 (each else 8). Anything the skin lacks falls back to the
* chart body, then the first body. A slot with no bar (past either end of the list) still gets a body, as LR2's rail
* draws past the end of the list.
*/
export function pickLR2BarBody(
bodies: readonly LR2BarBodySource[],
entry: LibraryEntry | undefined,
): LR2BarBodySource | undefined {
if (bodies.length === 0) return undefined;
const kind = barBodyKind(entry);
const fallback: LR2BarBodyKind | undefined =
kind === 'courseFolder' ? 'folder' : kind === 'courseCreate' || kind === 'randomCourse' ? 'course' : undefined;
return (
bodies.find((body) => body.kind === kind) ??
(fallback !== undefined ? bodies.find((body) => body.kind === fallback) : undefined) ??
bodies.find((body) => body.kind === 'song') ??
bodies[0]
);
}
const BAR_LEVEL_KINDS: readonly LR2BarLevelKind[] = ['undefined', 'beginner', 'normal', 'hyper', 'another', 'insane'];
/**
* The level a chart bar draws (`#SRC_BAR_LEVEL`): the chart's play level, in the level kind of its `#DIFFICULTY`
* (`undefined` for none; LR2's internet-ranking kind is never a chart's). None for a chart without a numeric level.
*/
export function resolveLR2BarLevel(chart: LibraryChart): { kind: LR2BarLevelKind; level: number } | undefined {
const level = lr2PlayLevel(chart);
if (level === undefined) return undefined;
const difficulty = resolveLibraryChartDifficultyValue(chart);
const kind = difficulty !== undefined ? (BAR_LEVEL_KINDS[difficulty] ?? 'undefined') : 'undefined';
return { kind, level };
}
/** A moment of the select screen that starts LR2 timers. */
export type LR2SelectTimerEvent =
/** The screen appears: timer 0, and the bar-change timer (11) so the bars slide in. */
| { readonly kind: 'scene-start'; readonly at: number }
/** The cursor moves by `delta` bars: timers 10 and 11, and 12 (up) or 13 (down). */
| { readonly kind: 'cursor'; readonly delta: number; readonly at: number }
/** Option panel 1-9 opens or closes: its open timer (21-29) runs while it is open, its close timer (31-39) from then. */
| { readonly kind: 'panel'; readonly panel: number; readonly open: boolean; readonly at: number }
/** Making a course starts (timer 17) or ends (timer 18). */
| { readonly kind: 'course-making'; readonly making: boolean; readonly at: number };
/** The LR2 timers a moment of the select screen starts and stops. */
export function resolveLR2SelectTimers(event: LR2SelectTimerEvent): LR2TimerUpdate {
switch (event.kind) {
case 'scene-start':
return lr2TimerUpdate([LR2_TIMER.SCENE_START, LR2_TIMER.SONG_BAR_CHANGE], event.at);
case 'cursor':
return lr2TimerUpdate(
[
LR2_TIMER.SONG_BAR_MOVE,
LR2_TIMER.SONG_BAR_CHANGE,
event.delta < 0 ? LR2_TIMER.SONG_BAR_UP : LR2_TIMER.SONG_BAR_DOWN,
],
event.at,
);
case 'panel': {
Iif (event.panel < 1 || event.panel > 9) return lr2TimerUpdate([], event.at);
const open = LR2_TIMER.PANEL1_OPEN + event.panel - 1;
const close = LR2_TIMER.PANEL1_CLOSE + event.panel - 1;
return event.open ? lr2TimerUpdate([open], event.at, [close]) : lr2TimerUpdate([close], event.at, [open]);
}
case 'course-making':
return event.making
? lr2TimerUpdate([LR2_TIMER.COURSE_MAKING_START], event.at, [LR2_TIMER.COURSE_MAKING_END])
: lr2TimerUpdate([LR2_TIMER.COURSE_MAKING_END], event.at, [LR2_TIMER.COURSE_MAKING_START]);
}
}
|