feat(wip): 시나리오 로더 및 파서 구현, 관련 타입 추가
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
import fs from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import {
|
||||
parseScenarioDefaults,
|
||||
parseScenarioDefinition,
|
||||
} from '../src/scenario/parseScenario.js';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
const repoRoot = path.resolve(__dirname, '..', '..', '..');
|
||||
const scenarioRoot = path.join(repoRoot, 'legacy', 'hwe', 'scenario');
|
||||
|
||||
const readJson = async (filePath: string): Promise<unknown> => {
|
||||
const raw = await fs.readFile(filePath, 'utf8');
|
||||
return JSON.parse(raw) as unknown;
|
||||
};
|
||||
|
||||
describe('scenario parser', () => {
|
||||
it('reads defaults from legacy default.json', async () => {
|
||||
const defaultsRaw = await readJson(
|
||||
path.join(scenarioRoot, 'default.json')
|
||||
);
|
||||
const defaults = parseScenarioDefaults(defaultsRaw);
|
||||
|
||||
expect(defaults.stat.total).toBe(165);
|
||||
expect(defaults.stat.min).toBe(15);
|
||||
expect(defaults.stat.max).toBe(80);
|
||||
expect(defaults.stat.npcTotal).toBe(150);
|
||||
expect(defaults.stat.npcMax).toBe(75);
|
||||
expect(defaults.stat.npcMin).toBe(10);
|
||||
expect(defaults.stat.chiefMin).toBe(65);
|
||||
expect(defaults.iconPath).toBe('.');
|
||||
});
|
||||
|
||||
it('defaults map/unit set when scenario omits map config', async () => {
|
||||
const defaultsRaw = await readJson(
|
||||
path.join(scenarioRoot, 'default.json')
|
||||
);
|
||||
const scenarioRaw = await readJson(
|
||||
path.join(scenarioRoot, 'scenario_0.json')
|
||||
);
|
||||
const defaults = parseScenarioDefaults(defaultsRaw);
|
||||
const scenario = parseScenarioDefinition(scenarioRaw, defaults);
|
||||
|
||||
expect(scenario.config.environment.mapName).toBe('che');
|
||||
expect(scenario.config.environment.unitSet).toBe('che');
|
||||
});
|
||||
|
||||
it('parses nation/general rows from a legacy scenario', async () => {
|
||||
const defaultsRaw = await readJson(
|
||||
path.join(scenarioRoot, 'default.json')
|
||||
);
|
||||
const scenarioRaw = await readJson(
|
||||
path.join(scenarioRoot, 'scenario_1010.json')
|
||||
);
|
||||
const defaults = parseScenarioDefaults(defaultsRaw);
|
||||
const scenario = parseScenarioDefinition(scenarioRaw, defaults);
|
||||
|
||||
expect(scenario.nations.length).toBeGreaterThan(0);
|
||||
expect(scenario.generals.length).toBeGreaterThan(0);
|
||||
|
||||
const firstNation = scenario.nations[0];
|
||||
expect(firstNation.name).toBe('후한');
|
||||
expect(firstNation.color).toBe('#800000');
|
||||
|
||||
const firstGeneral = scenario.generals[0];
|
||||
expect(firstGeneral.name).toBe('소제1');
|
||||
expect(firstGeneral.affinity).toBe(1);
|
||||
expect(firstGeneral.picture).toBe(1001);
|
||||
expect(firstGeneral.nation).toBe(1);
|
||||
expect(firstGeneral.city).toBe(null);
|
||||
expect(firstGeneral.leadership).toBe(20);
|
||||
expect(firstGeneral.personality).toBe('유지');
|
||||
expect(firstGeneral.special).toBe(null);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user