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 | 2x 22x 20x 20x 62x 12x 12x 6x 6x 13x 12x 97x 97x 3x 2x 8x 4x 3x 2x 2x 6x 6x 7x 1x 1x 1x 1x 5x 6x 5x 2x 5x 2x 2x 3x 2x 2x 1x 3x 1x 1x 2x 1x 2x 3x 4x 4x 52x 58x 58x 52x 145x 55x 120x 145x 52x 175x 84x 84x 672x 84x 55x 145x 145x 145x 58x 58x 42x 58x 145x | import { resolveBeatorajaGaugeTypeOps } from './play-ops.ts';
import { gaugePercent } from '@be-music/player-scene-model';
import { BEATORAJA_NUM, BEATORAJA_OP, computeJudgeExistOps } from '../runtime-ids.ts';
import type { BeatorajaEarlyLate, BeatorajaGaugeInput, BeatorajaScoreInput } from './inputs.ts';
/** What the score numbers a play skin and a result skin share read. */
export interface BeatorajaScoreNumberInput {
/** The judgment counts and scores; absent before the engine reports any (they read 0). */
readonly score?: BeatorajaScoreInput;
readonly gauge?: BeatorajaGaugeInput;
/** The combo shown as number 104: the running combo during a play. */
readonly combo: number;
/** The longest combo (number 105). */
readonly maxCombo: number;
readonly earlyLate?: BeatorajaEarlyLate;
/** The chart's `#TOTAL` as written, which number 368 shows until a gauge reports the TOTAL it runs on. */
readonly chartTotal?: number;
}
/** The integer part of a percentage and its first two decimals, as beatoraja's `*_AFTERDOT` pairs show it. */
function afterDot(percent: number): number {
return Math.floor((percent - Math.floor(percent)) * 100);
}
/** A rate as beatoraja's numbers draw it: the whole percent and its two digits after the dot. */
export interface BeatorajaRate {
readonly whole: number;
readonly afterDot: number;
}
/**
* The EX score as a percentage of the highest one `notes` notes can give (beatoraja `ScoreDataProperty`: `exscore /
* (notes × 2)`, 100 % for no notes), truncated to hundredths of a percent as the `*_RATE` / `*_AFTERDOT` pairs draw it.
*/
export function beatorajaScoreRate(exScore: number, notes: number): BeatorajaRate {
if (notes <= 0) return { whole: 100, afterDot: 0 };
const hundredths = Math.floor((exScore * 10_000) / (notes * 2));
return { whole: Math.floor(hundredths / 100), afterDot: hundredths % 100 };
}
/** The notes judged so far: every PERFECT … POOR (an empty POOR judges no note). */
export function beatorajaNotesJudged(
score: Pick<BeatorajaScoreInput, 'perfect' | 'great' | 'good' | 'bad' | 'poor'>,
): number {
return score.perfect + score.great + score.good + score.bad + score.poor;
}
/**
* The chart TOTAL readout (number 368, `chart_totalgauge`). beatoraja reads it after `BMSPlayerRule.validate`, i.e. the
* TOTAL the gauge actually runs on — a bmson `total` is a percentage of the ruleset's default TOTAL and a missing
* `#TOTAL` is that default — so the gauge's `effectiveTotal` wins whenever a gauge reports one. Without one (before the
* first frame) the chart header is shown as written. Floored, since the readout has no fraction digits; `undefined`
* when there is nothing to show.
*/
export function beatorajaChartTotalReadout(
gauge: Pick<BeatorajaGaugeInput, 'effectiveTotal'> | undefined,
chartTotal: number | undefined,
): number | undefined {
const effectiveTotal = gauge?.effectiveTotal;
if (typeof effectiveTotal === 'number' && Number.isFinite(effectiveTotal) && effectiveTotal > 0) {
return Math.floor(effectiveTotal);
}
return typeof chartTotal === 'number' && Number.isFinite(chartTotal) ? Math.floor(chartTotal) : undefined;
}
function early(earlyLate: BeatorajaEarlyLate | undefined, judge: keyof NonNullable<BeatorajaEarlyLate>): number {
return earlyLate?.[judge]?.early ?? 0;
}
function late(earlyLate: BeatorajaEarlyLate | undefined, judge: keyof NonNullable<BeatorajaEarlyLate>): number {
return earlyLate?.[judge]?.late ?? 0;
}
/**
* The score numbers a play skin and a result skin share (`IntegerPropertyFactory`): the score and its rates, the
* combo, the judgment counts and their early / late split, the gauge and the chart TOTAL. `undefined` for an id that is
* not one of them.
*
* - `POINT` (100) shows the displayed score and `SCORE2` (101) the EX score (beatoraja's `createScoreProperty`, LR2's
* number 101); `TOTAL_RATE` (115 / 116) the EX score as a rate of every note ({@link beatorajaScoreRate}), and so does
* `SCORE_RATE` (102 / 103) here: a finished run's rate, as beatoraja's result reads it (a play reads it over the notes
* judged so far, `resolveBeatorajaPlayNumber`). The rates read 0 before the engine reports a score.
* - `MISS` (420) reads empty POORs separately from note POORs. Its early / late rows (421 / 422) read the
* `MISS` entry of the early / late counts, else POOR's.
* - `COMBOBREAK` (425) counts BAD + POOR; 426 adds empty POORs to POOR and 427 adds them to BAD + POOR.
*/
export function resolveBeatorajaScoreNumber(id: number, input: BeatorajaScoreNumberInput): number | undefined {
const { score, earlyLate } = input;
switch (id) {
case BEATORAJA_NUM.POINT:
return score?.score ?? 0;
case BEATORAJA_NUM.SCORE2:
return score?.exScore ?? 0;
case BEATORAJA_NUM.SCORE_RATE:
case BEATORAJA_NUM.TOTAL_RATE:
return score !== undefined ? beatorajaScoreRate(score.exScore, score.total).whole : 0;
case BEATORAJA_NUM.SCORE_RATE_AFTERDOT:
case BEATORAJA_NUM.TOTAL_RATE_AFTERDOT:
return score !== undefined ? beatorajaScoreRate(score.exScore, score.total).afterDot : 0;
case BEATORAJA_NUM.COMBO:
return input.combo;
case BEATORAJA_NUM.MAXCOMBO_LIVE:
return input.maxCombo;
case BEATORAJA_NUM.TOTALNOTES:
case BEATORAJA_NUM.TOTALNOTES_LIVE:
return score?.total ?? 0;
case BEATORAJA_NUM.GROOVEGAUGE:
case BEATORAJA_NUM.GROOVEGAUGE_AFTERDOT: {
const percent = input.gauge !== undefined ? gaugePercent(input.gauge) : 0;
return id === BEATORAJA_NUM.GROOVEGAUGE ? Math.floor(percent) : afterDot(percent);
}
case BEATORAJA_NUM.BMS_TOTAL:
return beatorajaChartTotalReadout(input.gauge, input.chartTotal) ?? 0;
case BEATORAJA_NUM.PERFECT:
return score?.perfect ?? 0;
case BEATORAJA_NUM.GREAT:
return score?.great ?? 0;
case BEATORAJA_NUM.GOOD:
return score?.good ?? 0;
case BEATORAJA_NUM.BAD:
return score?.bad ?? 0;
case BEATORAJA_NUM.POOR:
return score?.poor ?? 0;
case BEATORAJA_NUM.MISS:
return score?.emptyPoor ?? 0;
case BEATORAJA_NUM.POOR_PLUS_MISS:
return (score?.poor ?? 0) + (score?.emptyPoor ?? 0);
case BEATORAJA_NUM.COMBOBREAK:
return (score?.bad ?? 0) + (score?.poor ?? 0);
case BEATORAJA_NUM.BAD_PLUS_POOR_PLUS_MISS:
return (score?.bad ?? 0) + (score?.poor ?? 0) + (score?.emptyPoor ?? 0);
case BEATORAJA_NUM.TOTALEARLY:
return score?.fast ?? 0;
case BEATORAJA_NUM.TOTALLATE:
return score?.slow ?? 0;
case BEATORAJA_NUM.EARLY_PERFECT:
return early(earlyLate, 'PERFECT');
case BEATORAJA_NUM.LATE_PERFECT:
return late(earlyLate, 'PERFECT');
case BEATORAJA_NUM.EARLY_GREAT:
return early(earlyLate, 'GREAT');
case BEATORAJA_NUM.LATE_GREAT:
return late(earlyLate, 'GREAT');
case BEATORAJA_NUM.EARLY_GOOD:
return early(earlyLate, 'GOOD');
case BEATORAJA_NUM.LATE_GOOD:
return late(earlyLate, 'GOOD');
case BEATORAJA_NUM.EARLY_BAD:
return early(earlyLate, 'BAD');
case BEATORAJA_NUM.LATE_BAD:
return late(earlyLate, 'BAD');
case BEATORAJA_NUM.EARLY_POOR:
return early(earlyLate, 'POOR');
case BEATORAJA_NUM.LATE_POOR:
return late(earlyLate, 'POOR');
case BEATORAJA_NUM.EARLY_MISS:
return early(earlyLate, earlyLate?.MISS !== undefined ? 'MISS' : 'POOR');
case BEATORAJA_NUM.LATE_MISS:
return late(earlyLate, earlyLate?.MISS !== undefined ? 'MISS' : 'POOR');
default:
return undefined;
}
}
/** The 1P gauge range ops (230-240: 0-9 % … 90-99 %, 100 %), lowest first. */
const GAUGE_RANGE_OPS: readonly number[] = [
BEATORAJA_OP.P1_BAND_0_9,
BEATORAJA_OP.P1_BAND_10_19,
BEATORAJA_OP.P1_BAND_20_29,
BEATORAJA_OP.P1_BAND_30_39,
BEATORAJA_OP.P1_BAND_40_49,
BEATORAJA_OP.P1_BAND_50_59,
BEATORAJA_OP.P1_BAND_60_69,
BEATORAJA_OP.P1_BAND_70_79,
BEATORAJA_OP.P1_BAND_80_89,
BEATORAJA_OP.P1_BAND_90_99,
BEATORAJA_OP.P1_BAND_100,
];
/**
* The gauge range op of a gauge: its tenth of the maximum, the full gauge on its own (beatoraja
* `BooleanPropertyFactory.GaugeDrawCondition`: `value >= range × 10 % of max && value < (range + 1) × 10 %`; LR2's
* "1P gauge 0-9 %" … "100 %").
*/
function gaugeRangeOp(gauge: Pick<BeatorajaGaugeInput, 'current' | 'max'>): number {
const range = Math.floor(gaugePercent(gauge) / 10);
return GAUGE_RANGE_OPS[Math.max(0, Math.min(GAUGE_RANGE_OPS.length - 1, range))]!;
}
/** The 27ths of the highest EX score each rank starts at, AAA first (beatoraja `BooleanPropertyFactory`). */
const RANK_BORDERS_IN_27THS = [24, 21, 18, 15, 12, 9, 6, 0] as const;
/**
* The 1P rank op (200 AAA … 207 F) of a play: the rank of the EX score over the notes judged so far, as beatoraja's
* `createNowRank` reads `ScoreDataProperty.nowrate` (`exscore / (notes judged × 2)`, 100 % before the first note, so a
* play starts on AAA); none on a chart without notes. The rate is compared with each border exactly, in 27ths.
*/
function beatorajaPlayRankOp(score: BeatorajaScoreInput): number | undefined {
if (score.total <= 0) return undefined;
const judged = beatorajaNotesJudged(score);
const index =
judged === 0 ? 0 : RANK_BORDERS_IN_27THS.findIndex((border) => score.exScore * 27 >= border * judged * 2);
return BEATORAJA_OP.P1_RANK_AAA + index;
}
/** The generic rank ops (220 AAA … 227 F), AAA first, in the order of {@link RANK_BORDERS_IN_27THS}. */
const GENERIC_RANK_OPS = [
BEATORAJA_OP.RANK_AAA,
BEATORAJA_OP.RANK_AA,
BEATORAJA_OP.RANK_A,
BEATORAJA_OP.RANK_B,
BEATORAJA_OP.RANK_C,
BEATORAJA_OP.RANK_D,
BEATORAJA_OP.RANK_E,
BEATORAJA_OP.RANK_F,
] as const;
/**
* The generic rank ops (220 AAA … 227 F) a score lights: every rank its EX score reaches over the chart's notes, as
* beatoraja's `BooleanPropertyFactory` asks `ScoreDataProperty.qualifyRank` (`rate >= border / 27`, with
* `rate = exscore / (notes × 2)`), so an AAA lights all eight and any score on a chart with notes lights F. The rate is
* compared with each border exactly, in 27ths. None on a chart without notes. `computeGenericRankOp` names one rank,
* the highest of these.
*/
export function beatorajaGenericRankOps(score: Pick<BeatorajaScoreInput, 'exScore' | 'total'>): number[] {
if (score.total <= 0) return [];
const ops: number[] = [];
RANK_BORDERS_IN_27THS.forEach((border, index) => {
if (score.exScore * 27 >= border * score.total * 2) ops.push(GENERIC_RANK_OPS[index]!);
});
return ops;
}
/**
* The "now" rank op (340-347, `NOW_*_1P`) for a 1P rank op (200-207): the same rank in the block beatoraja keeps for
* the rank being played (both read `createNowRank`).
*/
function nowRankOp(sideRank: number): number {
return sideRank - BEATORAJA_OP.P1_RANK_AAA + BEATORAJA_OP.NOW_AAA_1P;
}
/**
* The ops a play's running score and gauge light on a play skin, as of the engine's latest frame: the 1P and "now"
* rank ops over the notes judged so far ({@link beatorajaPlayRankOp}), the generic rank ops the EX score reaches
* ({@link beatorajaGenericRankOps}) and its judgment-exists ops (2241-2246); and with a gauge, its range op (230-240),
* `P1_BAND_BORDER_OR_MORE` (1240) while the gauge would clear (beatoraja `Gauge.isQualified`: above 0 and at its border
* or more), and `GAUGE_NOW_AT_MAX_1P` while it is full.
*/
export function resolveBeatorajaPlayScoreOps(
score: BeatorajaScoreInput,
gauge: Pick<BeatorajaGaugeInput, 'current' | 'max' | 'clearThreshold' | 'type'> | undefined,
): number[] {
const sideRank = beatorajaPlayRankOp(score);
const ops = [
...resolveBeatorajaGaugeTypeOps(gauge?.type),
...(sideRank !== undefined ? [sideRank, nowRankOp(sideRank)] : []),
...beatorajaGenericRankOps(score),
...computeJudgeExistOps(score),
];
if (gauge !== undefined && gauge.max > 0) {
ops.push(gaugeRangeOp(gauge));
if (gauge.current > 0 && gauge.current >= (gauge.clearThreshold ?? 0)) {
ops.push(BEATORAJA_OP.P1_BAND_BORDER_OR_MORE);
}
if (gaugePercent(gauge) >= 100) ops.push(BEATORAJA_OP.GAUGE_NOW_AT_MAX_1P);
}
return ops;
}
|