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 | 21x 21x | import {
resolveResultCourseCard,
resolveResultCourseScroll,
resolveResultLamp,
resolveResultPlayTag,
resolveResultTrackRows,
resolveStageOrientation,
type BeMusicResultData,
type BeMusicResultFrame,
type BeMusicSurface,
type ResultCourseCard,
resolveResultVerdict,
} from '@be-music/player-skin-sdk';
import { resolvePortraitResult } from './layout.ts';
import { ACCENT, DANGER, INK, MUTED, PANEL, stat, text } from './theme.ts';
const MARGIN = 16;
/**
* The result screen: verdict and rank, the score figures, the judgement counts, and the chart's facts — side by side on
* the landscape stage, stacked on the portrait one.
*/
export function drawResult(surface: BeMusicSurface<'2d'>, frame: BeMusicResultFrame): void {
const { context: ctx, width, height } = surface;
ctx.fillStyle = INK;
ctx.fillRect(0, 0, width, height);
if (resolveStageOrientation(surface) === 'portrait') {
drawPortraitResult(ctx, frame, width, height);
return;
}
const { result, nowMs } = frame;
text(ctx, resolveResultVerdict(result), MARGIN, 28, {
size: 20,
weight: 800,
color: result.cleared ? ACCENT : DANGER,
});
playTag(ctx, result, width - MARGIN, 28);
// Rank and rate.
ctx.fillStyle = PANEL;
ctx.fillRect(MARGIN, 60, 200, 160);
text(ctx, frame.rankLabel, MARGIN + 100, 130, { size: 56, weight: 800, align: 'center' });
text(ctx, `${frame.ratePercent.toFixed(2)}%`, MARGIN + 100, 196, { size: 14, color: MUTED, align: 'center' });
const lamp = resolveResultLamp(result);
text(ctx, lamp, MARGIN + 100, 80, {
size: 12,
weight: 800,
align: 'center',
color: lamp === 'FAILED' ? DANGER : ACCENT,
});
// Score figures in two rows of three.
scoreFigures(result).forEach(([label, value], index) => {
stat(ctx, label, value, 240 + (index % 3) * 130, 76 + Math.floor(index / 3) * 56, { maxWidth: 120, nowMs });
});
// Judgement counts.
judgeCounts(result).forEach(([label, count], index) => {
const y = 250 + index * 26;
text(ctx, label, MARGIN, y, { size: 12, color: MUTED, weight: 700 });
text(ctx, String(count), MARGIN + 200, y, { size: 14, align: 'right' });
});
// The chart, its facts, and the clear lamp on the right.
const x = width - MARGIN - 220;
ctx.fillStyle = PANEL;
ctx.fillRect(x, 60, 220, 330);
const course = resolveResultCourseCard(result);
if (course !== undefined) {
// A course run lists the charts it played in place of one chart's facts.
drawCourseCard(ctx, course, {
left: x + 14,
right: x + 206,
top: 78,
rowsY: 140,
bottom: 380,
nowMs,
elapsedMs: frame.shownMs,
});
} else {
// Genre, title, artist — the order every built-in skin uses.
const lift = result.chart.genre ? 12 : 0;
if (result.chart.genre) text(ctx, result.chart.genre, x + 14, 78, { size: 10, color: MUTED, maxWidth: 192, nowMs });
text(ctx, result.chart.title, x + 14, 82 + lift, { size: 14, weight: 800, maxWidth: 192, nowMs });
text(ctx, result.chart.artist ?? '', x + 14, 102 + lift, { size: 11, color: MUTED, maxWidth: 192, nowMs });
resolveResultTrackRows(result).forEach((row, index) => {
const y = 140 + index * 34;
text(ctx, row.label, x + 14, y, { size: 10, color: MUTED, weight: 700 });
text(ctx, row.value, x + 206, y, { size: 14, align: 'right', maxWidth: 120, nowMs });
});
}
// Between the 1P counts and the chart panel.
if (result.secondPlayer) drawSecondPlayer(ctx, result.secondPlayer, 240, 236, width - MARGIN - 220 - 16 - 240, nowMs);
}
/**
* The AUTO PLAY / ASSIST tag (`resolveResultPlayTag`) as an outlined badge, its right edge at `right` and its middle at
* `y`, on the verdict's line; nothing for a plain play.
*/
function playTag(ctx: CanvasRenderingContext2D, result: BeMusicResultData, right: number, y: number): void {
const tag = resolveResultPlayTag(result);
if (tag === undefined) return;
const color = tag === 'AUTO PLAY' ? DANGER : MUTED;
text(ctx, tag, right - 10, y, { size: 12, weight: 800, align: 'right', color });
const width = ctx.measureText(tag).width + 20;
ctx.strokeStyle = color;
ctx.lineWidth = 2;
ctx.strokeRect(right - width + 1, y - 12, width - 2, 24);
}
/**
* A two-player play's 2P result (LR2 BATTLE), between the 1P counts and the chart panel: its verdict, lamp, the
* figures and the judgement counts.
*/
function drawSecondPlayer(
ctx: CanvasRenderingContext2D,
result: BeMusicResultData,
x: number,
y: number,
w: number,
nowMs: number,
): void {
ctx.fillStyle = PANEL;
ctx.fillRect(x, y, w, 190);
const lamp = resolveResultLamp(result);
text(ctx, `2P ${resolveResultVerdict(result)}`, x + 14, y + 20, {
size: 14,
weight: 800,
color: result.cleared ? ACCENT : DANGER,
});
text(ctx, lamp, x + w - 14, y + 20, {
size: 12,
weight: 800,
align: 'right',
color: lamp === 'FAILED' ? DANGER : ACCENT,
});
const column = (w - 150) / 2;
scoreFigures(result)
.slice(0, 4)
.forEach(([label, value], index) => {
stat(ctx, label, value, x + 14 + (index % 2) * column, y + 46 + Math.floor(index / 2) * 56, {
maxWidth: column - 10,
nowMs,
});
});
judgeCounts(result).forEach(([label, count], index) => {
const rowY = y + 48 + index * 26;
text(ctx, label, x + w - 130, rowY, { size: 12, color: MUTED, weight: 700 });
text(ctx, String(count), x + w - 14, rowY, { size: 14, align: 'right' });
});
}
function scoreFigures(result: BeMusicResultData): Array<[string, string]> {
return [
['SCORE', String(result.score.score)],
['EX SCORE', `${result.score.exScore} / ${result.score.total * 2}`],
['MAX COMBO', String(result.maxCombo)],
['GAUGE', `${Math.round(result.gauge)}%`],
['PLAY TIME', `${result.playSeconds.toFixed(1)}s`],
['NOTES', String(result.score.total)],
];
}
function judgeCounts(result: BeMusicResultData): Array<[string, number]> {
return [
['PGREAT', result.score.perfect],
['GREAT', result.score.great],
['GOOD', result.score.good],
['BAD', result.score.bad],
['POOR', result.score.poor],
];
}
/**
* The portrait result: the same pieces as the landscape one, stacked (see {@link resolvePortraitResult}) — the verdict,
* the DJ LEVEL beside the score figures, the judgement counts, the chart with its facts and lamp, and the total.
*/
function drawPortraitResult(
ctx: CanvasRenderingContext2D,
frame: BeMusicResultFrame,
width: number,
height: number,
): void {
const { result, nowMs } = frame;
const grid = resolvePortraitResult(width, height);
text(ctx, resolveResultVerdict(result), grid.rank.x, grid.verdictY, {
size: 20,
weight: 800,
color: result.cleared ? ACCENT : DANGER,
});
playTag(ctx, result, width - MARGIN, grid.verdictY);
// Rank and rate.
const { rank } = grid;
ctx.fillStyle = PANEL;
ctx.fillRect(rank.x, rank.y, rank.w, rank.h);
text(ctx, frame.rankLabel, rank.x + rank.w / 2, rank.y + rank.h * 0.42, { size: 56, weight: 800, align: 'center' });
text(ctx, `${frame.ratePercent.toFixed(2)}%`, rank.x + rank.w / 2, rank.y + rank.h - 26, {
size: 14,
color: MUTED,
align: 'center',
});
const lamp = resolveResultLamp(result);
text(ctx, lamp, rank.x + rank.w / 2, grid.lampY, {
size: 14,
weight: 800,
align: 'center',
color: lamp === 'FAILED' ? DANGER : ACCENT,
});
// Score figures, two columns of three beside the rank.
scoreFigures(result).forEach(([label, value], index) => {
const box = grid.figures[index]!;
stat(ctx, label, value, box.x, box.y, { maxWidth: box.w - 10, nowMs, labelSize: 10 });
});
// Judgement counts, one row each across the panel.
const { judges } = grid;
ctx.fillStyle = PANEL;
ctx.fillRect(judges.x, judges.y, judges.w, judges.h);
judgeCounts(result).forEach(([label, count], index) => {
const y = grid.judgeRowsY + index * grid.rowPitch;
text(ctx, label, judges.x + 14, y, { size: 12, color: MUTED, weight: 700 });
text(ctx, String(count), judges.x + judges.w - 14, y, { size: 14, align: 'right' });
});
// The chart: genre, title, artist, its facts one per row, and the clear lamp at the foot.
const { track } = grid;
ctx.fillStyle = PANEL;
ctx.fillRect(track.x, track.y, track.w, track.h);
const left = track.x + 14;
const right = track.x + track.w - 14;
const textW = right - left;
const course = resolveResultCourseCard(result);
if (course !== undefined) {
// A course run lists the charts it played in place of one chart's facts.
drawCourseCard(ctx, course, {
left,
right,
top: track.y + 18,
rowsY: grid.trackRowsY - 8,
bottom: track.y + track.h - 8,
nowMs,
elapsedMs: frame.shownMs,
});
return;
}
const lift = result.chart.genre ? 12 : 0;
if (result.chart.genre) {
text(ctx, result.chart.genre, left, track.y + 18, { size: 10, color: MUTED, maxWidth: textW, nowMs });
}
text(ctx, result.chart.title, left, track.y + 24 + lift, { size: 16, weight: 800, maxWidth: textW, nowMs });
text(ctx, result.chart.artist ?? '', left, track.y + 46 + lift, { size: 11, color: MUTED, maxWidth: textW, nowMs });
resolveResultTrackRows(result).forEach((row, index) => {
const y = grid.trackRowsY + index * grid.rowPitch;
text(ctx, row.label, left, y, { size: 10, color: MUTED, weight: 700 });
text(ctx, row.value, right, y, { size: 14, align: 'right', maxWidth: textW - 120, nowMs });
});
}
/** How far apart the stages of a course card sit: a title line and an artist line. */
const COURSE_STAGE_PITCH = 34;
/**
* A course run's card in the chart panel: the course's kind, name and how far the run went (from `top`), then every
* stage chart in order — its number, title, level and artist — from `rowsY` down to `bottom`, each at its usual
* height. Stages past `bottom` are cut off, and the list scrolls up through them and starts over
* (`resolveResultCourseScroll`), fading out at the bottom and back in at the top, so every stage is shown in turn. A stage the run never reached is dimmed.
*/
function drawCourseCard(
ctx: CanvasRenderingContext2D,
course: ResultCourseCard,
area: { left: number; right: number; top: number; rowsY: number; bottom: number; nowMs: number; elapsedMs: number },
): void {
const { left, right, top, rowsY, bottom, nowMs } = area;
const textW = right - left;
text(ctx, course.kind, left, top, { size: 10, color: MUTED, weight: 700 });
text(ctx, course.title, left, top + 18, { size: 14, weight: 800, maxWidth: textW, nowMs });
text(ctx, course.detail, left, top + 38, { size: 11, color: MUTED, maxWidth: textW, nowMs });
// A row's title is centred 6 px under its top line and its artist 14 px under that, ending 21 px under the title.
const viewTop = rowsY - 4;
const contentBottom = rowsY + 6 + (course.stages.length - 1) * COURSE_STAGE_PITCH + 21;
const overflow = contentBottom - bottom;
const scroll = resolveResultCourseScroll(overflow, area.elapsedMs);
ctx.save();
ctx.beginPath();
ctx.rect(left - 2, viewTop, textW + 4, bottom - viewTop);
ctx.clip();
course.stages.forEach((stage, index) => {
const y = rowsY + 6 + index * COURSE_STAGE_PITCH - scroll.offsetPx;
if (y + 24 < viewTop || y - 16 > bottom) return;
ctx.globalAlpha = (stage.played ? 1 : 0.4) * scroll.alpha;
text(ctx, String(stage.stage), left, y, { size: 10, color: MUTED, weight: 700 });
text(ctx, stage.title, left + 16, y, { size: 12, weight: 700, maxWidth: textW - 16 - 30, nowMs });
text(ctx, stage.level, right, y, { size: 12, align: 'right', maxWidth: 26 });
if (stage.artist !== undefined) {
text(ctx, stage.artist, left + 16, y + 14, { size: 10, color: MUTED, maxWidth: textW - 16, nowMs });
}
});
ctx.globalAlpha = 1;
ctx.restore();
}
|