25 lines
1.4 KiB
JavaScript
25 lines
1.4 KiB
JavaScript
import { readFile, writeFile } from 'node:fs/promises';
|
|
import { formulaScoreMetadata } from './song-score-formulas.mjs';
|
|
|
|
const root = new URL('../', import.meta.url);
|
|
const catalogPath = new URL('src/lib/data/exact-chart-catalog.json', root);
|
|
const catalog = JSON.parse(await readFile(catalogPath, 'utf8'));
|
|
const updates = [];
|
|
const missing = [];
|
|
// Validate every chart before writing any changes. Do not change notes or SP timing.
|
|
for (const row of catalog.charts) {
|
|
const chartPath = new URL(`static${row.path}`, root);
|
|
const chart = JSON.parse(await readFile(chartPath, 'utf8'));
|
|
const metadata = formulaScoreMetadata(row.songId, row.difficulty, row.difficultyLevel, chart.notes.length, undefined, chart.source?.susSha256);
|
|
if (!metadata) { missing.push(`${row.songId}.${row.difficulty}`); continue; }
|
|
if (chart.songId !== row.songId || chart.difficulty !== row.difficulty || row.totalNotes !== chart.notes.length) {
|
|
throw new Error(`채보 카탈로그 불일치: ${row.songId}.${row.difficulty}`);
|
|
}
|
|
Object.assign(row, metadata);
|
|
Object.assign(chart, metadata);
|
|
updates.push({ chartPath, chart });
|
|
}
|
|
for (const { chartPath, chart } of updates) await writeFile(chartPath, JSON.stringify(chart));
|
|
await writeFile(catalogPath, `${JSON.stringify(catalog, null, 2)}\n`);
|
|
console.log(`${updates.length}개 채보에 곡별 공식을 적용했습니다. 기존 환산 유지: ${missing.join(', ') || '없음'}`);
|