fix: preserve NPC name prefixes in scenario bootstrap
This commit is contained in:
@@ -97,6 +97,22 @@ const DEFAULT_CITY_TRADE = 100;
|
||||
const DEFAULT_CITY_SUPPLY_STATE = 1;
|
||||
const DEFAULT_CITY_FRONT_STATE = 0;
|
||||
|
||||
// Ref Scenario\GeneralBuilder::build() decorates the persisted name after
|
||||
// setNPCType(); scenario JSON keeps the undecorated source name.
|
||||
const LEGACY_GENERAL_NAME_PREFIX_BY_NPC_TYPE: Readonly<Record<number, string>> = {
|
||||
0: '',
|
||||
1: 'ⓝ',
|
||||
2: 'ⓝ',
|
||||
3: 'ⓜ',
|
||||
4: 'ⓖ',
|
||||
5: '㉥',
|
||||
6: 'ⓤ',
|
||||
9: 'ⓞ',
|
||||
};
|
||||
|
||||
const decorateLegacyGeneralName = (name: string, npcType: number): string =>
|
||||
`${LEGACY_GENERAL_NAME_PREFIX_BY_NPC_TYPE[npcType] ?? 'ⓧ'}${name}`;
|
||||
|
||||
const canonicalizeDomesticTrait = (raw: string | null | undefined): string | null => {
|
||||
if (!raw || raw === 'None') {
|
||||
return null;
|
||||
@@ -484,6 +500,7 @@ const buildGeneralSeeds = (
|
||||
for (const row of rows) {
|
||||
const id = nextId;
|
||||
nextId += 1;
|
||||
const name = decorateLegacyGeneralName(row.name, npcType);
|
||||
|
||||
const nationId = resolveNationId(row.nation, nationNameToId, warnings, row.name);
|
||||
let cityId = resolveCityId(row.city, cityByName, warnings, row.name);
|
||||
@@ -555,7 +572,7 @@ const buildGeneralSeeds = (
|
||||
|
||||
const seed: GeneralSeed = {
|
||||
id,
|
||||
name: row.name,
|
||||
name,
|
||||
nationId,
|
||||
cityId,
|
||||
stats,
|
||||
@@ -610,7 +627,7 @@ const buildGeneralSeeds = (
|
||||
|
||||
generals.push({
|
||||
id,
|
||||
name: row.name,
|
||||
name,
|
||||
nationId,
|
||||
cityId,
|
||||
troopId: 0,
|
||||
|
||||
@@ -106,7 +106,24 @@ describe('scenario bootstrap', () => {
|
||||
},
|
||||
],
|
||||
generalsEx: [],
|
||||
generalsNeutral: [],
|
||||
generalsNeutral: [
|
||||
{
|
||||
affinity: 13,
|
||||
name: 'NeutralGeneral',
|
||||
picture: null,
|
||||
nation: null,
|
||||
city: 'Alpha',
|
||||
leadership: 50,
|
||||
strength: 50,
|
||||
intelligence: 50,
|
||||
officerLevel: 0,
|
||||
birthYear: 180,
|
||||
deathYear: 240,
|
||||
personality: 'Calm',
|
||||
special: '',
|
||||
text: null,
|
||||
},
|
||||
],
|
||||
cities: [],
|
||||
events: [],
|
||||
initialEvents: [],
|
||||
@@ -159,6 +176,18 @@ describe('scenario bootstrap', () => {
|
||||
expect(result.seed.cities[0]?.nationId).toBe(1);
|
||||
expect(result.snapshot.generals[0]?.cityId).toBe(1);
|
||||
expect(result.snapshot.generals[0]?.crewTypeId).toBe(1200);
|
||||
expect(result.seed.generals.map((general) => general.name)).toEqual([
|
||||
'ⓝTestGeneral',
|
||||
'ⓝMedicalGeneral',
|
||||
'ⓝChargeGeneral',
|
||||
'ⓤNeutralGeneral',
|
||||
]);
|
||||
expect(result.snapshot.generals.map((general) => general.name)).toEqual([
|
||||
'ⓝTestGeneral',
|
||||
'ⓝMedicalGeneral',
|
||||
'ⓝChargeGeneral',
|
||||
'ⓤNeutralGeneral',
|
||||
]);
|
||||
expect(result.snapshot.generals[0]?.role.specialDomestic).toBe('Special');
|
||||
expect(result.snapshot.generals[0]?.role.specialWar).toBeNull();
|
||||
expect(result.snapshot.generals[1]?.role).toMatchObject({
|
||||
@@ -442,8 +471,8 @@ describe('scenario bootstrap', () => {
|
||||
|
||||
const result = buildScenarioBootstrap({ scenario, map });
|
||||
|
||||
expect(result.seed.generals.map((row) => row.name)).toEqual(['현재']);
|
||||
expect(result.snapshot.generals.map((row) => row.name)).toEqual(['현재']);
|
||||
expect(result.seed.generals.map((row) => row.name)).toEqual(['ⓝ현재']);
|
||||
expect(result.snapshot.generals.map((row) => row.name)).toEqual(['ⓝ현재']);
|
||||
expect(result.seed.events).toEqual([
|
||||
['Month', 500, ['Date', '>=', 200, 1], ['Existing']],
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user