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 | 29x 88x 1x 28x 1x 27x 27x 29x 29x 29x 43x 69x 4x 39x 39x 15x 3x 12x 36x 3x 1x 2x 35x 215x 215x 47x 5x 42x 30x 29x 26x 26x 21x 43x 1x 20x 3x 17x 17x 6x 6x 6x 6x 12x 6x 6x 6x 6x 6x 33x 66x 1x 32x 32x 1x 31x 31x 31x 45x 5x 40x 6x 34x 25x 22x 5x 17x 10x 7x 23x 1x 22x | import {
CHART_JUDGE_MODIFIERS,
CHART_NOTES_OPTIONS,
CHART_RANDOM_OPTIONS,
chartVisualOptionFieldsOf,
isChartVisualOptionValue,
resolveChartOptionsAt,
} from '@be-music/chart-model';
import type {
ChartOptionProgram,
ChartOptionState,
ChartPlayOptionProgram,
ChartPlayOptions,
} from '@be-music/chart-model';
import { expectRecord, ReplayParseError } from './parse.ts';
/**
* Parse only supported effective profile fields, independently of current source-command compilation. Version 1 holds
* HI-SPEED only; version 2 adds the HIDDEN, CHANGE-HS and CRAZY size / X-wave fields; version 3 adds M-SUDDEN, the
* Y / XY / 3D waves and the other visual CRAZY fields. A recording that carries a field or value of a later version
* than its own is rejected, so an old replay can never activate a family implemented after it.
*/
export function parseChartOptionProgram(raw: unknown): ChartOptionProgram {
const program = expectRecord(raw, 'chart.chartOptions');
if (Object.keys(program).some((key) => !['version', 'initial', 'cues'].includes(key)))
throw new ReplayParseError('chart.chartOptions: unknown program field');
if (program.version !== 1 && program.version !== 2 && program.version !== 3 && program.version !== 4)
throw new ReplayParseError('chart.chartOptions.version: expected 1, 2, 3 or 4');
const version = program.version;
const visualVersion = version === 4 ? 3 : version;
const visualFields = chartVisualOptionFieldsOf(visualVersion);
const fields: readonly string[] = ['hiSpeed', ...visualFields, ...(version === 4 ? ['bgaMode'] : [])];
const state = (rawState: unknown): ChartOptionState => {
const value = expectRecord(rawState, 'chart.chartOptions state');
if (Object.keys(value).some((key) => !fields.includes(key)))
throw new ReplayParseError('chart.chartOptions: unknown effective state field');
const parsed: ChartOptionState = {};
if (value.hiSpeed !== undefined) {
if (
typeof value.hiSpeed !== 'number' ||
!Number.isFinite(value.hiSpeed) ||
value.hiSpeed < 0.25 ||
value.hiSpeed > 100
)
throw new ReplayParseError('chart.chartOptions.hiSpeed: expected 0.25..100');
parsed.hiSpeed = value.hiSpeed;
}
if (value.bgaMode !== undefined) {
if (value.bgaMode !== 0 && value.bgaMode !== 1 && value.bgaMode !== 2)
throw new ReplayParseError('chart.chartOptions.bgaMode: expected 0, 1 or 2');
parsed.bgaMode = value.bgaMode;
}
for (const field of visualFields) {
const fieldValue = value[field];
if (fieldValue === undefined) continue;
if (visualVersion === 1 || !isChartVisualOptionValue(field, fieldValue, visualVersion))
throw new ReplayParseError(`chart.chartOptions.${field}: unknown value`);
(parsed as Record<string, unknown>)[field] = fieldValue;
}
return parsed;
};
if (!Array.isArray(program.cues)) throw new ReplayParseError('chart.chartOptions.cues: expected an array');
let previous = 0;
return {
version,
initial: state(program.initial),
cues: program.cues.map((rawCue) => {
const cue = expectRecord(rawCue, 'chart.chartOptions cue');
if (Object.keys(cue).some((key) => key !== 'timeUs' && key !== 'state'))
throw new ReplayParseError('chart.chartOptions: unknown cue field');
if (typeof cue.timeUs !== 'number' || !Number.isSafeInteger(cue.timeUs) || cue.timeUs < previous)
throw new ReplayParseError('chart.chartOptions.timeUs: expected nondecreasing nonnegative safe integer');
previous = cue.timeUs;
return { timeUs: cue.timeUs, state: state(cue.state) };
}),
};
}
/** Retain only one stage's played ownership window on its offset-relative (already FIT-scaled) replay clock. */
export function shiftChartOptionProgram(
program: ChartOptionProgram,
window: { windowStartUs: number; windowEndUs?: number; offsetUs: number },
): ChartOptionProgram {
const startUs = Math.max(0, window.windowStartUs - window.offsetUs);
const courseStartUs = Math.max(window.windowStartUs, window.offsetUs);
const seed = resolveChartOptionsAt(program, courseStartUs);
const cues = program.cues
.filter((cue) => cue.timeUs > courseStartUs && cue.timeUs < (window.windowEndUs ?? Infinity))
.map((cue) => ({ timeUs: cue.timeUs - window.offsetUs, state: { ...cue.state } }));
if (startUs > 0) cues.unshift({ timeUs: startUs, state: seed });
const endUs = window.windowEndUs === undefined ? undefined : window.windowEndUs - window.offsetUs;
if (endUs !== undefined && endUs >= startUs) cues.push({ timeUs: endUs, state: {} });
return { version: program.version, initial: startUs === 0 ? seed : {}, cues };
}
/**
* Parse a recorded chart gameplay program strictly. Version 2 carries the authored base speed; version 3 may carry it, and
* reads the CRAZY gameplay options as nanasigroove does.
*/
export function parseChartPlayOptionProgram(raw: unknown): ChartPlayOptionProgram {
const program = expectRecord(raw, 'chart.chartPlayOptions');
if (Object.keys(program).some((key) => key !== 'version' && key !== 'options'))
throw new ReplayParseError('chart.chartPlayOptions: unknown program field');
const { version } = program;
if (version !== 1 && version !== 2 && version !== 3)
throw new ReplayParseError('chart.chartPlayOptions.version: expected 1, 2 or 3');
const options = expectRecord(program.options, 'chart.chartPlayOptions.options');
const parsed: ChartPlayOptions = {};
for (const [key, value] of Object.entries(options)) {
if (key === 'random' && (CHART_RANDOM_OPTIONS as readonly unknown[]).includes(value))
parsed.random = value as ChartPlayOptions['random'];
else if (key === 'judge' && (CHART_JUDGE_MODIFIERS as readonly unknown[]).includes(value))
parsed.judge = value as ChartPlayOptions['judge'];
else if (key === 'hellJudge' && value === true) parsed.hellJudge = true;
else if (key === 'addMine' && value === true) parsed.addMine = true;
else if (key === 'baseSpeed' && version !== 1 && (value === 1.2 || value === 1.5 || value === 2))
parsed.baseSpeed = value;
else if (key === 'notes' && (CHART_NOTES_OPTIONS as readonly unknown[]).includes(value))
parsed.notes = value as ChartPlayOptions['notes'];
else throw new ReplayParseError(`chart.chartPlayOptions.options.${key}: unsupported value`);
}
if (version === 2 && parsed.baseSpeed === undefined)
throw new ReplayParseError('chart.chartPlayOptions.options.baseSpeed: required in version 2');
return { version, options: parsed };
}
|