Normalize campaign reward labels
This commit is contained in:
@@ -856,7 +856,14 @@ function recordOrEmpty<T = unknown>(value: unknown): Record<string, T> {
|
||||
}
|
||||
|
||||
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[]) {
|
||||
@@ -1464,18 +1471,18 @@ function cloneCampaignRewardSnapshot(rewards?: CampaignRewardSnapshot): Campaign
|
||||
recruits: arrayOrEmpty<unknown>(rewardRecord.recruits)
|
||||
.filter(isPlainObject)
|
||||
.map((recruit) => ({
|
||||
unitId: typeof recruit.unitId === 'string' ? recruit.unitId : '',
|
||||
name: typeof recruit.name === 'string' ? recruit.name : ''
|
||||
unitId: typeof recruit.unitId === 'string' ? recruit.unitId.trim() : '',
|
||||
name: typeof recruit.name === 'string' ? recruit.name.trim() : ''
|
||||
}))
|
||||
.filter((recruit) => recruit.unitId && recruit.name),
|
||||
unlocks: arrayOrEmpty<unknown>(rewardRecord.unlocks)
|
||||
.filter(isPlainObject)
|
||||
.map((unlock) => ({
|
||||
battleId: typeof unlock.battleId === 'string' ? unlock.battleId : '',
|
||||
title: typeof unlock.title === 'string' ? unlock.title : ''
|
||||
battleId: typeof unlock.battleId === 'string' ? unlock.battleId.trim() : '',
|
||||
title: typeof unlock.title === 'string' ? unlock.title.trim() : ''
|
||||
}))
|
||||
.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