refactor: tighten backend and logic boundaries

This commit is contained in:
2026-08-15 06:46:52 +00:00
parent 7b02ff155f
commit 35d8824b95
86 changed files with 820 additions and 1872 deletions
+3 -31
View File
@@ -1,7 +1,7 @@
import type { City, Nation } from '@sammo-ts/logic';
import { asRecord, isRecord } from '@sammo-ts/common';
import type { City } from '@sammo-ts/logic';
import { asRecord } from '@sammo-ts/common';
export { asRecord, isRecord };
export { asRecord };
export const readNumber = (value: unknown, fallback = 0): number => {
if (typeof value === 'number' && Number.isFinite(value)) {
@@ -16,21 +16,6 @@ export const readNumber = (value: unknown, fallback = 0): number => {
return fallback;
};
export const readBoolean = (value: unknown, fallback = false): boolean => {
if (typeof value === 'boolean') {
return value;
}
if (typeof value === 'number') {
return value !== 0;
}
if (typeof value === 'string') {
return value === 'true' || value === '1';
}
return fallback;
};
export const readString = (value: unknown, fallback = ''): string => (typeof value === 'string' ? value : fallback);
export const readMetaNumber = (meta: Record<string, unknown>, key: string, fallback = 0): number =>
readNumber(meta[key], fallback);
@@ -49,12 +34,6 @@ export const readRequiredMetaNumber = (meta: Record<string, unknown>, key: strin
throw new Error(`meta.${key} is required${suffix}.`);
};
export const readMetaString = (meta: Record<string, unknown>, key: string, fallback = ''): string =>
readString(meta[key], fallback);
export const readMetaBoolean = (meta: Record<string, unknown>, key: string, fallback = false): boolean =>
readBoolean(meta[key], fallback);
export const valueFit = (value: number, min?: number | null, max?: number | null): number => {
let next = value;
if (min !== null && min !== undefined && next < min) {
@@ -108,10 +87,3 @@ export const calcCityDevRatio = (city: City): number => {
}
return total / max;
};
export const readNationTech = (nation: Nation | null | undefined): number => {
if (!nation) {
return 0;
}
return readMetaNumber(asRecord(nation.meta), 'tech', 0);
};
@@ -7,30 +7,7 @@ import { do후방워프, do전방워프, do내정워프, do귀환, do집합 } fr
import { doNPC헌납, doNPC사망대비 } from './npcActions.js';
import { do국가선택, do중립, do거병, do건국, do해산, do선양, do방랑군이동 } from './politicsActions.js';
export {
do일반내정,
do긴급내정,
do전쟁내정,
do금쌀구매,
do징병,
do전투준비,
do소집해제,
do출병,
do후방워프,
do전방워프,
do내정워프,
do귀환,
do집합,
doNPC헌납,
doNPC사망대비,
do국가선택,
do중립,
do거병,
do건국,
do해산,
do선양,
do방랑군이동,
};
export { do징병 };
export const generalActionHandlers: Record<
string,
@@ -12,29 +12,6 @@ import { do유저장긴급포상, do유저장포상, doNPC긴급포상, doNPC포
import { do불가침제의, do선전포고 } from './diplomacy.js';
import { do천도 } from './capital.js';
export {
do부대전방발령,
do부대후방발령,
do부대구출발령,
do부대유저장후방발령,
do유저장후방발령,
do유저장구출발령,
do유저장전방발령,
do유저장내정발령,
doNPC후방발령,
doNPC구출발령,
doNPC전방발령,
doNPC내정발령,
do유저장긴급포상,
do유저장포상,
doNPC긴급포상,
doNPC포상,
doNPC몰수,
do불가침제의,
do선전포고,
do천도,
};
export const nationActionHandlers: Record<
string,
(ai: GeneralAI) => ReturnType<GeneralAI['buildNationCandidate']> | null