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_SUPPLY_STATE = 1;
|
||||||
const DEFAULT_CITY_FRONT_STATE = 0;
|
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 => {
|
const canonicalizeDomesticTrait = (raw: string | null | undefined): string | null => {
|
||||||
if (!raw || raw === 'None') {
|
if (!raw || raw === 'None') {
|
||||||
return null;
|
return null;
|
||||||
@@ -484,6 +500,7 @@ const buildGeneralSeeds = (
|
|||||||
for (const row of rows) {
|
for (const row of rows) {
|
||||||
const id = nextId;
|
const id = nextId;
|
||||||
nextId += 1;
|
nextId += 1;
|
||||||
|
const name = decorateLegacyGeneralName(row.name, npcType);
|
||||||
|
|
||||||
const nationId = resolveNationId(row.nation, nationNameToId, warnings, row.name);
|
const nationId = resolveNationId(row.nation, nationNameToId, warnings, row.name);
|
||||||
let cityId = resolveCityId(row.city, cityByName, warnings, row.name);
|
let cityId = resolveCityId(row.city, cityByName, warnings, row.name);
|
||||||
@@ -555,7 +572,7 @@ const buildGeneralSeeds = (
|
|||||||
|
|
||||||
const seed: GeneralSeed = {
|
const seed: GeneralSeed = {
|
||||||
id,
|
id,
|
||||||
name: row.name,
|
name,
|
||||||
nationId,
|
nationId,
|
||||||
cityId,
|
cityId,
|
||||||
stats,
|
stats,
|
||||||
@@ -610,7 +627,7 @@ const buildGeneralSeeds = (
|
|||||||
|
|
||||||
generals.push({
|
generals.push({
|
||||||
id,
|
id,
|
||||||
name: row.name,
|
name,
|
||||||
nationId,
|
nationId,
|
||||||
cityId,
|
cityId,
|
||||||
troopId: 0,
|
troopId: 0,
|
||||||
|
|||||||
@@ -106,7 +106,24 @@ describe('scenario bootstrap', () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
generalsEx: [],
|
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: [],
|
cities: [],
|
||||||
events: [],
|
events: [],
|
||||||
initialEvents: [],
|
initialEvents: [],
|
||||||
@@ -159,6 +176,18 @@ describe('scenario bootstrap', () => {
|
|||||||
expect(result.seed.cities[0]?.nationId).toBe(1);
|
expect(result.seed.cities[0]?.nationId).toBe(1);
|
||||||
expect(result.snapshot.generals[0]?.cityId).toBe(1);
|
expect(result.snapshot.generals[0]?.cityId).toBe(1);
|
||||||
expect(result.snapshot.generals[0]?.crewTypeId).toBe(1200);
|
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.specialDomestic).toBe('Special');
|
||||||
expect(result.snapshot.generals[0]?.role.specialWar).toBeNull();
|
expect(result.snapshot.generals[0]?.role.specialWar).toBeNull();
|
||||||
expect(result.snapshot.generals[1]?.role).toMatchObject({
|
expect(result.snapshot.generals[1]?.role).toMatchObject({
|
||||||
@@ -442,8 +471,8 @@ describe('scenario bootstrap', () => {
|
|||||||
|
|
||||||
const result = buildScenarioBootstrap({ scenario, map });
|
const result = buildScenarioBootstrap({ scenario, map });
|
||||||
|
|
||||||
expect(result.seed.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.snapshot.generals.map((row) => row.name)).toEqual(['ⓝ현재']);
|
||||||
expect(result.seed.events).toEqual([
|
expect(result.seed.events).toEqual([
|
||||||
['Month', 500, ['Date', '>=', 200, 1], ['Existing']],
|
['Month', 500, ['Date', '>=', 200, 1], ['Existing']],
|
||||||
[
|
[
|
||||||
|
|||||||
Reference in New Issue
Block a user