// Loads the static game data and the lists of installed themes / languages. import { buildContext } from '../engine/context.js'; async function getJson(url) { const response = await fetch(url); if (!response.ok) throw new Error(`${url}: HTTP ${response.status}`); return response.json(); } // Every data file the game needs: context key -> file name in public/data/. export const DATA_FILES = { rules: 'rules', generators: 'generators', upgrades: 'upgrades', research: 'research', legacy: 'legacy', achievements: 'achievements', investments: 'investments', tabs: 'tabs', endless: 'endless', }; export async function loadGameContext() { const entries = await Promise.all( Object.entries(DATA_FILES).map(async ([key, file]) => [key, await getJson(`data/${file}.json`)]), ); return buildContext(Object.fromEntries(entries)); } /** [{ id, order, assets, locales }] discovered from public/themes/ by the server. */ export const fetchThemes = () => getJson('api/themes'); /** [{ code, name }] discovered from public/locales/ by the server. */ export const fetchLocales = () => getJson('api/locales');