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 | 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x 21x | import {
clampHoldSparkX,
flashingGreatColor,
holdSeed,
holdSparks,
isFlashingGreat,
judgeDisplayWord,
resolveJudgeWordY,
resolveLanePlayLabel,
LOADING_WORD,
resolveLaneRuns,
type BeMusicGameplayFrame,
type BeMusicGameplayRuntime,
type BeMusicSurface,
backSpinChevron,
hellChargeZigzag,
findWhiteLaneWidth,
longNoteCentreLineAlpha,
resolveNoteHeight,
resolveHellChargeLook,
resolveLongNoteMarks,
resolveSongInfoLayers,
} from '@be-music/player-skin-sdk';
import {
ACCENT,
DANGER,
FLASHING_GREAT,
INK,
LANE_FILL,
LINE,
MUTED,
NOTE_FILL,
PANEL,
TEXT,
css,
drawSongInfoLayers,
stat,
tabularText,
text,
} from './theme.ts';
import { drawCabinetHUD } from './cabinet.ts';
import { resolvePortraitGameplayHUD } from './layout.ts';
/** LR2's opacity for a long note missed at the head or let go early (`0x80` of `0xff`). */
const DROPPED_LONG_NOTE_ALPHA = 0x80 / 0xff;
/** How opaque an LN's tail cap is: clearly the end of the note, but quieter than a cap to hit. */
const LN_TAIL_ALPHA = 0.4;
/** Top of the right-hand judgement column: level with the BGA band's top, whatever size the BGA takes. */
const COLUMN_TOP = 66;
const MARGIN = 16;
/**
* The play screen. Landscape: lanes and notes on the left, the BGA beside them, the HUD in the cabinet layout around
* them (`cabinet.ts`); the landscape touch layout, whose lanes take the stage, keeps a lighter HUD. Portrait: the host
* puts the lanes across the lower part of the stage and the BGA at the top left; the HUD fills the band above the lanes
* (see {@link resolvePortraitGameplayHUD}). The lanes, notes, bombs and BGA are drawn the same way in both — they come
* placed in `frame.layout` — so only the HUD and the judgement's height depend on `layout.orientation`.
*/
export function drawGameplay({ context: ctx, width, height }: BeMusicSurface<'2d'>, frame: BeMusicGameplayFrame): void {
const { layout, runtime } = frame;
const portrait = layout.orientation === 'portrait';
// Background. The BGA plays *behind* this canvas, so its rect is cut out rather than painted over.
ctx.fillStyle = INK;
ctx.fillRect(0, 0, width, height);
const bga = layout.bga;
if (bga) {
if (runtime.hasBGA) {
ctx.clearRect(bga.x, bga.y, bga.w, bga.h);
} else {
ctx.fillStyle = PANEL;
ctx.fillRect(bga.x, bga.y, bga.w, bga.h);
text(ctx, 'SOUND ONLY', bga.x + bga.w / 2, bga.y + bga.h / 2, { size: 12, color: MUTED, align: 'center' });
}
ctx.strokeStyle = LINE;
ctx.strokeRect(bga.x - 0.5, bga.y - 0.5, bga.w + 1, bga.h + 1);
}
drawLanes(ctx, frame);
drawNotes(ctx, frame);
drawHolds(ctx, frame);
drawBombs(ctx, frame);
if (portrait) {
const hud = resolvePortraitGameplayHUD(layout);
drawJudgement(ctx, frame, hud.judgeY);
drawPortraitHUD(ctx, frame, hud);
} else if (layout.mode === 'standard') {
const { top, judgementY } = layout.playfield;
drawJudgement(ctx, frame, Math.round(top + (judgementY - top) * CABINET_JUDGE_SHARE));
drawCabinetHUD(ctx, frame);
} else {
drawJudgement(ctx, frame, 220);
drawHUD(ctx, frame, width, height);
}
}
/** How far down the lanes the judgement word sits on the cabinet layout: low, just above the judgement line. */
const CABINET_JUDGE_SHARE = 0.68;
/** Lane backgrounds, a light column for each held key, and the judgement line. */
function drawLanes(ctx: CanvasRenderingContext2D, frame: BeMusicGameplayFrame): void {
for (const lane of frame.lanes) {
ctx.fillStyle = LANE_FILL[lane.kind];
ctx.fillRect(lane.x, lane.top, lane.w, lane.bottom - lane.top);
if (lane.beam > 0) {
// One gradient serves every lane; how bright the beam is comes from the alpha.
ctx.fillStyle = beamGradient(ctx, lane.top, lane.bottom);
ctx.globalAlpha = lane.beam;
ctx.fillRect(lane.x, lane.top, lane.w, lane.bottom - lane.top);
ctx.globalAlpha = 1;
}
if (lane.kind === 'wheel-up' || lane.kind === 'wheel-down') {
drawWheelArrow(ctx, lane.x + lane.w / 2, lane.bottom - 12, Math.min(4, lane.w / 3), lane.kind === 'wheel-up');
}
}
// One judgement line per play side, so it never crosses the gap between the double-play banks.
ctx.fillStyle = DANGER;
for (const run of resolveLaneRuns(frame.lanes)) {
const side = frame.layout.lanes.find((lane) => lane.x >= run.left && lane.x < run.right)?.side ?? '1P';
const y = frame.layout.playfield.sides[side]?.judgementY ?? frame.layout.playfield.judgementY;
ctx.fillRect(run.left, y, run.right - run.left, 2);
}
}
/** A small triangle under a wheel lane's notes, pointing the way that lane turns the wheel. */
function drawWheelArrow(ctx: CanvasRenderingContext2D, x: number, y: number, size: number, up: boolean): void {
const tip = up ? -size : size;
ctx.fillStyle = MUTED;
ctx.beginPath();
ctx.moveTo(x, y + tip);
ctx.lineTo(x - size, y - tip);
ctx.lineTo(x + size, y - tip);
ctx.closePath();
ctx.fill();
}
/** Strokes an open polyline given as `[x0, y0, x1, y1, …]`. */
function strokePolyline(ctx: CanvasRenderingContext2D, points: readonly number[]): void {
if (points.length < 4) return;
ctx.beginPath();
ctx.moveTo(points[0]!, points[1]!);
for (let index = 2; index < points.length; index += 2) ctx.lineTo(points[index]!, points[index + 1]!);
ctx.stroke();
}
/** Fills a closed polygon given as `[x0, y0, x1, y1, …]`. */
function fillPolygon(ctx: CanvasRenderingContext2D, points: readonly number[]): void {
ctx.beginPath();
ctx.moveTo(points[0]!, points[1]!);
for (let index = 2; index < points.length; index += 2) ctx.lineTo(points[index]!, points[index + 1]!);
ctx.closePath();
ctx.fill();
}
const BEAM_GRADIENTS = new WeakMap<
CanvasRenderingContext2D,
{ top: number; bottom: number; gradient: CanvasGradient }
>();
/** The key-beam gradient (clear at the top, blue at the judgement line), made once per context and lane height. */
function beamGradient(ctx: CanvasRenderingContext2D, top: number, bottom: number): CanvasGradient {
const cached = BEAM_GRADIENTS.get(ctx);
if (cached && cached.top === top && cached.bottom === bottom) return cached.gradient;
const gradient = ctx.createLinearGradient(0, top, 0, bottom);
gradient.addColorStop(0, 'rgba(61, 123, 255, 0)');
gradient.addColorStop(1, 'rgba(61, 123, 255, 0.45)');
BEAM_GRADIENTS.set(ctx, { top, bottom, gradient });
return gradient;
}
/**
* Tap notes as flat bars. Long notes: a translucent body with a white centre line between the head and tail bars; an
* LN's tail (not judged) is translucent, a CN / HCN tail (judged on release) solid. An HCN's centre line zigzags and it
* shows how it stands (HELL violet before it is reached, an orange glow while held, a dim red while let go), a back-spin
* scratch's tail a chevron pointing back up the lane. A long note missed at the head or let go early draws at LR2's half
* alpha.
*/
function drawNotes(ctx: CanvasRenderingContext2D, frame: BeMusicGameplayFrame): void {
const whiteLaneWidth = findWhiteLaneWidth(frame.lanes);
for (const note of frame.longNotes) {
const alpha = (note.state === 'dropped' ? DROPPED_LONG_NOTE_ALPHA : 1) * (note.alpha ?? 1);
// A note is as tall as a share of its lane's width (every note as a white key's), standing on its bottom edge.
const noteHeight = resolveNoteHeight(note.w, whiteLaneWidth);
const bodyTop = note.top - noteHeight;
const bodyHeight = Math.max(1, note.bottom - note.top);
const marks = resolveLongNoteMarks(note);
// A hell charge note shows how it stands: colour, glow and zigzag motion change together (`resolveHellChargeLook`).
const look = marks.hellCharge ? resolveHellChargeLook(note.state, frame.nowMs) : undefined;
if (look) {
ctx.fillStyle = css(look.color);
if (look.glow > 0) {
ctx.globalAlpha = 0.3 * look.glow * alpha;
ctx.fillRect(note.x - 3, bodyTop, note.w + 6, bodyHeight);
ctx.fillRect(note.x - 3, note.bottom - noteHeight - 3, note.w + 6, noteHeight + 6);
}
ctx.globalAlpha = (0.2 + 0.3 * look.glow) * alpha;
ctx.fillRect(note.x + 1, bodyTop, note.w - 2, bodyHeight);
} else {
ctx.fillStyle = NOTE_FILL[note.kind];
ctx.globalAlpha = 0.25 * alpha;
ctx.fillRect(note.x + 1, bodyTop, note.w - 2, bodyHeight);
}
// Let go early, the centre line fades out with the hold.
const line = longNoteCentreLineAlpha(note.releasedElapsedMs);
if (look) {
// A hell charge note's centre line zigzags: flowing into the judgement line while it charges, back up while it
// drains, still otherwise.
ctx.strokeStyle = css(look.lineColor);
ctx.lineWidth = 2;
ctx.globalAlpha = (0.55 + 0.45 * look.glow) * alpha * line;
strokePolyline(
ctx,
hellChargeZigzag(note.x, note.w, bodyTop, bodyTop + bodyHeight, { nowMs: frame.nowMs, flow: look.flow }),
);
} else {
ctx.fillStyle = '#ffffff';
ctx.globalAlpha = 0.6 * alpha * line;
ctx.fillRect(note.x + note.w / 2 - 1, bodyTop, 2, bodyHeight);
}
ctx.globalAlpha = alpha;
ctx.fillStyle = NOTE_FILL[note.kind];
ctx.fillRect(note.x, note.bottom - noteHeight, note.w, noteHeight);
// An LN's tail is not judged: drawn translucent, where to let go. A CN / HCN tail is judged and stays solid.
if (!marks.judgedTail) ctx.globalAlpha = alpha * LN_TAIL_ALPHA;
ctx.fillRect(note.x, note.top - noteHeight, note.w, noteHeight);
if (marks.backSpin) {
ctx.globalAlpha = alpha;
ctx.fillStyle = '#ffffff';
fillPolygon(ctx, backSpinChevron(note.x, note.w, note.top, noteHeight));
}
ctx.globalAlpha = 1;
}
for (const note of frame.notes) {
const noteHeight = resolveNoteHeight(note.w, whiteLaneWidth);
ctx.globalAlpha = note.alpha ?? 1;
ctx.fillStyle = NOTE_FILL[note.kind];
ctx.fillRect(note.x, note.y - noteHeight, note.w, noteHeight);
ctx.globalAlpha = 1;
}
}
/**
* While a long note is held, its lane's stretch of the judgement line glows (a slow pulse) and sparks keep rising
* from it, so a held note reads as held at a glance. Drawn from the hold's age alone, like every effect here.
*/
function drawHolds(ctx: CanvasRenderingContext2D, frame: BeMusicGameplayFrame): void {
for (const lane of frame.lanes) {
if (lane.holding !== true || lane.holdStartedAtMs === undefined) continue;
const y = lane.bottom;
const ageMs = frame.nowMs - lane.holdStartedAtMs;
const centerX = lane.x + lane.w / 2;
ctx.fillStyle = HOLD_GLOW;
ctx.globalAlpha = 0.55 + 0.25 * Math.sin(ageMs / 90);
ctx.fillRect(lane.x, y - 3, lane.w, 6);
ctx.fillStyle = '#ffffff';
// The sparks stay on the held note, under its end and inside its width, so the end stays easy to see.
const maxRise = lane.holdTop === undefined ? undefined : y - lane.holdTop - PLAIN_SPARK_MAX / 2;
for (const spark of holdSparks(ageMs, holdSeed(lane.channel, lane.holdStartedAtMs), lane.w, { maxRise })) {
ctx.globalAlpha = spark.alpha;
const size = spark.size * 1.6;
const x = clampHoldSparkX(centerX + spark.offsetX, size, lane.x, lane.w);
ctx.fillRect(x - size / 2, y - spark.rise - size / 2, size, size);
}
ctx.globalAlpha = 1;
}
}
/** Largest spark Plain draws (`holdSparks`' largest, 3.5 px, at 1.6x). */
const PLAIN_SPARK_MAX = 3.5 * 1.6;
/** The held lane's glow on the judgement line: the key beam's blue, brighter. */
const HOLD_GLOW = 'rgb(120, 170, 255)';
/** Each hit draws a ring that widens and fades over the effect's lifetime. */
function drawBombs(ctx: CanvasRenderingContext2D, frame: BeMusicGameplayFrame): void {
for (const bomb of frame.bombs) {
const t = Math.min(1, bomb.elapsedMs / 300);
ctx.strokeStyle = `rgba(255, 255, 255, ${1 - t})`;
ctx.lineWidth = 2;
ctx.beginPath();
ctx.arc(bomb.x + bomb.w / 2, bomb.y, 6 + 18 * t, 0, Math.PI * 2);
ctx.stroke();
}
}
/** The latest judgement and combo over each play side, centred on `y` — or NOW LOADING while the chart loads. */
function drawJudgement(ctx: CanvasRenderingContext2D, frame: BeMusicGameplayFrame, skinY: number): void {
const { runtime, layout, nowMs } = frame;
const y = resolveJudgeWordY(skinY, layout.playfield);
if (runtime.loading) {
const x = layout.playfield.left + 12;
const width = Math.min(180, layout.playfield.right - x - 12);
text(ctx, LOADING_WORD, x, y, { size: 13, color: MUTED, maxWidth: width });
ctx.fillStyle = LINE;
ctx.fillRect(x, y + 18, width, 4);
ctx.fillStyle = ACCENT;
ctx.fillRect(x, y + 18, width * (runtime.loadingProgress ?? 0), 4);
return;
}
for (const side of ['1P', '2P'] as const) {
const bounds = layout.playfield.sides[side];
const mode = resolveLanePlayLabel(runtime, side);
if (!bounds || !mode) continue;
text(
ctx,
mode,
(bounds.left + bounds.right) / 2,
y + ((bounds.judgementY ?? layout.playfield.judgementY) - layout.playfield.judgementY) - 28,
{ size: 10, color: MUTED, align: 'center', maxWidth: bounds.right - bounds.left - 12 },
);
}
for (const side of runtime.judgeSides ?? []) {
if (!side.judge) continue;
const bounds = layout.playfield.sides[side.side];
const sideY = y + ((bounds?.judgementY ?? layout.playfield.judgementY) - layout.playfield.judgementY);
const x = bounds ? (bounds.left + bounds.right) / 2 : layout.playfield.centerX;
const color = isFlashingGreat(side.judge) ? css(flashingGreatColor(nowMs, FLASHING_GREAT)) : judgeColor(side.judge);
text(ctx, judgeDisplayWord(side.judge), x, sideY, { size: 20, weight: 800, color, align: 'center' });
const combo = side.combo ?? 0;
const keepsCombo = side.judge === 'PERFECT' || side.judge === 'GREAT' || side.judge === 'GOOD';
if (keepsCombo && combo > 0) text(ctx, String(combo), x, sideY + 24, { size: 16, align: 'center' });
// The judge detail above the word: FAST / SLOW or the offset, the keys' and the scratch's side by side when apart.
const details = side.details ?? [];
const detailY = sideY - (resolveLanePlayLabel(runtime, side.side) ? 44 : 22);
details.forEach((detail, index) => {
const spread = details.length > 1 ? (index - (details.length - 1) / 2) * JUDGE_DETAIL_SPREAD : 0;
tabularText(
ctx,
detail.lane === undefined ? detail.text : `${JUDGE_DETAIL_LANES[detail.lane]} ${detail.text}`,
x + spread,
detailY,
{ size: 10, weight: 700, color: JUDGE_DETAIL_COLORS[detail.tone], align: 'center' },
);
});
}
}
/** The judge detail's colours, and the names the keys' and the scratch's lead with when they are shown apart. */
const JUDGE_DETAIL_COLORS = { fast: ACCENT, slow: DANGER, just: TEXT } as const;
const JUDGE_DETAIL_LANES = { keys: 'KEY', scratch: 'SCR' } as const;
const JUDGE_DETAIL_SPREAD = 84;
function judgeColor(judge: string): string {
if (judge === 'GOOD') return ACCENT;
if (judge === 'BAD' || judge === 'POOR') return DANGER;
return TEXT;
}
/**
* Header (mode, tempo, speed) over the BGA, the gauge under the lanes, the track and the score figures along the bottom.
* The lanes run from the stage's top, so the header starts at the BGA's left edge, clear of them; the gauge and the track
* share the lanes' left edge.
*/
function drawHUD(ctx: CanvasRenderingContext2D, frame: BeMusicGameplayFrame, width: number, height: number): void {
const { runtime, nowMs, layout } = frame;
const { playfield } = layout;
const headerX = layout.bga?.x ?? playfield.right + MARGIN;
const left = playfield.left;
text(ctx, runtime.autoplay ? 'AUTO PLAY' : 'PLAY', headerX, 18, { size: 12, weight: 800, color: ACCENT });
text(
ctx,
`BPM ${Math.round(runtime.bpm ?? 0)} ${runtime.floatingHiSpeed ? 'FHS' : 'SPEED'} x${(runtime.hiSpeed ?? 0).toFixed(runtime.floatingHiSpeed ? 2 : 1)}`,
headerX + 94,
18,
{
size: 12,
color: MUTED,
},
);
// Gauge: a bar under the lanes with a tick at the clear line. A two-player play draws each player's under its lanes.
const second = runtime.secondPlayer;
const side1P = frame.layout.playfield.sides['1P'];
const side2P = frame.layout.playfield.sides['2P'];
if (second && side1P && side2P) {
drawGauge(ctx, runtime, side1P.left, 372, side1P.right - side1P.left, 9, '1P ');
drawGauge(ctx, second, side2P.left, 372, side2P.right - side2P.left, 9, '2P ');
} else drawGauge(ctx, runtime, left, 372, playfield.right - left, 9);
// Track, bottom left.
// Genre, title, artist — the order every built-in skin uses.
drawSongInfoLayers(ctx, resolveSongInfoLayers(runtime), (info) => {
if (info.chartGenre) {
text(ctx, info.chartGenre, left, height - 70, { size: 10, color: MUTED, maxWidth: 380, nowMs });
}
text(ctx, info.chartTitle ?? '', left, height - 50, { size: 16, weight: 700, maxWidth: 380, nowMs });
text(ctx, info.chartArtist ?? '', left, height - 28, { size: 11, color: MUTED, maxWidth: 380, nowMs });
});
// Score figures, bottom right, in one row (the 2P player's row above the 1P player's).
scoreFigures(runtime).forEach(([label, value], index) => {
stat(ctx, second ? `1P ${label}` : label, value, width - MARGIN - 400 + index * 106, height - 56, {
maxWidth: 98,
nowMs,
});
});
if (second) {
scoreFigures(second).forEach(([label, value], index) => {
stat(ctx, `2P ${label}`, value, width - MARGIN - 400 + index * 106, height - 104, { maxWidth: 98, nowMs });
});
}
// Judgement counts down the right edge, beside the BGA; a two-player play adds the 2P player's counts beside them.
const columnX = width - MARGIN - 80;
// The player turned the judgment counts off.
if (runtime.hidesJudgeCounts) return;
judgeCounts(runtime).forEach(([label, count], index) => {
const y = COLUMN_TOP + index * 22;
text(ctx, label, columnX, y, { size: 11, color: MUTED, weight: 700 });
text(ctx, String(count ?? 0), columnX + (second ? 44 : 80), y, { size: 13, align: 'right' });
});
if (second) {
text(ctx, '1P', columnX + 44, COLUMN_TOP - 22, { size: 10, color: MUTED, weight: 700, align: 'right' });
text(ctx, '2P', columnX + 80, COLUMN_TOP - 22, { size: 10, color: MUTED, weight: 700, align: 'right' });
judgeCounts(second).forEach(([, count], index) => {
text(ctx, String(count ?? 0), columnX + 80, COLUMN_TOP + index * 22, { size: 13, align: 'right' });
});
}
}
/** The gauge bar (`y` its top, 8 px tall) with a tick at the clear line, its label and percentage on the line above. */
function drawGauge(
ctx: CanvasRenderingContext2D,
runtime: Pick<BeMusicGameplayRuntime, 'gauge' | 'clearThreshold' | 'gaugeLabel'>,
x: number,
y: number,
w: number,
labelSize: number,
prefix = '',
): void {
const gauge = Math.max(0, Math.min(100, runtime.gauge ?? 0));
const clear = runtime.clearThreshold ?? 80;
text(ctx, `${prefix}${runtime.gaugeLabel ?? 'GROOVE'} GAUGE`, x, y - 10, {
maxWidth: w - 48,
size: labelSize,
color: MUTED,
weight: 700,
});
text(ctx, `${Math.round(gauge)}%`, x + w, y - 10, { size: 12, align: 'right' });
ctx.fillStyle = PANEL;
ctx.fillRect(x, y, w, 8);
ctx.fillStyle = gauge >= clear ? DANGER : ACCENT;
ctx.fillRect(x, y, (w * gauge) / 100, 8);
ctx.fillStyle = TEXT;
ctx.fillRect(x + (w * clear) / 100, y - 3, 1, 14);
}
/** SCORE, EX SCORE, COMBO, RANK — the figures both HUDs show. */
function scoreFigures(
runtime: Pick<BeMusicGameplayRuntime, 'score' | 'exScore' | 'exScoreMax' | 'combo' | 'rank'>,
): Array<[string, string]> {
return [
['SCORE', String(runtime.score ?? 0)],
['EX SCORE', `${runtime.exScore ?? 0}/${runtime.exScoreMax ?? 0}`],
['COMBO', String(runtime.combo ?? 0)],
['RANK', runtime.rank ?? '-'],
];
}
/** The judgement counts, abbreviated. */
function judgeCounts(
runtime: Pick<BeMusicGameplayRuntime, 'perfect' | 'great' | 'good' | 'bad' | 'poor'>,
): Array<[string, number | undefined]> {
return [
['PG', runtime.perfect],
['GR', runtime.great],
['GD', runtime.good],
['BD', runtime.bad],
['PR', runtime.poor],
];
}
/**
* The portrait HUD, everything above the lanes: the header band (mode, tempo, speed — clear of the top corners, where a
* host may put its pause button and menu), the column beside the BGA (track, score figures, judgement counts), and the
* gauge across the stage just above the lanes. Nothing is smaller than 10 px.
*/
function drawPortraitHUD(
ctx: CanvasRenderingContext2D,
frame: BeMusicGameplayFrame,
hud: ReturnType<typeof resolvePortraitGameplayHUD>,
): void {
const { runtime, nowMs } = frame;
const { header, track, scores, counts, gauge } = hud;
const headerY = header.height / 2;
text(ctx, runtime.autoplay ? 'AUTO PLAY' : 'PLAY', header.left, headerY, { size: 14, weight: 800, color: ACCENT });
text(
ctx,
`BPM ${Math.round(runtime.bpm ?? 0)} ${runtime.floatingHiSpeed ? 'FHS' : 'SPEED'} x${(runtime.hiSpeed ?? 0).toFixed(runtime.floatingHiSpeed ? 2 : 1)}`,
header.right,
headerY,
{
size: 14,
color: MUTED,
align: 'right',
maxWidth: header.right - header.left - 100,
},
);
// Genre, title, artist — the order every built-in skin uses — at the top of the column.
const textW = track.w;
drawSongInfoLayers(ctx, resolveSongInfoLayers(runtime), (info) => {
const lift = info.chartGenre ? 12 : 0;
if (info.chartGenre) {
text(ctx, info.chartGenre, track.x, track.y + 8, { size: 14, color: MUTED, maxWidth: textW, nowMs });
}
text(ctx, info.chartTitle ?? '', track.x, track.y + 14 + lift, { size: 20, weight: 700, maxWidth: textW, nowMs });
text(ctx, info.chartArtist ?? '', track.x, track.y + 34 + lift, {
size: 14,
color: MUTED,
maxWidth: textW,
nowMs,
});
});
// Score figures, two by two.
scoreFigures(runtime).forEach(([label, value], index) => {
const box = scores[index]!;
text(ctx, label, box.x, box.y, { size: 14, color: MUTED, weight: 700 });
text(ctx, value, box.x, box.y + 20, { size: 22, weight: 700, maxWidth: box.w - 8, nowMs });
});
// Judgement counts in one row: label over count. None when the player turned them off.
(runtime.hidesJudgeCounts ? [] : judgeCounts(runtime)).forEach(([label, count], index) => {
const box = counts[index]!;
text(ctx, label, box.x, box.y, { size: 14, color: MUTED, weight: 700 });
text(ctx, String(count ?? 0), box.x, box.y + 16, { size: 18, maxWidth: box.w - 6 });
});
const second = runtime.secondPlayer;
if (second) {
// Two players share the gauge band: 1P on the left half, 2P on the right.
const half = (gauge.w - 12) / 2;
drawGauge(ctx, runtime, gauge.x, gauge.y, half, 10, '1P ');
drawGauge(ctx, second, gauge.x + half + 12, gauge.y, half, 10, '2P ');
} else drawGauge(ctx, runtime, gauge.x, gauge.y, gauge.w, 10);
}
|