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 | 51x 51x 22x 16x 51x 9x 9x 8x 6x 5x 54x 3x 6x 20x 1x 24x 28x 1x 4x 1x 1x 21x 61x 61x 60x 60x 34x 34x 4x 4x 4x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 60x 51x 5x 5x 1x 1x 5x 19x 19x 5x 5x 5x 16x 19x 19x 3x 2x 1x 1x 9x 19x 2x 2x 2x 2x 38x 38x 2x 1x 1x 34x 32x 32x 32x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 5x 5x 2x 1x 1x 2x 1x 2x 1x 2x 1x 9x 2x 2x 3x 1x 1x 4x | import { resolveBeatorajaSelectReplayOps } from './replay-slots.ts';
import {
resolveCourseView,
type BrowseListOptions,
type BrowseSort,
type CourseView,
type KeysFilter,
type LibraryCourse,
type LibraryEntry,
} from '@be-music/player-scene-model';
import { BEATORAJA_BUTTON, BEATORAJA_NUM, BEATORAJA_OP, BEATORAJA_TEXT } from '../runtime-ids.ts';
import { beatorajaMissingCourseStages, resolveBeatorajaCourseBarOps, resolveBeatorajaCourseText } from './course.ts';
import type { BeatorajaNoteBreakdown, BeatorajaWallClock } from './inputs.ts';
import { beatorajaKeysongOp, resolveBeatorajaChartTraitOps, type BeatorajaChartTraits } from './play-ops.ts';
import {
resolveBeatorajaSkinText,
resolveBeatorajaChartText,
joinBeatorajaText,
type BeatorajaSkinTextInput,
} from './chart-text.ts';
/** The key-mode filters in the order of beatoraja's MODE button (`BUTTON_MODE`), which its `modeset` images follow. */
export const BEATORAJA_KEYS_FILTERS: readonly KeysFilter[] = [
'ALL',
'KEYS_5',
'KEYS_7',
'KEYS_10',
'KEYS_14',
'KEYS_9',
'KEYS_24',
'KEYS_48',
];
/** The sorts in the order of beatoraja's SORT button (`BUTTON_SORT`), which its `sortset` images follow. */
export const BEATORAJA_SORTS: readonly BrowseSort[] = [
'OFF',
'TITLE',
'ARTIST',
'GENRE',
'LEVEL',
'BPM',
'NOTES',
'LASTPLAY',
];
/** A key-mode filter's place on beatoraja's MODE button (0 ALL … 7 24 KEYS DOUBLE). */
export function beatorajaKeysFilterIndex(filter: KeysFilter): number {
return Math.max(0, BEATORAJA_KEYS_FILTERS.indexOf(filter));
}
/** A sort's place on beatoraja's SORT button; 0 (the library's order) for a sort it does not have (`CLEAR`). */
export function beatorajaSortIndex(sort: BrowseSort): number {
return Math.max(0, BEATORAJA_SORTS.indexOf(sort));
}
const KEYS_FILTER_BY_VARIANT: Readonly<Record<string, KeysFilter>> = {
'5': 'KEYS_5',
'7': 'KEYS_7',
'9': 'KEYS_9',
'10': 'KEYS_10',
'14': 'KEYS_14',
'24': 'KEYS_24',
'48': 'KEYS_48',
};
/**
* A play variant's place on beatoraja's MODE button (`'5'` 1, `'7'` 2, `'10'` 3, `'14'` 4, `'9'` 5, `'24'` 6, `'48'`
* 7): the filter that lists a chart of that variant. 0 (ALL) for an unknown variant.
*/
export function beatorajaKeyModeIndex(playVariant: string | undefined): number {
const filter = playVariant !== undefined ? KEYS_FILTER_BY_VARIANT[playVariant] : undefined;
return filter !== undefined ? beatorajaKeysFilterIndex(filter) : 0;
}
/**
* The LNMODE button's index (0 LN, 1 CN, 2 HCN) for a chart's `#LNMODE`, which counts from 1 (1 LN, 2 CN, 3 HCN).
* Charts without the directive, or with a value outside 1..3, read as LN.
*/
export function beatorajaLNModeIndex(lnMode: number | undefined): 0 | 1 | 2 {
if (lnMode === 2) return 1;
if (lnMode === 3) return 2;
return 0;
}
/**
* The difficulty ops of a chart's `#DIFFICULTY` (1 BEGINNER … 5 INSANE): beatoraja's `LEVEL_*` op (70-74) and LR2's
* `DIFFICULTY_*` one (151-155), which skins gate on either of. Without a difficulty only `DIFFICULTY_UNDEFINED` (150).
*/
export function beatorajaDifficultyOps(difficulty: number | undefined): number[] {
switch (difficulty) {
case 1:
return [BEATORAJA_OP.LEVEL_BEGINNER, BEATORAJA_OP.DIFFICULTY_BEGINNER];
case 2:
return [BEATORAJA_OP.LEVEL_NORMAL, BEATORAJA_OP.DIFFICULTY_NORMAL];
case 3:
return [BEATORAJA_OP.LEVEL_HYPER, BEATORAJA_OP.DIFFICULTY_HYPER];
case 4:
return [BEATORAJA_OP.LEVEL_ANOTHER, BEATORAJA_OP.DIFFICULTY_ANOTHER];
case 5:
return [BEATORAJA_OP.LEVEL_INSANE, BEATORAJA_OP.DIFFICULTY_INSANE];
default:
return [BEATORAJA_OP.DIFFICULTY_UNDEFINED];
}
}
/**
* The judge-rank op of a chart's `#RANK` (0 VERY HARD … 4 VERY EASY, `JUDGE_*` 180-184); NORMAL for a chart without one
* or with another value, as beatoraja reads a chart without `#RANK`.
*/
export function beatorajaJudgeRankOp(rank: number | undefined): number {
switch (rank) {
case 0:
return BEATORAJA_OP.JUDGE_VERYHARD;
case 1:
return BEATORAJA_OP.JUDGE_HARD;
case 3:
return BEATORAJA_OP.JUDGE_EASY;
case 4:
return BEATORAJA_OP.JUDGE_VERYEASY;
default:
return BEATORAJA_OP.JUDGE_NORMAL;
}
}
/** Notes per second, as a whole number and its two decimal digits (numbers 360-365, beatoraja `SongInformation`). */
export interface BeatorajaDensityReadout {
readonly whole: number;
readonly afterDot: number;
}
/** What the select screen reads of the focused chart beyond its library entry. */
export interface BeatorajaSelectChartFacts {
readonly playVariant?: string;
readonly traits: BeatorajaChartTraits;
/** `#DIFFICULTY`. */
readonly difficulty?: number;
/** `#RANK`. */
readonly judgeRank?: number;
/** `#TOTAL` as written. */
readonly total?: number;
/** `#LNMODE` as written (1 LN, 2 CN, 3 HCN). */
readonly lnMode?: number;
/** The sub-artist line. */
readonly subartist: string;
readonly noteBreakdown: BeatorajaNoteBreakdown;
readonly density: {
readonly peak: BeatorajaDensityReadout;
readonly end: BeatorajaDensityReadout;
readonly average: BeatorajaDensityReadout;
};
/** The chart's length in seconds. */
readonly lengthSeconds: number;
/** The lowest and highest BPM; absent without a positive one. */
readonly bpmRange?: { readonly min: number; readonly max: number };
/**
* The BPM the most judged notes sit at (beatoraja's MAINBPM, `resolveChartMainBPM` of `@be-music/chart-model`, the rule a
* play reads); the header BPM when 0 or absent.
*/
readonly mainBPM?: number;
}
/**
* What the select screen's skin reads: the bar under the cursor (with its chart's facts when it is a chart bar), where
* the list is and how it is shaped, the options the screen keeps, the focused bar's record, and the clock.
*/
export interface BeatorajaSelectInput {
readonly focused?: LibraryEntry;
/** The facts of the focused chart; read only on a chart bar. */
readonly chart?: BeatorajaSelectChartFacts;
/** The label of the folder the list is in; empty at the root. */
readonly folderLabel: string;
/** The search text as typed. */
readonly searchText: string;
readonly list: Pick<BrowseListOptions, 'keysFilter' | 'sort'>;
/** The player's LN MODE (0 LN, 1 CN, 2 HCN), which the LNMODE button steps; the focused chart's `#LNMODE` when absent. */
readonly lnMode?: 0 | 1 | 2;
readonly skin?: BeatorajaSkinTextInput;
/** The skin config's judge timing offset (ms). */
readonly judgeTiming: number;
/** The focused bar's best clear lamp, as its op (`beatorajaClearLampOp`); NO PLAY when absent. */
readonly lampOp?: number;
/** Which of the focused chart's or course's replay slots hold a replay; none when absent. */
readonly replaySlots?: readonly boolean[];
/** The replay slot REPLAY plays (0-3), or −1 for none. */
readonly selectedReplaySlot?: number;
readonly wallClock?: BeatorajaWallClock;
}
/**
* The ops the select screen lights for the bar under the cursor, none without one. With a bar: the screen's fixed state
* (`LOADED`, `OFFLINE`, `REPLAY_OFF`, `DISABLE_SAVE_SCORE`, `NO_SAVE_CLEAR`, `BGA_ON`), and `FOLDERBAR` on a folder bar,
* the course bar ops on a course bar ({@link resolveBeatorajaCourseBarOps}), and on a chart bar `SONGBAR`,
* `PLAYABLEBAR`, its key-mode, trait, difficulty and judge-rank ops and its clear lamp. A chart or course bar also lights
* its replay slot ops ({@link resolveBeatorajaSelectReplayOps}).
*/
export function resolveBeatorajaSelectBarOps(input: BeatorajaSelectInput): number[] {
const entry = input.focused;
if (entry === undefined) return [];
const ops: number[] = [
BEATORAJA_OP.LOADED,
BEATORAJA_OP.OFFLINE,
BEATORAJA_OP.REPLAY_OFF,
BEATORAJA_OP.DISABLE_SAVE_SCORE,
BEATORAJA_OP.NO_SAVE_CLEAR,
BEATORAJA_OP.BGA_ON,
];
switch (entry.kind) {
case 'folder':
ops.push(BEATORAJA_OP.FOLDERBAR);
break;
case 'course':
ops.push(...resolveBeatorajaCourseBarOps(entry.course, input.lampOp));
ops.push(...resolveBeatorajaSelectReplayOps(input.replaySlots ?? [], input.selectedReplaySlot ?? -1));
break;
case 'chart': {
ops.push(BEATORAJA_OP.SONGBAR, BEATORAJA_OP.PLAYABLEBAR);
const chart = input.chart;
const keysong = beatorajaKeysongOp(chart?.playVariant);
Eif (keysong !== undefined) ops.push(keysong);
Eif (chart !== undefined) {
ops.push(...resolveBeatorajaChartTraitOps(chart.traits));
ops.push(...beatorajaDifficultyOps(chart.difficulty));
ops.push(beatorajaJudgeRankOp(chart.judgeRank));
}
ops.push(input.lampOp ?? BEATORAJA_OP.CLEAR_LAMP_NOPLAY);
ops.push(...resolveBeatorajaSelectReplayOps(input.replaySlots ?? [], input.selectedReplaySlot ?? -1));
break;
}
}
return ops;
}
const COURSE_VIEWS = new WeakMap<LibraryCourse, { view: CourseView; missing: ReadonlySet<number> }>();
function courseView(course: LibraryCourse): { view: CourseView; missing: ReadonlySet<number> } {
let cached = COURSE_VIEWS.get(course);
if (cached === undefined) {
cached = { view: resolveCourseView(course), missing: beatorajaMissingCourseStages(course) };
COURSE_VIEWS.set(course, cached);
}
return cached;
}
/**
* The select screen's text for the bar under the cursor. A course bar names its stages on 150-159, marking the ones the
* library lacks. The title and full title read a folder bar's label (`StringPropertyFactory`'s `DirectoryBar` case);
* the other song texts read empty off a chart bar. The folder text is the chart's folder, else the folder the list is
* in; the search word is the search text; the difficulty-table texts read empty.
*/
export function resolveBeatorajaSelectText(id: number, input: BeatorajaSelectInput): string | undefined {
const entry = input.focused;
if (entry?.kind === 'course') {
const { view, missing } = courseView(entry.course);
const courseText = resolveBeatorajaCourseText(id, view, { missingStages: missing });
if (courseText !== undefined) return courseText;
}
const chartEntry = entry?.kind === 'chart' ? entry.chart : undefined;
const folderLabel = entry?.kind === 'folder' ? entry.folder.label : undefined;
switch (id) {
case BEATORAJA_TEXT.TITLE:
return folderLabel ?? chartEntry?.title ?? '';
case BEATORAJA_TEXT.FULLTITLE:
return folderLabel ?? joinBeatorajaText(chartEntry?.title, chartEntry?.subtitle);
case BEATORAJA_TEXT.SEARCHWORD:
return input.searchText;
case BEATORAJA_TEXT.TABLE_NAME:
case BEATORAJA_TEXT.TABLE_LEVEL:
case BEATORAJA_TEXT.TABLE_FULL:
return '';
}
const songText = resolveBeatorajaChartText(id, {
title: chartEntry?.title,
subtitle: chartEntry?.subtitle,
genre: chartEntry?.genre,
artist: chartEntry?.artist,
subartist: chartEntry !== undefined ? input.chart?.subartist : undefined,
directory: chartEntry?.directoryLabel ?? input.folderLabel,
});
return songText ?? resolveBeatorajaSkinText(id, input.skin);
}
/** `#PLAYLEVEL` as a number: a number as it is, text parsed; `undefined` without a readable one. */
function playLevelNumber(level: number | string | undefined): number | undefined {
Iif (typeof level === 'number') return Number.isFinite(level) ? level : undefined;
Eif (typeof level === 'string' && level.length > 0) {
const parsed = Number.parseInt(level, 10);
return Number.isFinite(parsed) ? parsed : undefined;
}
return undefined;
}
/**
* The select screen's number for the bar under the cursor, `undefined` to hide it. The folder bar's chart count (300)
* and the clock (21-26) read on any bar; the rest on a chart bar only: its `#TOTAL` (368), note kinds (350-353),
* densities (360-365), notes, BPMs and `#PLAYLEVEL`, length (1163 / 1164), and the judge timing offset (12). The main
* BPM (92) is the one a play shows ({@link BeatorajaSelectChartFacts.mainBPM}), not the header BPM. The play's live
* numbers read 0 (there is no play on the select screen).
*/
export function resolveBeatorajaSelectNumber(id: number, input: BeatorajaSelectInput): number | undefined {
const entry = input.focused;
switch (id) {
case BEATORAJA_NUM.FOLDER_TOTALSONGS:
return entry?.kind === 'folder' ? entry.folder.charts.length : undefined;
case BEATORAJA_NUM.TIME_YEAR:
return input.wallClock?.year;
case BEATORAJA_NUM.TIME_MONTH:
return input.wallClock?.month;
case BEATORAJA_NUM.TIME_DAY:
return input.wallClock?.day;
case BEATORAJA_NUM.TIME_HOUR:
return input.wallClock?.hour;
case BEATORAJA_NUM.TIME_MINUTE:
return input.wallClock?.minute;
case BEATORAJA_NUM.TIME_SECOND:
return input.wallClock?.second;
}
if (entry?.kind !== 'chart') return undefined;
const chartEntry = entry.chart;
const chart = input.chart;
switch (id) {
case BEATORAJA_NUM.BMS_TOTAL:
return chart?.total !== undefined && Number.isFinite(chart.total) ? Math.floor(chart.total) : undefined;
case BEATORAJA_NUM.TOTALNOTE_NORMAL:
return chart?.noteBreakdown.normal;
case BEATORAJA_NUM.TOTALNOTE_LN:
return chart?.noteBreakdown.ln;
case BEATORAJA_NUM.TOTALNOTE_SCRATCH:
return chart?.noteBreakdown.scratch;
case BEATORAJA_NUM.TOTALNOTE_BSS:
return chart?.noteBreakdown.bss;
case BEATORAJA_NUM.DENSITY_PEAK:
return chart?.density.peak.whole;
case BEATORAJA_NUM.DENSITY_PEAK_AFTERDOT:
return chart?.density.peak.afterDot;
case BEATORAJA_NUM.DENSITY_END:
return chart?.density.end.whole;
case BEATORAJA_NUM.DENSITY_END_AFTERDOT:
return chart?.density.end.afterDot;
case BEATORAJA_NUM.DENSITY_AVERAGE:
return chart?.density.average.whole;
case BEATORAJA_NUM.DENSITY_AVERAGE_AFTERDOT:
return chart?.density.average.afterDot;
case BEATORAJA_NUM.TOTALNOTES:
case BEATORAJA_NUM.TOTALNOTES_LIVE:
return chartEntry.totalNotes;
case BEATORAJA_NUM.MAINBPM: {
const main = chart?.mainBPM !== undefined && chart.mainBPM > 0 ? chart.mainBPM : chartEntry.bpm;
return main !== undefined ? Math.round(main) : undefined;
}
case BEATORAJA_NUM.NOWBPM:
return chartEntry.bpm !== undefined ? Math.round(chartEntry.bpm) : undefined;
case BEATORAJA_NUM.MAXBPM:
return chart?.bpmRange?.max;
case BEATORAJA_NUM.MINBPM:
return chart?.bpmRange?.min;
case BEATORAJA_NUM.PLAYLEVEL:
return playLevelNumber(chartEntry.playLevel);
case BEATORAJA_NUM.JUDGETIMING:
return input.judgeTiming;
case BEATORAJA_NUM.SONGLENGTH_MINUTE:
return chart !== undefined ? Math.floor(chart.lengthSeconds / 60) : undefined;
case BEATORAJA_NUM.SONGLENGTH_SECOND:
return chart !== undefined ? Math.floor(chart.lengthSeconds) % 60 : undefined;
case BEATORAJA_NUM.POINT:
case BEATORAJA_NUM.SCORE2:
case BEATORAJA_NUM.SCORE_RATE:
case BEATORAJA_NUM.SCORE_RATE_AFTERDOT:
case BEATORAJA_NUM.COMBO:
case BEATORAJA_NUM.MAXCOMBO_LIVE:
case BEATORAJA_NUM.GROOVEGAUGE:
case BEATORAJA_NUM.PERFECT:
case BEATORAJA_NUM.GREAT:
case BEATORAJA_NUM.GOOD:
case BEATORAJA_NUM.BAD:
case BEATORAJA_NUM.POOR:
return 0;
default:
return undefined;
}
}
/**
* The image an image set with a `ref` picks on the select screen: the MODE button's filter (11), the SORT button's sort
* (12), the player's LN MODE (308, else the focused chart's `#LNMODE`) and the best clear lamp (370, NO PLAY: no
* records feed it yet). 0 (the first image) for any other ref.
*/
export function resolveBeatorajaSelectRefValue(ref: number, input: BeatorajaSelectInput): number {
switch (ref) {
case BEATORAJA_BUTTON.MODE:
return beatorajaKeysFilterIndex(input.list.keysFilter);
case BEATORAJA_BUTTON.SORT:
return beatorajaSortIndex(input.list.sort);
case BEATORAJA_BUTTON.LNMODE:
return input.lnMode ?? beatorajaLNModeIndex(input.focused?.kind === 'chart' ? input.chart?.lnMode : undefined);
case BEATORAJA_NUM.CLEAR:
return 0;
default:
return 0;
}
}
/**
* The select screen's slider positions: the volume sliders (17-19) at full, as there is no volume to show yet.
* `undefined` (the slider at its home) for the others.
*/
export function resolveBeatorajaSelectSliderValue(type: number): number | undefined {
return type === 17 || type === 18 || type === 19 ? 1 : undefined;
}
|