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 | 42x 59x 57x 3x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 25x 25x 25x 20x 20x 20x 20x 20x 2x 1x 2x 1x 1x 1x 1x 1x 2x 1x 1x 1x 1x 1x 1x 1x 1x 11x 11x 10x 1x 1x 8x 2x 21x 21x 21x 1x 1x 3x 2x 2x 6x 6x 59x 59x 26x 11x 2x 18x 12x 12x 4x 4x 12x 12x 12x 7x 4x 3x | import { resolveClearLamp, resolve____RankIndexFromScore } from '@be-music/player-engine/ruleset';
import {
isAutoPlayResult,
resolveLibraryChartDifficultyValue,
type CourseView,
type PlayResult,
} from '@be-music/player-scene-model';
import { LR2_NUM, LR2_OP, LR2_TEXT, LR2_TIMER } from '../ids/index.ts';
import { resolveLR2ChartText, resolveLR2DifficultyOp, resolveLR2KeyModeOp } from './chart.ts';
import { resolveLR2CourseNumber, resolveLR2CourseOps, resolveLR2CourseText } from './course.ts';
import { resolveLR2LampOp } from './records.ts';
import { resolveLR2RateNumber } from './score.ts';
import type { LR2SceneState } from './scene-state.ts';
/** What the LR2 result screen shows: a play's result, the course it belongs to, and the skins' facts. */
export interface LR2ResultInput {
/** The result of the play (a single play, a course stage, a course run or a NONSTOP run). */
readonly result: PlayResult;
/** The course the result belongs to: a stage of a running course (with its `stageIndex`) or a whole course run. */
readonly course?: CourseView;
/** Whether the play skin declared `#FLIPRESULT` (op 351; 350 otherwise). */
readonly flipResult?: boolean;
/** The result skin's `#CUSTOMOPTION` choices: their ops (900-999). */
readonly customOps?: Iterable<number>;
}
/** The LR2 result screen's state: a {@link LR2SceneState} and the fill of each bar graph. */
export interface LR2ResultState extends LR2SceneState {
/** How full a `#SRC_BARGRAPH` of this `type` is, 0..1; `undefined` leaves it undrawn. */
bargraph(type: number): number | undefined;
}
/**
* Ops the result screen always lights: no GHOST, score graph, live BGA, difficulty filter, internet ranking, auto scratch
* or score saving; the normal gauges.
*/
const RESULT_BASE_OPS: readonly number[] = [
LR2_OP.GHOST_OFF,
LR2_OP.SCORE_GRAPH_OFF,
LR2_OP.BGA_OFF,
LR2_OP.GAUGE_1P_NORMAL,
LR2_OP.GAUGE_2P_NORMAL,
LR2_OP.DIFFICULTY_FILTER_OFF,
LR2_OP.OFFLINE,
LR2_OP.AUTO_SCRATCH_1P_OFF,
LR2_OP.AUTO_SCRATCH_2P_OFF,
LR2_OP.SCORE_SAVE_OFF,
LR2_OP.CLEAR_SAVE_OFF,
LR2_OP.LOADED,
];
/**
* The key-config op (400-402) for a key-mode op: 7 / 14 KEYS share 400, 9 KEYS is 401, 5 / 10 KEYS share 402. The
* stock result skin gates its per-key-mode panels on these.
*/
function keyConfigOp(keyModeOp: number): number {
if (keyModeOp === LR2_OP.KEYS_9) return LR2_OP.KEY_CONFIG_9;
if (keyModeOp === LR2_OP.KEYS_5 || keyModeOp === LR2_OP.KEYS_10) return LR2_OP.KEY_CONFIG_5_10;
return LR2_OP.KEY_CONFIG_7_14;
}
/**
* The play's rank, 0 AAA … 7 F, by its EX score; AAA for a chart without notes, so the rank panel still draws
* something.
*/
function rankIndex(result: PlayResult): number {
return resolve____RankIndexFromScore(result.score) ?? 0;
}
function resultOps(input: LR2ResultInput): number[] {
const { result } = input;
const ops = [...RESULT_BASE_OPS];
for (const op of input.customOps ?? []) ops.push(op);
ops.push(result.cleared ? LR2_OP.RESULT_CLEAR : LR2_OP.RESULT_FAIL);
// LR2 keeps its replay status through the results of a replay (a course replay's too, OpenLR2 L4740-L4741).
ops.push(result.fromReplay === true ? LR2_OP.REPLAY_PLAYING : LR2_OP.REPLAY_OFF);
// AUTOPLAY is the play's mode, kept through its results as the replay status is.
ops.push(isAutoPlayResult(result) ? LR2_OP.AUTOPLAY_ON : LR2_OP.AUTOPLAY_OFF);
// The result is always on a chart.
ops.push(LR2_OP.SONG_BAR, LR2_OP.PLAYABLE_BAR);
// The key mode in both ranges, as skins gate on either.
const keyModeOp = resolveLR2KeyModeOp(result.chart);
ops.push(keyModeOp, keyConfigOp(keyModeOp));
// A chart without a difficulty reads NORMAL here: the stock skin ships per-difficulty panels for 152-155 only.
const difficultyOp = resolveLR2DifficultyOp(resolveLibraryChartDifficultyValue(result.chart));
ops.push(difficultyOp === LR2_OP.DIFFICULTY_UNDEFINED ? LR2_OP.DIFFICULTY_NORMAL : difficultyOp);
// The play's lamp, else the one clear-lamp rule over its result.
const lamp =
result.lamp ??
resolveClearLamp({
cleared: result.cleared,
score: result.score,
...(result.gaugeType !== undefined ? { gauge: result.gaugeType } : {}),
...(result.judgeRuleset !== undefined ? { ruleset: result.judgeRuleset } : {}),
});
ops.push(resolveLR2LampOp(lamp));
// The rank now and after the update (300-308 / 340-347); without score history there was no rank before (328) and
// every play updates the best score, max combo, BP and rank (330-335).
const rank = rankIndex(result);
ops.push(LR2_OP.RESULT_RANK_AAA + rank, LR2_OP.UPDATED_RANK_AAA + rank, LR2_OP.PREVIOUS_RANK_0);
ops.push(LR2_OP.SCORE_UPDATED, LR2_OP.MAX_COMBO_UPDATED, LR2_OP.MIN_BP_UPDATED, LR2_OP.RANK_UPDATED);
ops.push(input.flipResult === true ? LR2_OP.RESULT_FLIP_ON : LR2_OP.RESULT_FLIP_OFF);
if (input.course !== undefined) ops.push(...resolveLR2CourseOps(input.course));
return ops;
}
/**
* A result's numbers. Without score history the best record's numbers (70-89) read this play's, and before / after
* (170-184) read nothing before it: 0, or every note BAD for the fewest BAD + POOR, so the difference shows an
* improvement.
*/
function resultNumber(num: number, result: PlayResult): number | undefined {
const { score } = result;
const rateNumber = resolveLR2RateNumber(num, score);
if (rateNumber !== undefined) return rateNumber;
const totalNotes = score.total;
const exMax = totalNotes * 2;
const minBp = score.bad + score.poor;
// The best record's rates as LR2 draws them: whole percents, truncated (OpenLR2 `SetObjectValue_Num` 73, 85-89).
const percentOfNotes = (count: number): number => (totalNotes > 0 ? Math.floor((count * 100) / totalNotes) : 0);
switch (num) {
case LR2_NUM.BEST_SCORE:
case LR2_NUM.SCORE:
return score.score;
case LR2_NUM.BEST_EXSCORE:
case LR2_NUM.EXSCORE:
case LR2_NUM.RESULT_EXSCORE:
case LR2_NUM.RESULT_EXSCORE_DIFF:
return score.exScore;
case LR2_NUM.EXSCORE_MAX:
return exMax;
case LR2_NUM.BEST_RATE:
return exMax > 0 ? Math.floor((score.exScore * 100) / exMax) : 0;
case LR2_NUM.TOTAL_NOTES:
case LR2_NUM.NOTES:
return totalNotes;
case LR2_NUM.BEST_MAX_COMBO:
case LR2_NUM.MAX_COMBO:
case LR2_NUM.RESULT_MAX_COMBO:
case LR2_NUM.RESULT_MAX_COMBO_DIFF:
return result.maxCombo;
case LR2_NUM.COMBO:
// No running combo on the result: the stock skin's max-combo panel falls back to number 104.
return result.maxCombo;
case LR2_NUM.BEST_MIN_BP:
case LR2_NUM.RESULT_MIN_BP:
return minBp;
case LR2_NUM.PLAY_COUNT:
case LR2_NUM.CLEAR_COUNT:
case LR2_NUM.FAIL_COUNT:
case LR2_NUM.RESULT_EXSCORE_BEFORE:
case LR2_NUM.RESULT_MAX_COMBO_BEFORE:
case LR2_NUM.RESULT_RATE_BEFORE:
case LR2_NUM.RESULT_RATE_BEFORE_AFTERDOT:
return 0;
case LR2_NUM.BEST_PERFECT:
case LR2_NUM.PERFECT:
return score.perfect;
case LR2_NUM.BEST_GREAT:
case LR2_NUM.GREAT:
return score.great;
case LR2_NUM.BEST_GOOD:
case LR2_NUM.GOOD:
return score.good;
case LR2_NUM.BEST_BAD:
case LR2_NUM.BAD:
return score.bad;
case LR2_NUM.BEST_POOR:
case LR2_NUM.POOR:
return score.poor;
case LR2_NUM.BEST_PERFECT_RATE:
return percentOfNotes(score.perfect);
case LR2_NUM.BEST_GREAT_RATE:
return percentOfNotes(score.great);
case LR2_NUM.BEST_GOOD_RATE:
return percentOfNotes(score.good);
case LR2_NUM.BEST_BAD_RATE:
return percentOfNotes(score.bad);
case LR2_NUM.BEST_POOR_RATE:
return percentOfNotes(score.poor);
case LR2_NUM.MAX_BPM:
case LR2_NUM.MIN_BPM:
return result.chart.bpm ?? result.chart.chart.metadata.bpm;
case LR2_NUM.GAUGE:
return Math.round(result.gauge);
case LR2_NUM.PLAY_MINUTE:
return Math.floor(result.playSeconds / 60);
case LR2_NUM.PLAY_SECOND:
return Math.floor(result.playSeconds % 60);
case LR2_NUM.LOADING_PROGRESS:
return 100;
case LR2_NUM.RESULT_MIN_BP_BEFORE:
return totalNotes;
case LR2_NUM.RESULT_MIN_BP_DIFF:
return Math.max(0, totalNotes - minBp);
default:
return undefined;
}
}
function resultText(st: number, input: LR2ResultInput): string | undefined {
const courseText = input.course !== undefined ? resolveLR2CourseText(st, input.course) : undefined;
if (courseText !== undefined) return courseText;
switch (st) {
case LR2_TEXT.RIVAL:
return 'TARGET';
case LR2_TEXT.PLAYER:
return 'PLAYER';
case LR2_TEXT.TITLE_ALT:
// LR2 reuses text 20 for the internet ranking's message once a play is saved (OpenLR2 `SaveResult` clears it,
// `ProcI_Result` sets it): with no internet ranking there is none.
return '';
default:
return resolveLR2ChartText(st, input.result.chart);
}
}
function resultProgress(result: PlayResult): number | undefined {
return result.chartSeconds && result.chartSeconds > 0
? Math.max(0, Math.min(1, result.playSeconds / result.chartSeconds))
: undefined;
}
/**
* How full a result `#SRC_BARGRAPH` of `type` is, as LR2 fills it (OpenLR2 `SetObjectValue_Bargraph`, `LR2f.cpp`
* L6814-L6990): 1 the play's progress, 2 loading (done), 10 the EX score rate, 11 the rate over the notes judged so far,
* 14 the 2P player's EX score rate in a BATTLE play, 20-25 the 1P judgement counts and max combo over the notes, 26 the
* money score, 27 the EX score, and 30-37 the same for the 2P player. Types 12 / 13 (the best record) and 14 / 15 (the
* target) outside BATTLE stay undrawn: the result carries no score history and no target, and a native type never
* stands in for another statistic. Select-screen types (3-9) and any other are undrawn too.
*/
function resultBargraph(type: number, result: PlayResult): number | undefined {
const score = result.score;
const ratio = (value: number, max: number) => (max > 0 ? Math.max(0, Math.min(1, value / max)) : 0);
switch (type) {
case 1:
return resultProgress(result);
case 2:
return 1;
case 10:
case 27:
return ratio(score.exScore, score.total * 2);
case 11: {
const judged = score.perfect + score.great + score.good + score.bad + (result.judgedPoor ?? score.poor);
return judged > 0 ? ratio(score.exScore, judged * 2) : undefined;
}
case 14:
return result.secondPlayer ? resultBargraph(10, result.secondPlayer) : undefined;
case 20:
return ratio(score.perfect, score.total);
case 21:
return ratio(score.great, score.total);
case 22:
return ratio(score.good, score.total);
case 23:
return ratio(score.bad, score.total);
case 24:
return ratio(score.poor, score.total);
case 25:
return ratio(result.maxCombo, score.total);
case 26:
return result.judgeRuleset === 'lr2' ? ratio(score.score, 200000) : undefined;
// The best record (12 / 13) and the target (15) need score history the result does not carry.
case 12:
case 13:
case 15:
return undefined;
default:
// The 2P player's counts, max combo, score and EX score (30-37 mirror 20-27).
return type >= 30 && type <= 37 && result.secondPlayer
? resultBargraph(type - 10, result.secondPlayer)
: undefined;
}
}
/**
* The LR2 result screen's state for a play's result: the result ops (cleared / failed, the chart's key mode in the
* select and key-config ranges, its difficulty, the lamp, the ranks and updates, the result flip, the course), the
* numbers (this play's score, counts, rates, combo, gauge and time, and the best-record and before / after numbers
* read off it), the chart's and the course's texts, and the bar graphs and the play progress slider.
*/
export function resolveLR2ResultState(input: LR2ResultInput): LR2ResultState {
const { result, course } = input;
return {
ops: new Set(resultOps(input)),
number: (num) =>
(course !== undefined ? resolveLR2CourseNumber(num, course) : undefined) ?? resultNumber(num, result),
text: (st) => resultText(st, input),
slider: (type) => (type === 6 ? resultProgress(result) : undefined),
bargraph: (type) => resultBargraph(type, result),
};
}
/** A moment of the result screen, as its LR2 timers read it; every time is on the clock the screen stamps timers with. */
export interface LR2ResultTimerInput {
/** The time now, and when the screen was entered. */
readonly clock: { readonly nowMs: number; readonly enteredAtMs: number };
/** When input opens: the skin's `#STARTINPUT` after the entry. The graphs start drawing then. */
readonly inputOpenAtMs: number;
/** When the graphs finished drawing, by themselves or skipped by the player; absent until then. */
readonly graphShownAtMs?: number;
/** When the player pressed on to the record update; absent until then. */
readonly updateShownAtMs?: number;
}
/**
* The LR2 timers running on a moment of the result screen, each with when it started:
*
* - timer 0 (the scene) from the screen's entry;
* - timers 1 (input) and 150 (the graphs start drawing) once input has opened;
* - timer 151 (the graphs drawn: the rank and the score show) once the graphs have drawn or been skipped;
* - timer 152 (the record update) once the player has pressed on to it.
*/
export function resolveLR2ResultTimers(input: LR2ResultTimerInput): ReadonlyMap<number, number> {
const timers = new Map<number, number>([[LR2_TIMER.SCENE_START, input.clock.enteredAtMs]]);
if (input.clock.nowMs >= input.inputOpenAtMs) {
timers.set(LR2_TIMER.START_INPUT, input.inputOpenAtMs);
timers.set(LR2_TIMER.RESULT_GRAPH_START, input.inputOpenAtMs);
}
if (input.graphShownAtMs !== undefined) timers.set(LR2_TIMER.RESULT_GRAPH_END, input.graphShownAtMs);
if (input.updateShownAtMs !== undefined) timers.set(LR2_TIMER.RESULT_UPDATE, input.updateShownAtMs);
return timers;
}
/**
* How much of a result graph shows, 0..1, `elapsedMs` after its timer started (`undefined`: not started): nothing before
* the graph's `start` ms, then a linear sweep to all of it at `end` ms. LR2's stock result skin sweeps from 500 to
* 2000 ms after timer 150.
*/
export function resolveLR2GraphReveal(elapsedMs: number | undefined, start: number, end: number): number {
if (elapsedMs === undefined || elapsedMs < start) return 0;
if (end <= start) return 1;
return Math.max(0, Math.min(1, (elapsedMs - start) / (end - start)));
}
|