Files
core2026/app/game-engine/src/turn/oldNationArchive.ts
T
Hide_D 630bc29100 fix: 특수 유저 커맨드의 Ref 호환 경계를 보강한다
수뇌 국가 설정과 NPC 정책을 actor-bound ENGINE mutation으로 옮기고, 추방·등용·점령·멸망·아이템 폐기의 특수 분기를 Ref와 맞춘다.

요청 ID를 사용자·프로필별로 격리하고 토너먼트 손상 projection을 fail-closed하며 실제 DB 및 Ref 차등 회귀를 보강한다.
2026-08-24 12:10:57 +00:00

47 lines
1.6 KiB
TypeScript

import { asRecord } from '@sammo-ts/common';
import type { Nation } from '@sammo-ts/logic';
const readNumber = (value: unknown): number => {
const parsed = typeof value === 'string' ? Number(value) : value;
return typeof parsed === 'number' && Number.isFinite(parsed) ? parsed : 0;
};
const readTextArray = (value: unknown): string[] =>
Array.isArray(value) ? value.filter((entry): entry is string => typeof entry === 'string') : [];
const readArchiveText = (values: readonly unknown[], fallback: string | null): string | null => {
const value = values.find((candidate) => candidate !== undefined && candidate !== null);
return value === undefined ? fallback : String(value);
};
export const buildOldNationArchiveData = (options: {
nation: Nation;
generalIds: readonly number[];
history: readonly string[];
}): Record<string, unknown> => {
const { nation } = options;
const meta = asRecord(nation.meta);
const maxPower = asRecord(meta.max_power);
const aux = {
...asRecord(meta.aux),
...maxPower,
};
const maxCities = readTextArray(maxPower.maxCities);
const nationNotice = asRecord(meta.nationNotice);
return {
...nation,
nation: nation.id,
type: nation.typeCode,
tech: readNumber(meta.tech),
maxPower: readNumber(maxPower.maxPower),
maxCrew: readNumber(maxPower.maxCrew),
maxCities,
aux,
generals: [...options.generalIds],
history: [...options.history],
msg: readArchiveText([meta.notice, nationNotice.msg, meta.msg], ''),
scout_msg: readArchiveText([meta.infoText, meta.scout_msg], null),
};
};