Normalize campaign reward labels
This commit is contained in:
@@ -343,11 +343,12 @@ try {
|
|||||||
mvp: { unitId: 'liu-bei', name: 'Liu Bei', damageDealt: '88', defeats: '2' },
|
mvp: { unitId: 'liu-bei', name: 'Liu Bei', damageDealt: '88', defeats: '2' },
|
||||||
itemRewards: ['Bean', 'Bean', 10],
|
itemRewards: ['Bean', 'Bean', 10],
|
||||||
campaignRewards: {
|
campaignRewards: {
|
||||||
supplies: ['Bean', 'Bean', 20],
|
supplies: [' Bean ', 'Bean', 20],
|
||||||
equipment: ['Iron Sword'],
|
equipment: [' Iron Sword ', 'Iron Sword'],
|
||||||
reputation: ['Village Thanks'],
|
reputation: ['Village Thanks', ' Village Thanks '],
|
||||||
recruits: [{ unitId: 'guan-yu', name: 'Guan Yu' }, { unitId: '', name: 'Broken' }],
|
recruits: [{ unitId: ' guan-yu ', name: ' Guan Yu ' }, { unitId: '', name: 'Broken' }],
|
||||||
unlocks: [{ battleId: 'second-battle-yellow-turban-pursuit', title: 'Next' }, { battleId: '', title: 'Broken' }]
|
unlocks: [{ battleId: ' second-battle-yellow-turban-pursuit ', title: ' Next ' }, { battleId: '', title: 'Broken' }],
|
||||||
|
note: ' Reward note '
|
||||||
},
|
},
|
||||||
completedCampDialogues: ['intro', 'intro', 7],
|
completedCampDialogues: ['intro', 'intro', 7],
|
||||||
completedCampVisits: { corrupted: true },
|
completedCampVisits: { corrupted: true },
|
||||||
@@ -373,7 +374,13 @@ try {
|
|||||||
malformedReport.firstBattleReport.mvp?.damageDealt === 88 &&
|
malformedReport.firstBattleReport.mvp?.damageDealt === 88 &&
|
||||||
malformedReport.firstBattleReport.itemRewards.length === 1 &&
|
malformedReport.firstBattleReport.itemRewards.length === 1 &&
|
||||||
malformedReport.firstBattleReport.campaignRewards?.supplies.length === 1 &&
|
malformedReport.firstBattleReport.campaignRewards?.supplies.length === 1 &&
|
||||||
|
malformedReport.firstBattleReport.campaignRewards?.supplies[0] === 'Bean' &&
|
||||||
|
malformedReport.firstBattleReport.campaignRewards?.equipment.length === 1 &&
|
||||||
|
malformedReport.firstBattleReport.campaignRewards?.reputation.length === 1 &&
|
||||||
malformedReport.firstBattleReport.campaignRewards?.recruits.length === 1 &&
|
malformedReport.firstBattleReport.campaignRewards?.recruits.length === 1 &&
|
||||||
|
malformedReport.firstBattleReport.campaignRewards?.recruits[0].unitId === 'guan-yu' &&
|
||||||
|
malformedReport.firstBattleReport.campaignRewards?.unlocks[0].battleId === 'second-battle-yellow-turban-pursuit' &&
|
||||||
|
malformedReport.firstBattleReport.campaignRewards?.note === 'Reward note' &&
|
||||||
malformedReport.firstBattleReport.completedCampDialogues.length === 1 &&
|
malformedReport.firstBattleReport.completedCampDialogues.length === 1 &&
|
||||||
malformedReport.firstBattleReport.completedCampVisits.length === 0,
|
malformedReport.firstBattleReport.completedCampVisits.length === 0,
|
||||||
`Expected malformed report fields to be normalized without discarding the report: ${JSON.stringify(malformedReport)}`
|
`Expected malformed report fields to be normalized without discarding the report: ${JSON.stringify(malformedReport)}`
|
||||||
|
|||||||
@@ -856,7 +856,14 @@ function recordOrEmpty<T = unknown>(value: unknown): Record<string, T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function uniqueStrings(value: unknown): string[] {
|
function uniqueStrings(value: unknown): string[] {
|
||||||
return [...new Set(arrayOrEmpty<unknown>(value).filter((entry): entry is string => typeof entry === 'string' && entry.length > 0))];
|
return [
|
||||||
|
...new Set(
|
||||||
|
arrayOrEmpty<unknown>(value)
|
||||||
|
.filter((entry): entry is string => typeof entry === 'string')
|
||||||
|
.map((entry) => entry.trim())
|
||||||
|
.filter((entry) => entry.length > 0)
|
||||||
|
)
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizedRosterUnitIds(roster: UnitData[]) {
|
function normalizedRosterUnitIds(roster: UnitData[]) {
|
||||||
@@ -1464,18 +1471,18 @@ function cloneCampaignRewardSnapshot(rewards?: CampaignRewardSnapshot): Campaign
|
|||||||
recruits: arrayOrEmpty<unknown>(rewardRecord.recruits)
|
recruits: arrayOrEmpty<unknown>(rewardRecord.recruits)
|
||||||
.filter(isPlainObject)
|
.filter(isPlainObject)
|
||||||
.map((recruit) => ({
|
.map((recruit) => ({
|
||||||
unitId: typeof recruit.unitId === 'string' ? recruit.unitId : '',
|
unitId: typeof recruit.unitId === 'string' ? recruit.unitId.trim() : '',
|
||||||
name: typeof recruit.name === 'string' ? recruit.name : ''
|
name: typeof recruit.name === 'string' ? recruit.name.trim() : ''
|
||||||
}))
|
}))
|
||||||
.filter((recruit) => recruit.unitId && recruit.name),
|
.filter((recruit) => recruit.unitId && recruit.name),
|
||||||
unlocks: arrayOrEmpty<unknown>(rewardRecord.unlocks)
|
unlocks: arrayOrEmpty<unknown>(rewardRecord.unlocks)
|
||||||
.filter(isPlainObject)
|
.filter(isPlainObject)
|
||||||
.map((unlock) => ({
|
.map((unlock) => ({
|
||||||
battleId: typeof unlock.battleId === 'string' ? unlock.battleId : '',
|
battleId: typeof unlock.battleId === 'string' ? unlock.battleId.trim() : '',
|
||||||
title: typeof unlock.title === 'string' ? unlock.title : ''
|
title: typeof unlock.title === 'string' ? unlock.title.trim() : ''
|
||||||
}))
|
}))
|
||||||
.filter((unlock) => unlock.battleId && unlock.title),
|
.filter((unlock) => unlock.battleId && unlock.title),
|
||||||
note: typeof rewardRecord.note === 'string' ? rewardRecord.note : undefined
|
note: typeof rewardRecord.note === 'string' && rewardRecord.note.trim().length > 0 ? rewardRecord.note.trim() : undefined
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user