feat: improve combination search and offline build
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import type { ExactSongChart } from '$lib/engine/index.ts';
|
||||
|
||||
const chartSources = import.meta.glob('../static/data/charts/*.json', {
|
||||
eager: true,
|
||||
query: '?raw',
|
||||
import: 'default'
|
||||
}) as Record<string, string>;
|
||||
|
||||
const sourceByFilename = new Map(
|
||||
Object.entries(chartSources).map(([path, source]) => [path.split('/').at(-1) ?? path, source])
|
||||
);
|
||||
const parsedCharts = new Map<string, ExactSongChart>();
|
||||
|
||||
export async function loadExactSongChart(path: string): Promise<ExactSongChart> {
|
||||
const filename = path.split('/').at(-1) ?? path;
|
||||
const cached = parsedCharts.get(filename);
|
||||
if (cached) return cached;
|
||||
|
||||
const source = sourceByFilename.get(filename);
|
||||
if (!source) throw new Error(`포함된 채보 데이터를 찾지 못했습니다: ${filename}`);
|
||||
const chart = JSON.parse(source) as ExactSongChart;
|
||||
parsedCharts.set(filename, chart);
|
||||
return chart;
|
||||
}
|
||||
Reference in New Issue
Block a user