feat: eslint 적용 및 관련 코드 일괄 수정
This commit is contained in:
@@ -2,10 +2,7 @@ import { describe, expect, it } from 'vitest';
|
||||
|
||||
import type { City, General, Nation } from '../src/domain/entities.js';
|
||||
import type { MapDefinition } from '../src/world/types.js';
|
||||
import {
|
||||
isCrewTypeAvailable,
|
||||
parseUnitSetDefinition,
|
||||
} from '../src/world/unitSet.js';
|
||||
import { isCrewTypeAvailable, parseUnitSetDefinition } from '../src/world/unitSet.js';
|
||||
|
||||
const buildMap = (): MapDefinition => ({
|
||||
id: 'test',
|
||||
@@ -104,6 +101,7 @@ const buildCities = (): City[] => [
|
||||
name: 'A',
|
||||
nationId: 1,
|
||||
level: 6,
|
||||
state: 0,
|
||||
population: 50000,
|
||||
populationMax: 100000,
|
||||
agriculture: 500,
|
||||
@@ -212,9 +210,7 @@ describe('crew type availability', () => {
|
||||
magicCoef: 0,
|
||||
cost: 9,
|
||||
rice: 9,
|
||||
requirements: [
|
||||
{ type: 'ReqCitiesWithCityLevel', level: 7, cities: ['A'] },
|
||||
],
|
||||
requirements: [{ type: 'ReqCitiesWithCityLevel', level: 7, cities: ['A'] }],
|
||||
attackCoef: {},
|
||||
defenceCoef: {},
|
||||
info: [],
|
||||
@@ -239,4 +235,3 @@ describe('crew type availability', () => {
|
||||
expect(isCrewTypeAvailable(unitSet, 1300, context)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import {
|
||||
DEFAULT_WAR_TERM,
|
||||
DIPLOMACY_STATE,
|
||||
processDiplomacyMonth,
|
||||
type DiplomacyEntry,
|
||||
} from '@sammo-ts/logic';
|
||||
import { DEFAULT_WAR_TERM, DIPLOMACY_STATE, processDiplomacyMonth, type DiplomacyEntry } from '@sammo-ts/logic';
|
||||
|
||||
const buildEntry = (
|
||||
fromNationId: number,
|
||||
@@ -28,7 +23,13 @@ describe('diplomacy month processing', () => {
|
||||
buildEntry(1, 2, DIPLOMACY_STATE.DECLARATION, 1),
|
||||
buildEntry(2, 1, DIPLOMACY_STATE.DECLARATION, 1),
|
||||
];
|
||||
const result = processDiplomacyMonth(entries, new Map([[1, 1], [2, 1]]));
|
||||
const result = processDiplomacyMonth(
|
||||
entries,
|
||||
new Map([
|
||||
[1, 1],
|
||||
[2, 1],
|
||||
])
|
||||
);
|
||||
|
||||
for (const entry of result) {
|
||||
expect(entry.state).toBe(DIPLOMACY_STATE.WAR);
|
||||
@@ -37,11 +38,14 @@ describe('diplomacy month processing', () => {
|
||||
});
|
||||
|
||||
it('ends war when both terms reach zero without casualties', () => {
|
||||
const entries = [
|
||||
buildEntry(1, 2, DIPLOMACY_STATE.WAR, 1),
|
||||
buildEntry(2, 1, DIPLOMACY_STATE.WAR, 1),
|
||||
];
|
||||
const result = processDiplomacyMonth(entries, new Map([[1, 1], [2, 1]]));
|
||||
const entries = [buildEntry(1, 2, DIPLOMACY_STATE.WAR, 1), buildEntry(2, 1, DIPLOMACY_STATE.WAR, 1)];
|
||||
const result = processDiplomacyMonth(
|
||||
entries,
|
||||
new Map([
|
||||
[1, 1],
|
||||
[2, 1],
|
||||
])
|
||||
);
|
||||
|
||||
for (const entry of result) {
|
||||
expect(entry.state).toBe(DIPLOMACY_STATE.TRADE);
|
||||
@@ -50,18 +54,17 @@ describe('diplomacy month processing', () => {
|
||||
});
|
||||
|
||||
it('extends war term based on accumulated casualties', () => {
|
||||
const entries = [
|
||||
buildEntry(1, 2, DIPLOMACY_STATE.WAR, 3, 400),
|
||||
buildEntry(2, 1, DIPLOMACY_STATE.WAR, 3, 0),
|
||||
];
|
||||
const result = processDiplomacyMonth(entries, new Map([[1, 2], [2, 2]]));
|
||||
const entries = [buildEntry(1, 2, DIPLOMACY_STATE.WAR, 3, 400), buildEntry(2, 1, DIPLOMACY_STATE.WAR, 3, 0)];
|
||||
const result = processDiplomacyMonth(
|
||||
entries,
|
||||
new Map([
|
||||
[1, 2],
|
||||
[2, 2],
|
||||
])
|
||||
);
|
||||
|
||||
const forward = result.find(
|
||||
(entry) => entry.fromNationId === 1 && entry.toNationId === 2
|
||||
);
|
||||
const reverse = result.find(
|
||||
(entry) => entry.fromNationId === 2 && entry.toNationId === 1
|
||||
);
|
||||
const forward = result.find((entry) => entry.fromNationId === 1 && entry.toNationId === 2);
|
||||
const reverse = result.find((entry) => entry.fromNationId === 2 && entry.toNationId === 1);
|
||||
expect(forward?.term).toBe(4);
|
||||
expect(forward?.dead).toBe(0);
|
||||
expect(reverse?.term).toBe(2);
|
||||
@@ -72,7 +75,13 @@ describe('diplomacy month processing', () => {
|
||||
buildEntry(1, 2, DIPLOMACY_STATE.NON_AGGRESSION, 1),
|
||||
buildEntry(2, 1, DIPLOMACY_STATE.NON_AGGRESSION, 1),
|
||||
];
|
||||
const result = processDiplomacyMonth(entries, new Map([[1, 1], [2, 1]]));
|
||||
const result = processDiplomacyMonth(
|
||||
entries,
|
||||
new Map([
|
||||
[1, 1],
|
||||
[2, 1],
|
||||
])
|
||||
);
|
||||
|
||||
for (const entry of result) {
|
||||
expect(entry.state).toBe(DIPLOMACY_STATE.TRADE);
|
||||
|
||||
@@ -55,6 +55,7 @@ const buildCity = (id: number, nationId: number): City => ({
|
||||
name: `City${id}`,
|
||||
nationId,
|
||||
level: 2,
|
||||
state: 0,
|
||||
population: 10000,
|
||||
populationMax: 10000,
|
||||
agriculture: 1000,
|
||||
@@ -204,7 +205,7 @@ describe('che_출병', () => {
|
||||
seedBase: 'test-seed',
|
||||
warConfig,
|
||||
aftermathConfig,
|
||||
},
|
||||
} as any,
|
||||
{
|
||||
now: new Date('2000-01-01T00:00:00Z'),
|
||||
schedule,
|
||||
@@ -215,12 +216,8 @@ describe('che_출병', () => {
|
||||
);
|
||||
|
||||
expect(resolution.logs.length).toBeGreaterThan(0);
|
||||
expect(resolution.patches?.generals.some((patch) => patch.id === defender.id)).toBe(
|
||||
true
|
||||
);
|
||||
expect(resolution.patches?.cities.some((patch) => patch.id === defenderCity.id)).toBe(
|
||||
true
|
||||
);
|
||||
expect(resolution.patches?.generals.some((patch) => patch.id === defender.id)).toBe(true);
|
||||
expect(resolution.patches?.cities.some((patch) => patch.id === defenderCity.id)).toBe(true);
|
||||
expect(
|
||||
resolution.effects.some(
|
||||
(effect) =>
|
||||
|
||||
@@ -52,12 +52,10 @@ describe('sendMessage', () => {
|
||||
expect(result.receiverId).toBe(1);
|
||||
expect(result.senderId).toBe(2);
|
||||
expect(store.records).toHaveLength(2);
|
||||
expect(store.records[0].draft.mailbox).toBe(draft.dest.generalId);
|
||||
expect(store.records[1].draft.mailbox).toBe(draft.src.generalId);
|
||||
expect(store.records[0].draft.payload.option).not.toHaveProperty(
|
||||
'receiverMessageID'
|
||||
);
|
||||
expect(store.records[1].draft.payload.option).toMatchObject({
|
||||
expect(store.records[0]!.draft.mailbox).toBe(draft.dest.generalId);
|
||||
expect(store.records[1]!.draft.mailbox).toBe(draft.src.generalId);
|
||||
expect(store.records[0]!.draft.payload.option).not.toHaveProperty('receiverMessageID');
|
||||
expect(store.records[1]!.draft.payload.option).toMatchObject({
|
||||
receiverMessageID: 1,
|
||||
});
|
||||
});
|
||||
@@ -73,9 +71,7 @@ describe('sendMessage', () => {
|
||||
|
||||
expect(result.senderId).toBeUndefined();
|
||||
expect(store.records).toHaveLength(1);
|
||||
expect(store.records[0].draft.mailbox).toBe(
|
||||
MESSAGE_MAILBOX_NATIONAL_BASE + 1
|
||||
);
|
||||
expect(store.records[0]!.draft.mailbox).toBe(MESSAGE_MAILBOX_NATIONAL_BASE + 1);
|
||||
});
|
||||
|
||||
it('keeps public messages in the shared mailbox only', async () => {
|
||||
@@ -89,7 +85,7 @@ describe('sendMessage', () => {
|
||||
|
||||
expect(result.senderId).toBeUndefined();
|
||||
expect(store.records).toHaveLength(1);
|
||||
expect(store.records[0].draft.mailbox).toBe(MESSAGE_MAILBOX_PUBLIC);
|
||||
expect(store.records[0]!.draft.mailbox).toBe(MESSAGE_MAILBOX_PUBLIC);
|
||||
});
|
||||
|
||||
it('removes diplomacy action from sender copy', async () => {
|
||||
@@ -102,7 +98,7 @@ describe('sendMessage', () => {
|
||||
|
||||
await sendMessage(store, draft);
|
||||
|
||||
const senderPayload = store.records[1].draft.payload.option ?? {};
|
||||
const senderPayload = store.records[1]!.draft.payload.option ?? {};
|
||||
expect(senderPayload).not.toHaveProperty('action');
|
||||
expect(senderPayload).toMatchObject({ payload: 1 });
|
||||
});
|
||||
|
||||
@@ -4,10 +4,7 @@ import { fileURLToPath } from 'node:url';
|
||||
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import {
|
||||
parseScenarioDefaults,
|
||||
parseScenarioDefinition,
|
||||
} from '../src/scenario/parseScenario.js';
|
||||
import { parseScenarioDefaults, parseScenarioDefinition } from '../src/scenario/parseScenario.js';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
@@ -21,9 +18,7 @@ const readJson = async (filePath: string): Promise<unknown> => {
|
||||
|
||||
describe('scenario parser', () => {
|
||||
it('reads defaults from legacy default.json', async () => {
|
||||
const defaultsRaw = await readJson(
|
||||
path.join(scenarioRoot, 'default.json')
|
||||
);
|
||||
const defaultsRaw = await readJson(path.join(scenarioRoot, 'default.json'));
|
||||
const defaults = parseScenarioDefaults(defaultsRaw);
|
||||
|
||||
expect(defaults.stat.total).toBe(165);
|
||||
@@ -37,12 +32,8 @@ describe('scenario parser', () => {
|
||||
});
|
||||
|
||||
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 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);
|
||||
|
||||
@@ -51,23 +42,19 @@ describe('scenario parser', () => {
|
||||
});
|
||||
|
||||
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 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];
|
||||
const firstNation = scenario.nations[0]!;
|
||||
expect(firstNation.name).toBe('후한');
|
||||
expect(firstNation.color).toBe('#800000');
|
||||
|
||||
const firstGeneral = scenario.generals[0];
|
||||
const firstGeneral = scenario.generals[0]!;
|
||||
expect(firstGeneral.name).toBe('소제1');
|
||||
expect(firstGeneral.affinity).toBe(1);
|
||||
expect(firstGeneral.picture).toBe(1001);
|
||||
|
||||
@@ -69,6 +69,7 @@ const buildCity = (): City => ({
|
||||
name: 'TestCity',
|
||||
nationId: 1,
|
||||
level: 2,
|
||||
state: 0,
|
||||
population: 10000,
|
||||
populationMax: 10000,
|
||||
agriculture: 500,
|
||||
@@ -163,27 +164,15 @@ const buildUnitSet = (): UnitSetDefinition => ({
|
||||
|
||||
describe('trait modules', () => {
|
||||
it('loads trait modules by key', async () => {
|
||||
const domestic = await loadDomesticTraitModules([
|
||||
'che_인덕',
|
||||
'che_발명',
|
||||
]);
|
||||
const domestic = await loadDomesticTraitModules(['che_인덕', 'che_발명']);
|
||||
const war = await loadWarTraitModules(['che_의술', 'che_징병']);
|
||||
|
||||
expect(domestic.map((module) => module.key)).toEqual([
|
||||
'che_인덕',
|
||||
'che_발명',
|
||||
]);
|
||||
expect(war.map((module) => module.key)).toEqual([
|
||||
'che_의술',
|
||||
'che_징병',
|
||||
]);
|
||||
expect(domestic.map((module) => module.key)).toEqual(['che_인덕', 'che_발명']);
|
||||
expect(war.map((module) => module.key)).toEqual(['che_의술', 'che_징병']);
|
||||
});
|
||||
|
||||
it('applies domestic and war modifiers in general pipeline', async () => {
|
||||
const domestic = await loadDomesticTraitModules([
|
||||
'che_인덕',
|
||||
'che_발명',
|
||||
]);
|
||||
const domestic = await loadDomesticTraitModules(['che_인덕', 'che_발명']);
|
||||
const war = await loadWarTraitModules(['che_의술', 'che_징병']);
|
||||
const registry = createTraitModuleRegistry({ domestic, war });
|
||||
const traitModules = createTraitModules(registry);
|
||||
@@ -204,20 +193,13 @@ describe('trait modules', () => {
|
||||
});
|
||||
|
||||
const context = { general };
|
||||
expect(
|
||||
pipeline.onCalcDomestic(context, '민심', 'score', 100)
|
||||
).toBeCloseTo(110);
|
||||
expect(
|
||||
pipeline.onCalcDomestic(context, '징병', 'train', 40)
|
||||
).toBe(70);
|
||||
expect(pipeline.onCalcDomestic(context, '민심', 'score', 100)).toBeCloseTo(110);
|
||||
expect(pipeline.onCalcDomestic(context, '징병', 'train', 40)).toBe(70);
|
||||
expect(pipeline.onCalcStat(context, 'leadership', 80)).toBe(100);
|
||||
});
|
||||
|
||||
it('heals city generals with 의술 pre-turn trigger', async () => {
|
||||
const domestic = await loadDomesticTraitModules([
|
||||
'che_인덕',
|
||||
'che_발명',
|
||||
]);
|
||||
const domestic = await loadDomesticTraitModules(['che_인덕', 'che_발명']);
|
||||
const war = await loadWarTraitModules(['che_의술', 'che_징병']);
|
||||
const registry = createTraitModuleRegistry({ domestic, war });
|
||||
const traitModules = createTraitModules(registry);
|
||||
@@ -270,10 +252,7 @@ describe('trait modules', () => {
|
||||
});
|
||||
|
||||
it('activates 의술 battle trigger and reduces damage', async () => {
|
||||
const domestic = await loadDomesticTraitModules([
|
||||
'che_인덕',
|
||||
'che_발명',
|
||||
]);
|
||||
const domestic = await loadDomesticTraitModules(['che_인덕', 'che_발명']);
|
||||
const war = await loadWarTraitModules(['che_의술', 'che_징병']);
|
||||
const registry = createTraitModuleRegistry({ domestic, war });
|
||||
const traitModules = createTraitModules(registry);
|
||||
@@ -281,7 +260,7 @@ describe('trait modules', () => {
|
||||
const rng = new RandUtil(new ConstantRNG(0));
|
||||
const config = buildConfig();
|
||||
const unitSet = buildUnitSet();
|
||||
const crewType = new WarCrewType(unitSet.crewTypes?.[0]!);
|
||||
const crewType = new WarCrewType(unitSet.crewTypes![0]);
|
||||
const city = buildCity();
|
||||
const nation = buildNation();
|
||||
const general = buildGeneral({
|
||||
@@ -315,7 +294,7 @@ describe('trait modules', () => {
|
||||
config,
|
||||
city,
|
||||
nation,
|
||||
new WarCrewType(unitSet.crewTypes?.[1]!),
|
||||
new WarCrewType(unitSet.crewTypes![1]),
|
||||
new ActionLogger({}),
|
||||
200,
|
||||
180
|
||||
@@ -325,9 +304,7 @@ describe('trait modules', () => {
|
||||
defender.setOppose(attacker);
|
||||
attacker.beginPhase();
|
||||
|
||||
const caller = attacker
|
||||
.getActionPipeline()
|
||||
.getBattlePhaseTriggerList(attacker.getActionContext());
|
||||
const caller = attacker.getActionPipeline().getBattlePhaseTriggerList(attacker.getActionContext());
|
||||
caller.fire({ rng, attacker, defender }, createWarTriggerEnv());
|
||||
|
||||
expect(defender.getWarPowerMultiply()).toBeCloseTo(0.7);
|
||||
|
||||
@@ -49,6 +49,7 @@ const buildCity = (id: number, nationId: number): City => ({
|
||||
name: `City${id}`,
|
||||
nationId,
|
||||
level: 2,
|
||||
state: 0,
|
||||
population: 10000,
|
||||
populationMax: 10000,
|
||||
agriculture: 1000,
|
||||
|
||||
@@ -94,6 +94,7 @@ const buildCity = (): City => ({
|
||||
name: 'TestCity',
|
||||
nationId: 1,
|
||||
level: 2,
|
||||
state: 0,
|
||||
population: 10000,
|
||||
populationMax: 10000,
|
||||
agriculture: 500,
|
||||
@@ -160,7 +161,7 @@ describe('war triggers', () => {
|
||||
it('activates and applies critical damage', async () => {
|
||||
const rng = new RandUtil(new ConstantRNG(0));
|
||||
const config = buildConfig();
|
||||
const crewType = new WarCrewType(buildUnitSet().crewTypes?.[0]!);
|
||||
const crewType = new WarCrewType(buildUnitSet().crewTypes![0]);
|
||||
const nation = buildNation();
|
||||
const city = buildCity();
|
||||
|
||||
@@ -180,7 +181,7 @@ describe('war triggers', () => {
|
||||
config,
|
||||
city,
|
||||
nation,
|
||||
new WarCrewType(buildUnitSet().crewTypes?.[1]!),
|
||||
new WarCrewType(buildUnitSet().crewTypes![1]),
|
||||
new ActionLogger({}),
|
||||
200,
|
||||
180
|
||||
@@ -199,10 +200,7 @@ describe('war triggers', () => {
|
||||
if (!caller) {
|
||||
throw new Error('Missing che_필살 trigger list');
|
||||
}
|
||||
caller.fire(
|
||||
{ rng, attacker, defender },
|
||||
{ e_attacker: {}, e_defender: {} }
|
||||
);
|
||||
caller.fire({ rng, attacker, defender }, { e_attacker: {}, e_defender: {} });
|
||||
|
||||
expect(attacker.hasActivatedSkill('필살')).toBe(true);
|
||||
expect(attacker.getWarPowerMultiply()).toBeCloseTo(1.3);
|
||||
|
||||
Reference in New Issue
Block a user