election-game/backend/apps/sim/src/world.ts

13 lines
881 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { CONTENT } from "@election2026/content";
import { loadScenarioRegistry } from "@election2026/scenarios";
import { DEFAULT_PARAMS, type Scenario, type World } from "@election2026/engine";
import { loadPack } from "@election2026/pack-loader";
export async function loadWorld(scenarioId: string, mood?: Scenario["mood"]): Promise<World> {
const scenario = (await loadScenarioRegistry()).find(scenarioId);
if (!scenario) throw new Error(`找不到劇本 ${scenarioId}`);
// 和伺服器(apps/server/src/app.ts)一樣:總統選舉合成縣市、立委只取選區內的村里
const pack = await loadPack(scenario.packId, undefined, { regionLevel: scenario.region.regionLevel, villages: scenario.villages ? new Set(scenario.villages) : undefined });
return { scenario: mood ? { ...scenario, mood } : scenario, pack, content: CONTENT, params: DEFAULT_PARAMS };
}