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 | 12x 12x 12x 86x 29x 8x 8x 3x 7x 70x 20x 21x 21x 21x 68x 22x 22x 12x 12x 1x 11x 11x 11x 6x 22x 10x 10x 10x 9x 9x 36x 36x 9x 6x 13x 27x 27x 17x 8x 8x | // The player's best records, handed to the select skins through `resolveChartBestRecord` / `resolveCourseBestRecord`: the keys
// they are kept under — one record per chart (or course) and judge ruleset — and their persistence across reloads. The
// rules they are kept by — merging a play, what a play contributes, which plays count — are `@be-music/player-engine/records`.
import {
chartProgramCopiesChart,
courseStageKeepsRecord,
playKeepsRecord,
type BestRecord,
type RecordPlayKind,
type RecordSlot,
} from '@be-music/player-engine/records';
import { compileChartPlayOptions } from '@be-music/chart-model';
import { isClearLamp, RULESET_IDS, type RulesetId } from '@be-music/player-engine/ruleset';
import { resolveLibraryChartPlayVariant, type LibraryChart } from '@be-music/player-scene-model';
const STORAGE_KEY = 'be-music.chart-best-records';
/**
* The stored map's revision. `0` while the shape is still being defined: it may change incompatibly without the number
* moving. The current shape keys every record by its judge ruleset ({@link rulesetRecordKey}). Any other stamp is
* unreadable.
*/
const STORAGE_VERSION = 0;
const JUDGE_RULESETS: readonly RulesetId[] = RULESET_IDS;
/** How a play was played and judged, as far as which record it keeps goes. */
export type RecordedPlayKind = RecordPlayKind & {
/** The judge ruleset the play ran under: it keeps that ruleset's record. */
judgeRuleset: RulesetId;
};
/**
* The key a record is stored under: the judge ruleset it was played under, then the chart's key ({@link chartBestRecordKey})
* or the course's (`courseBestRecordKey`), e.g. `lr2:sha256:…`. Each ruleset has its own lamps, BP and scoring, so a chart
* keeps one record per ruleset.
*/
export function rulesetRecordKey(ruleset: RulesetId, key: string): string {
return `${ruleset}:${key}`;
}
/** The judge ruleset a {@link rulesetRecordKey} keeps its record under, or `undefined` for a key that names none. */
export function recordKeyRuleset(key: string): RulesetId | undefined {
return JUDGE_RULESETS.find((ruleset) => key.startsWith(`${ruleset}:`));
}
/**
* The key of a record slot beside a chart's ordinary record (`RecordPolicy.recordSlot`): an LR2 separate lamp (D-BATTLE,
* SP TO DP, EXTRA MODE) as `lr2:d-battle:sha256:…`. The ordinary slot keeps the key itself.
*/
export function slotRecordKey(key: string, slot: RecordSlot): string {
const ruleset = recordKeyRuleset(key);
if (slot === 'main' || ruleset === undefined) return key;
return `${ruleset}:${slot}:${key.slice(ruleset.length + 1)}`;
}
/** The records of one judge ruleset, looked up by a chart's or a course's own key (as `lookupCourseBestRecord` reads them). */
export function rulesetRecords<T>(
records: { get(key: string): T | undefined },
ruleset: RulesetId,
): { get(key: string): T | undefined } {
return { get: (key) => records.get(rulesetRecordKey(ruleset, key)) };
}
/**
* The key a play's result is recorded under — its chart's, under the judge ruleset the play ran under — or `undefined`
* when the play leaves the records alone (`playKeepsRecord`): an auto play, a replay, a course stage (NONSTOP included —
* the course keeps the record) and a play at another tempo (practice).
*/
export function playRecordKey(
chartEntry: Pick<LibraryChart, 'chartPath'>,
chartSHA256: string | undefined,
play: RecordedPlayKind & { course: boolean },
): string | undefined {
return playKeepsRecord(play)
? rulesetRecordKey(play.judgeRuleset, chartBestRecordKey(chartEntry, chartSHA256))
: undefined;
}
/**
* The key an EXPERT / GRADE course stage also updates its chart's record under (under the judge ruleset the stage ran
* under), or `undefined` when it leaves the chart's record alone (`courseStageKeepsRecord`): an auto play, a replay and a
* play at another tempo.
*/
export function courseStageRecordKey(
chartEntry: Pick<LibraryChart, 'chartPath'>,
chartSHA256: string | undefined,
play: RecordedPlayKind,
): string | undefined {
return courseStageKeepsRecord(play)
? rulesetRecordKey(play.judgeRuleset, chartBestRecordKey(chartEntry, chartSHA256))
: undefined;
}
/**
* Whether a chart's own `774:NOTES_COPY` / `DBLCOPY` makes it a double-play chart outside a course (#932): its record is
* then of the double-play chart, which a course stage (keeping its key mode, without the copy) must not update
* (`RecordPlayKind.chartCopyLeftOut`). Read from the declarations outside `#RANDOM`, as a stage starts.
*/
export function chartCopiesItself(chartEntry: LibraryChart): boolean {
const { bms } = chartEntry.chart;
const program = compileChartPlayOptions({ initial: bms.options ?? (bms.option ? [bms.option] : []) });
return (
program.options.notes !== undefined && chartProgramCopiesChart(program, resolveLibraryChartPlayVariant(chartEntry))
);
}
/**
* The key a chart's record is stored under, before its judge ruleset ({@link rulesetRecordKey}): its chart-file SHA-256
* when known (stable across sessions, machines, and file moves — the same hash the replays record), else its chart
* path inside the dropped library.
*/
export function chartBestRecordKey(
chartEntry: Pick<LibraryChart, 'chartPath'>,
chartSHA256: string | undefined,
): string {
return chartSHA256 !== undefined && chartSHA256.length > 0 ? `sha256:${chartSHA256}` : `path:${chartEntry.chartPath}`;
}
/**
* Parses stored records, keyed by {@link rulesetRecordKey}. Entries whose lamp is unknown (or whose key names no judge
* ruleset) are dropped and malformed counts are left out, so a hand-edited or stale store can't hand a skin junk;
* anything unreadable yields no records.
*/
export function parseChartBestRecords(raw: string | null | undefined): Map<string, BestRecord> {
const records = new Map<string, BestRecord>();
if (!raw) return records;
let parsed: unknown;
try {
parsed = JSON.parse(raw);
} catch {
return records;
}
Iif (typeof parsed !== 'object' || parsed === null) return records;
const { version, records: stored } = parsed as { version?: unknown; records?: unknown };
if (version !== STORAGE_VERSION || typeof stored !== 'object' || stored === null) return records;
for (const [key, entry] of Object.entries(stored)) {
if (!JUDGE_RULESETS.some((ruleset) => key.startsWith(`${ruleset}:`))) continue;
Iif (typeof entry !== 'object' || entry === null) continue;
const { lamp } = entry as { lamp?: unknown };
if (!isClearLamp(lamp)) continue;
const record: BestRecord = { lamp };
for (const field of ['exScore', 'maxCombo', 'missCount', 'playCount'] as const) {
const value = (entry as Record<string, unknown>)[field];
if (typeof value === 'number' && Number.isInteger(value) && value >= 0) record[field] = value;
}
records.set(key, record);
}
return records;
}
/** Serializes records as `{ version: 0, records: { [rulesetRecordKey]: BestRecord } }`. */
export function serializeChartBestRecords(records: ReadonlyMap<string, BestRecord>): string {
return JSON.stringify({ version: STORAGE_VERSION, records: Object.fromEntries(records) });
}
export function readStoredChartBestRecords(): Map<string, BestRecord> {
try {
return parseChartBestRecords(window.localStorage.getItem(STORAGE_KEY));
} catch {
return new Map();
}
}
export function storeChartBestRecords(records: ReadonlyMap<string, BestRecord>): void {
try {
window.localStorage.setItem(STORAGE_KEY, serializeChartBestRecords(records));
} catch {
// Private windows / blocked or full storage: the records still hold for this session.
}
}
|