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 | 121x 121x 121x 121x 121x 121x 121x 68x 51x 51x 51x 7x 121x 121x 121x 121x 121x 121x 81x 30x 64x 10x 10x 10x 10x 54x 20x 20x 20x 20x 34x 34x 34x 34x 64x 121x 31x 31x 27x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 17x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 3x 121x 4x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 3x 3x 121x 7x 5x 4x 3x 121x 121x 11x 10x 10x 11x 8x 8x 13x 13x 13x 13x 31x | import type { DifficultyBasis } from '@be-music/player-engine/display';
import {
resolveLibraryChartDifficulty,
type CourseView,
type LibraryChartDifficultySource,
} from '@be-music/player-scene-model';
import { PLAYFIELD } from './playfield.ts';
import { STAGE_HEIGHT, STAGE_MARGIN, STAGE_WIDTH } from './stage.ts';
import type { BeMusicGameplayLayout, BeMusicGameplayRuntime, BeMusicRect, BeMusicStage } from './types.ts';
/**
* The cabinet layout of the 16:9 play screen: the play area on the left (the lanes over the keys, the gauge, then the
* score and hi-speed), the score graph beside it, and on the right the stage name, the players and the chart, the BGA,
* and the judgement and BPM panels along the bottom. The lanes keep the standard geometry; the panels follow
* `layout.playfield.right`, so a wider chart narrows the right-hand column and, when it leaves too little room, drops
* the graph.
*/
export interface CabinetLayout {
/** Independent second player's panels, with the monitor between the lane banks. */
secondSide?: { gauge: BeMusicRect; score: BeMusicRect; hiSpeed: BeMusicRect };
/** The play area's frame: the lanes down to the judgement line, the keys, the gauge, the score and the hi-speed. */
play: BeMusicRect;
/** The chart's progress, a thin bar left of the lanes; omitted when the lanes start at the stage's edge. */
progress?: BeMusicRect;
/** The key and scratch strip under the judgement line. */
keys: BeMusicRect;
/** The gauge bar; its label and percentage go on the line above it, inside {@link gaugeLabelY}. */
gauge: BeMusicRect;
/** Middle of the gauge's label line. */
gaugeLabelY: number;
score: BeMusicRect;
hiSpeed: BeMusicRect;
/** The score graph: YOU and PACEMAKER over the bars, then the lane option and the pacemaker's name. */
graph?: { header: BeMusicRect; bars: BeMusicRect; footer: BeMusicRect };
/** The stage name band aligned with its information column. */
stage: BeMusicRect;
/** The players and the chart: 1P's plate on the left, the title in the middle, 2P's plate on the right. */
players: BeMusicRect;
/** The BGA square, as {@link resolveCabinetBGARect} places it. */
bga: BeMusicRect;
/** The judgement counts, FAST / SLOW and the last timing. */
judge: BeMusicRect;
/** The BPM now with the chart's lowest and highest. */
bpm: BeMusicRect;
/** The play tempo, under the BPM. */
tempo: BeMusicRect;
/**
* True for a double-play field centred on the stage ({@link cabinetStage}'s `doublePlayCenterX`): the stage band, the
* chart, the BGA and the judgement panel take the left column, the graph and the tempo the right one, and the score,
* the gauge, the hi-speed and the BPM sit under the lanes. The chart panel is then a narrow stack.
*/
doublePlay: boolean;
/** The box between the two sides' keys, for the gauge they share; double play only. */
center?: BeMusicRect;
/**
* A band aligned with the right column, for what the narrow stage band has no
* room for (the play mode, a DOM skin's buttons); double play only.
*/
controls?: BeMusicRect;
}
/** Gap between the panels. */
const GAP = 8;
/** Width of the score graph column. */
const GRAPH_WIDTH = 132;
/** The right-hand column is never narrower than this; a wider chart gives up the graph first. */
const MIN_INFO_WIDTH = 300;
/** Narrowest the play area gets, so a 5 KEY chart still fits the score and the hi-speed under it. */
const MIN_PLAY_WIDTH = 210;
/** Top of the BGA area and of the bottom panels. */
const BGA_TOP = 98;
const PANELS_TOP = 360;
/** Below this the BGA would be a postage stamp; it is hidden instead, as on {@link wideStage}. */
const MIN_BGA_SIZE = 120;
/** Right edge of the play area for lanes ending at `playfieldRight`. */
function playRight(playfieldRight: number): number {
return Math.max(playfieldRight + 8, STAGE_MARGIN + MIN_PLAY_WIDTH);
}
/** The right-hand column's left edge, and whether the graph sits between it and the play area. */
function infoColumn(playfieldRight: number): { left: number; graph: boolean } {
const right = playRight(playfieldRight);
const withGraph = right + GAP + GRAPH_WIDTH + GAP;
if (STAGE_WIDTH - STAGE_MARGIN - withGraph >= MIN_INFO_WIDTH) return { left: withGraph, graph: true };
return { left: right + GAP, graph: false };
}
/**
* Width of one independent player's lane bank in 7-key play. The monitor between the banks, and each side's score and
* hi-speed, keep this width when a 5-key bank is narrower, so the two key counts share one arrangement.
*/
const TWO_PLAYER_BANK_WIDTH = 194;
/** Lanes starting this far right of the margin were centred for double play. */
const CENTRED_LEFT = 120;
/** Uniform gap between panels in the double-play side columns. */
const DP_GAP = 8;
/** Top of the panels below the 22 px top bands. */
const DP_TOP = 8 + 22 + DP_GAP;
/** Height of the double-play chart panel and of the row of score, gauge and hi-speed under the keys. */
const DP_CHART_H = 64;
const DP_ROW_H = 36;
function isCentred(playfieldLeft: number): boolean {
return playfieldLeft - STAGE_MARGIN >= CENTRED_LEFT;
}
/** The double-play left column (stage band, chart, BGA, judgement) for lanes starting at `playfieldLeft`. */
function leftColumn(playfieldLeft: number): { x: number; w: number } {
return { x: STAGE_MARGIN, w: playfieldLeft - 14 - STAGE_MARGIN };
}
/**
* The BGA square for lanes from `playfieldLeft` to `playfieldRight`: as large as the right-hand column's width and the
* band between the players and the bottom panels allow, centred in the column; for a double-play field centred on the
* stage, at the top of the left column under the chart. Independent players use the square between their banks. Too small a square gives an empty rect, so the play has no BGA.
*/
export function resolveCabinetBGARect(
playfieldRight: number,
playfieldLeft: number = STAGE_MARGIN,
twoPlayer = false,
): BeMusicRect {
if (twoPlayer) {
// Keep the same monitor in 5-key and 7-key play; the adjacent graph and judge panel use the remaining centre.
const centerLeft = playfieldLeft + TWO_PLAYER_BANK_WIDTH + 16;
const centerRight = playfieldRight - TWO_PLAYER_BANK_WIDTH - 16;
const infoLeft = centerLeft + GRAPH_WIDTH + 16;
return { x: Math.round((infoLeft + centerRight - 220) / 2), y: 100, w: 220, h: 220 };
}
if (isCentred(playfieldLeft)) {
const column = leftColumn(playfieldLeft);
const top = DP_TOP + DP_CHART_H + DP_GAP;
const size = Math.min(column.w, 190);
return size >= MIN_BGA_SIZE
? { x: Math.round(column.x + (column.w - size) / 2), y: top, w: size, h: size }
: { x: column.x, y: top, w: 0, h: 0 };
}
const { left } = infoColumn(playfieldRight);
const width = STAGE_WIDTH - STAGE_MARGIN - left;
const fit = Math.min(width, PANELS_TOP - GAP - BGA_TOP);
const size = fit >= MIN_BGA_SIZE ? fit : 0;
return { x: Math.round(left + (width - size) / 2), y: BGA_TOP, w: size, h: size };
}
/**
* The 16:9 stage with the cabinet layout's BGA square: {@link wideStage}'s size and lanes, with a double-play field
* centred on the stage.
*/
export const cabinetStage: BeMusicStage = {
width: STAGE_WIDTH,
height: STAGE_HEIGHT,
playfield: {
standard: {
top: PLAYFIELD.y,
judgementY: PLAYFIELD.judgementY + 12,
doublePlayCenterX: STAGE_WIDTH / 2,
twoPlayerSideInset: 33,
},
},
resolveBGARect: resolveCabinetBGARect,
fitBGAVideoAspect: true,
};
/** The {@link CabinetLayout} of a landscape gameplay `layout` on the {@link cabinetStage}. */
export function resolveCabinetLayout(layout: Pick<BeMusicGameplayLayout, 'playfield' | 'twoPlayer'>): CabinetLayout {
const { playfield } = layout;
if (layout.twoPlayer && playfield.sides['1P'] && playfield.sides['2P']) return resolveTwoPlayerCabinet(playfield);
if (isCentred(playfield.left)) return resolveDoublePlayCabinet(playfield);
const right = playRight(playfield.right);
const play = { x: STAGE_MARGIN, y: playfield.top, w: right - STAGE_MARGIN, h: STAGE_HEIGHT - 12 - playfield.top };
const keys = { x: playfield.left, y: playfield.judgementY + 2, w: playfield.right - playfield.left, h: 28 };
const gauge = { x: STAGE_MARGIN + 4, y: keys.y + keys.h + 28, w: play.w - 8, h: 12 };
const gaugeLabelY = (keys.y + keys.h + gauge.y) / 2;
const scoreY = gauge.y + gauge.h + 8;
// The score and the hi-speed sit inside the play area's frame, as the gauge does.
const scoreH = play.y + play.h - 4 - scoreY;
const scoreW = Math.round((play.w - 8 - GAP) * 0.58);
const { left, graph } = infoColumn(playfield.right);
const infoRight = STAGE_WIDTH - STAGE_MARGIN;
const infoW = infoRight - left;
const judgeW = Math.round((infoW - GAP) * 0.55);
const sideW = infoW - GAP - judgeW;
const graphX = right + GAP;
return {
play,
...(playfield.left - STAGE_MARGIN >= 12
? { progress: { x: STAGE_MARGIN + 2, y: playfield.top + 4, w: 6, h: playfield.judgementY - playfield.top - 8 } }
: {}),
keys,
gauge,
gaugeLabelY,
score: { x: STAGE_MARGIN + 4, y: scoreY, w: scoreW, h: scoreH },
hiSpeed: { x: STAGE_MARGIN + 4 + scoreW + GAP, y: scoreY, w: play.w - 8 - scoreW - GAP, h: scoreH },
...(graph
? {
graph: {
header: { x: graphX, y: 8, w: GRAPH_WIDTH, h: 54 },
bars: { x: graphX, y: 62 + GAP, w: GRAPH_WIDTH, h: PANELS_TOP - GAP - (62 + GAP) },
footer: { x: graphX, y: PANELS_TOP, w: GRAPH_WIDTH, h: STAGE_HEIGHT - 16 - PANELS_TOP },
},
}
: {}),
stage: { x: left, y: 8, w: infoW, h: 22 },
players: { x: left, y: 30 + GAP, w: infoW, h: BGA_TOP - GAP - (30 + GAP) },
bga: resolveCabinetBGARect(playfield.right),
judge: { x: left, y: PANELS_TOP, w: judgeW, h: STAGE_HEIGHT - 16 - PANELS_TOP },
bpm: { x: left + judgeW + GAP, y: PANELS_TOP, w: sideW, h: 64 },
tempo: { x: left + judgeW + GAP, y: PANELS_TOP + 64 + 8, w: sideW, h: STAGE_HEIGHT - 16 - PANELS_TOP - 72 },
doublePlay: false,
};
}
/**
* The double-play arrangement around lanes centred on the stage: the left column holds the stage band, the chart, the
* BGA and the judgement panel; the right column the controls, graph and tempo; and under the
* keys sit the score (under 1P), the gauge both sides share, the hi-speed (under 2P), and the BPM below them. The box
* between the two banks of keys shows the shared gauge.
*/
function resolveDoublePlayCabinet(playfield: BeMusicGameplayLayout['playfield']): CabinetLayout {
const bottom = STAGE_HEIGHT - 16;
const left = leftColumn(playfield.left);
const rightX = playfield.right + 14;
const right = { x: rightX, w: STAGE_WIDTH - STAGE_MARGIN - rightX };
const play = {
x: playfield.left - 8,
y: playfield.top,
w: playfield.right - playfield.left + 16,
h: STAGE_HEIGHT - 8,
};
const keys = { x: playfield.left, y: playfield.judgementY + 2, w: playfield.right - playfield.left, h: 28 };
const rowY = keys.y + keys.h + 10;
const figureW = Math.min(120, Math.round(play.w * 0.24));
const score = { x: playfield.left, y: rowY, w: figureW, h: DP_ROW_H };
const hiSpeed = { x: playfield.right - figureW, y: rowY, w: figureW, h: DP_ROW_H };
const gaugeX = score.x + score.w + GAP;
const gauge = { x: gaugeX, y: rowY + 20, w: hiSpeed.x - GAP - gaugeX, h: 12 };
const bpmW = Math.min(200, play.w - 40);
const bga = resolveCabinetBGARect(playfield.right, playfield.left);
const judgeY = bga.y + Math.max(bga.h, MIN_BGA_SIZE) + DP_GAP;
const side1P = playfield.sides['1P'];
const side2P = playfield.sides['2P'];
const footerH = 64;
const tempoH = 36;
const tempoY = bottom - tempoH;
const footerY = tempoY - 8 - footerH;
return {
play,
progress: { x: playfield.left - 7, y: playfield.top + 4, w: 4, h: playfield.judgementY - playfield.top - 8 },
keys,
gauge,
gaugeLabelY: (keys.y + keys.h + gauge.y) / 2,
score,
hiSpeed,
graph: {
header: { x: right.x, y: DP_TOP, w: right.w, h: 54 },
bars: { x: right.x, y: DP_TOP + 54 + DP_GAP, w: right.w, h: footerY - 8 - (DP_TOP + 54 + DP_GAP) },
footer: { x: right.x, y: footerY, w: right.w, h: footerH },
},
stage: { ...left, y: 8, h: 22 },
players: { ...left, y: DP_TOP, h: DP_CHART_H },
bga,
judge: { ...left, y: judgeY, h: bottom - judgeY },
bpm: {
x: Math.round((playfield.left + playfield.right - bpmW) / 2),
y: rowY + DP_ROW_H + 8,
w: bpmW,
h: bottom - (rowY + DP_ROW_H + 8),
},
tempo: { ...right, y: tempoY, h: tempoH },
doublePlay: true,
controls: { ...right, y: 8, h: 22 },
...(side1P && side2P && side2P.left - side1P.right >= 24
? { center: { x: side1P.right + 4, y: keys.y, w: side2P.left - side1P.right - 8, h: keys.h } }
: {}),
};
}
/**
* Two independent players, with their gauges under their own keys and shared information around the monitor. Each
* side's gauge, score and hi-speed span at least a 7-key bank ({@link TWO_PLAYER_BANK_WIDTH}) from its outer edge, so a
* 5-key bank keeps the 7-key boxes.
*/
function resolveTwoPlayerCabinet(playfield: BeMusicGameplayLayout['playfield']): CabinetLayout {
const one = playfield.sides['1P']!;
const two = playfield.sides['2P']!;
const x = playfield.left + TWO_PLAYER_BANK_WIDTH + 16;
const w = playfield.right - TWO_PLAYER_BANK_WIDTH - 16 - x;
const keysY = playfield.judgementY + 2;
const gaugeY = keysY + 28 + 24;
const sideWidth = one.right - one.left;
const figuresWidth = Math.max(sideWidth, TWO_PLAYER_BANK_WIDTH);
const scoreWidth = Math.round((figuresWidth - GAP) * 0.62);
const score = { x: one.left, y: gaugeY + 20, w: scoreWidth, h: 464 - gaugeY - 20 };
const hiSpeed = { ...score, x: score.x + score.w + GAP, w: figuresWidth - score.w - GAP };
const secondLeft = two.right - figuresWidth;
const infoX = x + GRAPH_WIDTH + 16;
const infoW = x + w - infoX;
const bpmW = Math.min(132, infoW * 0.6);
return {
play: { x: one.left - 8, y: playfield.top, w: figuresWidth + 16, h: 464 - playfield.top },
progress: { x: one.left - 7, y: playfield.top + 4, w: 4, h: playfield.judgementY - playfield.top - 8 },
keys: { x: one.left, y: keysY, w: two.right - one.left, h: 28 },
gauge: { x: one.left, y: gaugeY, w: figuresWidth, h: 12 },
gaugeLabelY: (keysY + 28 + gaugeY) / 2,
score,
hiSpeed,
secondSide: {
gauge: { x: secondLeft, y: gaugeY, w: figuresWidth, h: 12 },
score: { ...score, x: secondLeft },
hiSpeed: { ...hiSpeed, x: secondLeft + scoreWidth + GAP },
},
graph: {
header: { x, y: 100, w: GRAPH_WIDTH, h: 54 },
bars: { x, y: 160, w: GRAPH_WIDTH, h: 190 },
footer: { x, y: 360, w: GRAPH_WIDTH, h: 104 },
},
stage: { x, y: 8, w: w - 180, h: 22 },
controls: { x: x + w - 170, y: 8, w: 170, h: 22 },
players: { x, y: 36, w, h: 54 },
bga: resolveCabinetBGARect(playfield.right, playfield.left, true),
judge: { x: infoX, y: 328, w: infoW, h: 92 },
bpm: { x: infoX, y: 428, w: bpmW, h: 36 },
tempo: { x: infoX + bpmW + GAP, y: 428, w: infoW - bpmW - GAP, h: 36 },
doublePlay: false,
};
}
/** One score the graph compares the player's against: its total for the chart, where it stands now, and the gap. */
export interface ScorePaceTarget {
/** What it is called on the graph (`AAA`, `MY BEST`, ...). */
label: string;
/** EX score over the whole chart. */
exScore: number;
/** EX score it holds at the notes judged so far: `exScore` times the share of the chart's notes judged. */
pace: number;
/** The player's EX score minus {@link pace}: ahead when positive. */
diff: number;
}
/** The score graph's figures: the player's EX score against the chart's maximum, the pacemaker and the best record. */
export interface ScorePace {
exScore: number;
/** The chart's maximum EX score. */
max: number;
/** Share of the chart's notes judged so far, 0..1. */
progress: number;
/** The pacemaker: the host's target, else the AAA line. */
target: ScorePaceTarget;
/** The player's best record on the chart; omitted without one. */
best?: ScorePaceTarget;
}
/** EX score of the AAA line (eight ninths of the maximum), the pacemaker when the host names none. */
function aaaLine(max: number): number {
return Math.ceil((max * 8) / 9);
}
/** The longest pacemaker name the score graph's box holds after the word PACEMAKER, in characters. */
export const PACEMAKER_NAME_LIMIT = 9;
/**
* The score graph's pacemaker box: `PACEMAKER RANK AAA`. A longer name (a score rate, a ranking place, a replay's)
* stands alone, so the box shows the whole of it.
*/
export function formatPacemakerLabel(name: string): string {
return name.length > PACEMAKER_NAME_LIMIT ? name : `PACEMAKER ${name}`;
}
/**
* The score graph's figures for a gameplay `runtime`: the player's EX score, the pacemaker's ({@link
* BeMusicGameplayRuntime.targetEXScore}, else the AAA line) and the best record's ({@link
* BeMusicGameplayRuntime.bestEXScore}), each held to the share of the chart's notes judged so far, as a pacemaker reads.
* A host that knows where its target stands now ({@link BeMusicGameplayRuntime.targetPaceEXScore}, a replay ghost) gives
* that in place of the share.
*/
export function resolveScorePace(
runtime: Pick<
BeMusicGameplayRuntime,
| 'exScore'
| 'exScoreMax'
| 'totalNotes'
| 'perfect'
| 'great'
| 'good'
| 'bad'
| 'poor'
| 'bestEXScore'
| 'targetEXScore'
| 'targetPaceEXScore'
| 'targetLabel'
>,
): ScorePace {
const exScore = runtime.exScore ?? 0;
const max = Math.max(0, runtime.exScoreMax ?? 0);
const total = runtime.totalNotes ?? 0;
const judged =
(runtime.perfect ?? 0) + (runtime.great ?? 0) + (runtime.good ?? 0) + (runtime.bad ?? 0) + (runtime.poor ?? 0);
const progress = total > 0 ? Math.min(1, judged / total) : 0;
const against = (label: string, score: number): ScorePaceTarget => {
const pace = Math.round(score * progress);
return { label, exScore: score, pace, diff: exScore - pace };
};
const hostTarget = runtime.targetEXScore !== undefined && runtime.targetEXScore > 0;
const hostPace = runtime.targetPaceEXScore;
return {
exScore,
max,
progress,
target: hostTarget
? hostPace !== undefined
? {
label: runtime.targetLabel ?? 'TARGET',
exScore: runtime.targetEXScore!,
pace: hostPace,
diff: exScore - hostPace,
}
: against(runtime.targetLabel ?? 'TARGET', runtime.targetEXScore!)
: against(runtime.targetLabel ?? 'AAA', aaaLine(max)),
...(runtime.bestEXScore !== undefined && runtime.bestEXScore > 0
? { best: against('MY BEST', runtime.bestEXScore) }
: {}),
};
}
/** A score difference as the graph shows it: a sign and four digits (`+0168`, `-0003`, `±0000`). */
export function formatScoreDiff(diff: number): string {
const digits = String(Math.abs(Math.trunc(diff))).padStart(4, '0');
return diff > 0 ? `+${digits}` : diff < 0 ? `-${digits}` : `±${digits}`;
}
const ORDINALS = ['1ST', '2ND', '3RD', '4TH', '5TH', '6TH', '7TH', '8TH', '9TH', '10TH'] as const;
/**
* What the stage band says: `1ST STAGE` … for a course stage, `FINAL STAGE` for its last, the course's title for a
* NONSTOP run (one stitched play), and `FREE PLAY` for a single chart (`PRACTICE PLAY` when `practice`).
*/
export function resolveStageLabel(
course: Pick<CourseView, 'kind' | 'title' | 'stages' | 'stageIndex'> | undefined,
practice = false,
): string {
if (!course) return practice ? 'PRACTICE PLAY' : 'FREE PLAY';
if (course.kind === 'nonstop' || course.stageIndex === undefined) return course.title;
if (course.stages.length > 1 && course.stageIndex === course.stages.length - 1) return 'FINAL STAGE';
return `${ORDINALS[course.stageIndex] ?? `${course.stageIndex + 1}TH`} STAGE`;
}
const DIFFICULTY_NAMES = ['BEGINNER', 'NORMAL', 'HYPER', 'ANOTHER', 'INSANE'] as const;
/**
* The mark a chart screen writes after an estimated difficulty's name, by its basis: `?` for one read from the chart's
* names (`HYPER?`), `??` for one beatoraja would give by the note count (`HYPER??`), which is right far less often.
*/
export const DIFFICULTY_BASIS_MARKS: Readonly<Record<DifficultyBasis, string>> = { chart: '', names: '?', notes: '??' };
/**
* The chart's difficulty by name (`BEGINNER` … `INSANE`) and where it comes from (`resolveLibraryChartDifficulty`):
* the chart's own `#DIFFICULTY`, its names or its note count. `UNSPECIFIED` with no basis when none gives one, or
* `undefined` without a chart.
*/
export function resolveDifficulty(
chart: LibraryChartDifficultySource | undefined,
): { name: string; basis?: DifficultyBasis } | undefined {
if (chart === undefined) return undefined;
const difficulty = resolveLibraryChartDifficulty(chart);
const name = difficulty !== undefined ? DIFFICULTY_NAMES[difficulty.value - 1] : undefined;
return name !== undefined ? { name, basis: difficulty!.basis } : { name: 'UNSPECIFIED' };
}
/**
* The chart's difficulty by name (`BEGINNER` … `INSANE`), followed by its basis mark when it was estimated
* ({@link DIFFICULTY_BASIS_MARKS}: `HYPER?` from the names, `HYPER??` from the note count); `UNSPECIFIED` when it has
* none, or `undefined` without a chart.
*/
export function resolveDifficultyName(chart: LibraryChartDifficultySource | undefined): string | undefined {
const difficulty = resolveDifficulty(chart);
return (
difficulty && `${difficulty.name}${difficulty.basis !== undefined ? DIFFICULTY_BASIS_MARKS[difficulty.basis] : ''}`
);
}
/** Turntable angle in radians: one clockwise revolution per four chart beats. */
export function resolveScratchAngle(
chartBeat: number,
input?: { angle: number; direction: 1 | -1; atMs: number },
nowMs = 0,
): number {
const beat = Number.isFinite(chartBeat) ? chartBeat : 0;
const offset =
input === undefined
? 0
: input.angle + input.direction * (Math.PI / 2) * (1 - Math.exp(-Math.max(0, nowMs - input.atMs) / 120));
const angle = beat * (Math.PI / 2) + offset;
return ((angle % (2 * Math.PI)) + 2 * Math.PI) % (2 * Math.PI);
}
/** Caption above a lane bank’s judgment; a replay ghost takes precedence over autoplay. */
export function resolveLanePlayLabel(
runtime: Pick<BeMusicGameplayRuntime, 'autoplay' | 'ghostSide'>,
side: '1P' | '2P',
): string | undefined {
return runtime.ghostSide === side ? 'GHOST PLAY' : runtime.autoplay ? 'AUTO PLAY' : undefined;
}
|