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 | 599x 599x 272x 272x 267x 272x 14x 14x 11x 8x 253x 253x 202x 185x 185x 53x 53x 67x 53x 253x 253x 54x 54x 199x 196x 196x 3x 193x 192x 189x 4x 185x 185x 3462x 3462x 3462x 169x 169x 158x 150x 126x 126x 58x 3462x 3462x 3462x 151x 151x 4x 4x 147x 147x 1x 1x 146x 146x 102x 102x 44x 44x 3462x 14231x 8216x | import { parseHDXLongNoteMode } from './hdx-long-note-mode.ts';
import { findLastIndexAtOrBefore } from '@be-music/shared-utils/core';
import type { ChartOptionTimeline } from './chart-options.ts';
import { isChartGaugeOptionDeclaration } from './chart-gauge-options.ts';
import { isChartPlayOptionDeclaration } from './chart-play-options.ts';
import { parseChartVisualOption, type ChartVisualOptionFields } from './chart-option-visual.ts';
import { resolveChartLegacyOptionAlias } from './chart-option-legacy.ts';
export interface ChartOptionState extends ChartVisualOptionFields {
/** Compulsory visual spacing multiplier, independent of audio tempo and user hi-speed limits. */
hiSpeed?: number;
/** charatbeatHDX placement inside the BGA viewport. */
bgaMode?: 0 | 1 | 2;
}
/**
* The effective-program profile this build compiles. Version 1 holds HI-SPEED only; version 2 adds HIDDEN, CHANGE-HS
* and the CRAZY size / X-wave subfamilies (#843); version 3 adds HIDDEN_M-SUDDEN and the other visual CRAZY options
* (STAR, SPIN, CLONE, LINEMOVE, the Y / XY / 3D waves, HIDJUDGE, DARK, REVERSE; #931). A replay keeps the version it
* was recorded with, so an older recording never activates a family implemented after it.
*/
export const CHART_OPTION_PROGRAM_VERSION = 4;
export interface ChartOptionStateCue {
timeUs: number;
/** Complete effective authored state at this instant. Empty restores user display settings. */
state: ChartOptionState;
}
/** Versioned effective operations, safe to retain in a replay without reinterpreting unsupported source IDs later. */
export interface ChartOptionProgram {
version: 1 | 2 | 3 | 4;
initial: ChartOptionState;
cues: ChartOptionStateCue[];
}
export interface ChartOptionDiagnostic {
code:
| 'unsupported-option'
| 'invalid-parameter'
| 'initial-only-alias'
| 'initial-only-option'
| 'missing-reference'
| 'invalid-time';
declaration?: string;
key?: string;
seconds?: number;
}
export interface CompiledChartOptions {
program: ChartOptionProgram;
diagnostics: ChartOptionDiagnostic[];
}
const LEGACY_HI_SPEED_VALUES = new Set([
'0.2',
'0.4',
'0.6',
'0.8',
'1.0',
'1.5',
'2.0',
'2.5',
'3.0',
'3.5',
'4.0',
'4.5',
'5.0',
'5.5',
'6.0',
'6.5',
'7.0',
'7.5',
'8.0',
'8.5',
'9.0',
'9.5',
'10.0',
'12.0',
'15.0',
'20.0',
'100.0',
]);
type StateChange = (state: ChartOptionState) => ChartOptionState;
function compileDeclaration(source: string, timed: boolean): StateChange | ChartOptionDiagnostic['code'] {
// Legacy HID-* / CRA-* IDs are initial-only, like the legacy HSP values: A6 disregards old IDs.
const legacy = resolveChartLegacyOptionAlias(source);
if (timed && (legacy !== undefined || /^774:CRA-RHS[123]$/.test(source))) return 'initial-only-alias';
const declaration = legacy ?? source;
if (/^charatbeatHDX:BGAMODE(?:\s|$)/.test(declaration)) {
const mode = /^charatbeatHDX:BGAMODE\s+([012])$/.exec(declaration)?.[1];
if (mode === undefined) return 'invalid-parameter';
if (timed) return 'initial-only-option';
return (state) => ({ ...state, bgaMode: Number(mode) as 0 | 1 | 2 });
}
const hiSpeed = compileHiSpeed(declaration, timed);
if (typeof hiSpeed === 'number') return (state) => ({ ...state, hiSpeed });
if (hiSpeed !== 'unsupported-option') return hiSpeed;
const visual = parseChartVisualOption(declaration);
if (visual === undefined) return 'unsupported-option';
return (state) => {
const next: ChartOptionState = { ...state, ...visual.set };
for (const field of visual.clear) delete next[field];
return next;
};
}
function compileHiSpeed(declaration: string, timed: boolean): number | ChartOptionDiagnostic['code'] {
const modern = /^774:HI-SPEED_x(\d+(?:\.\d{1,2})?)$/.exec(declaration);
if (modern) {
const value = Number(modern[1]);
return value >= 0.25 && value <= 100 ? value : 'invalid-parameter';
}
if (declaration.startsWith('774:HI-SPEED_')) return 'invalid-parameter';
const legacy = /^774:HSP-(.+)$/.exec(declaration);
if (legacy && LEGACY_HI_SPEED_VALUES.has(legacy[1]!))
return timed ? 'initial-only-alias' : Math.max(0.25, Number(legacy[1]));
if (parseHDXLongNoteMode(declaration) !== undefined) return 'initial-only-option';
// GAMELEVEL and EXTRA are initial-only in nanasigroove; `compileChartGaugeOptions` consumes the initial ones.
if (isChartGaugeOptionDeclaration(declaration)) return 'initial-only-option';
// RANDOM and gameplay CRAZY are initial-only in nanasigroove; `compileChartPlayOptions` consumes the initial ones.
// `CRAZY_OFF` also clears the visual CRAZY subfamilies, so it stays a display operation too.
if (isChartPlayOptionDeclaration(declaration) && parseChartVisualOption(declaration) === undefined)
return 'initial-only-option';
Iif (declaration.startsWith('charatbeatHDX:LONGMODE')) return 'invalid-parameter';
return 'unsupported-option';
}
/**
* Compile supported native declarations once. Unknown or disallowed declarations are diagnosed and do not cancel
* earlier accepted values. Equal-time A6 operations execute in normalized IR order (Be-Music policy).
*/
export function compileChartOptions(timeline: ChartOptionTimeline): CompiledChartOptions {
const diagnostics: ChartOptionDiagnostic[] = [];
let state: ChartOptionState = {};
for (const source of timeline.initial) {
const declaration = resolveChartLegacyOptionAlias(source) ?? source;
// LONGMODE is resolved by note-rules before note extraction, not a display/replay-profile operation.
if (parseHDXLongNoteMode(declaration) !== undefined) continue;
// GAMELEVEL and EXTRA choose the play's gauge (`compileChartGaugeOptions`), not a display operation.
if (isChartGaugeOptionDeclaration(declaration)) continue;
// RANDOM and gameplay CRAZY are play options (`compileChartPlayOptions`), not display operations; `CRAZY_OFF` is both.
if (isChartPlayOptionDeclaration(declaration) && parseChartVisualOption(declaration) === undefined) continue;
const value = compileDeclaration(declaration, false);
if (typeof value === 'function') state = value(state);
else diagnostics.push({ code: value, declaration: source });
}
const initial = { ...state };
const cues: ChartOptionStateCue[] = [];
for (const cue of [...timeline.cues].sort((left, right) => left.seconds - right.seconds)) {
const context = { key: cue.key, seconds: cue.seconds };
if (cue.declaration === undefined) {
diagnostics.push({ code: 'missing-reference', ...context });
continue;
}
const timeUs = Math.round(cue.seconds * 1_000_000);
if (!Number.isSafeInteger(timeUs) || timeUs < 0) {
diagnostics.push({ code: 'invalid-time', declaration: cue.declaration, ...context });
continue;
}
const value = compileDeclaration(cue.declaration, true);
if (typeof value !== 'function') {
diagnostics.push({ code: value, declaration: cue.declaration, ...context });
continue;
}
state = value(state);
cues.push({ timeUs, state });
}
return {
program: { version: initial.bgaMode === undefined ? 3 : CHART_OPTION_PROGRAM_VERSION, initial, cues },
diagnostics,
};
}
/** Active effective authored options at integer replay/chart microseconds; stateless across pause and seek. */
export function resolveChartOptionsAt(program: ChartOptionProgram, timeUs: number): ChartOptionState {
const index = findLastIndexAtOrBefore(program.cues, timeUs, (cue) => cue.timeUs);
return { ...(index < 0 ? program.initial : program.cues[index]!.state) };
}
|