Normalize campaign inventory labels

This commit is contained in:
2026-07-05 10:46:07 +09:00
parent 788e2ce21a
commit a0ced53e8d
2 changed files with 10 additions and 4 deletions

View File

@@ -901,9 +901,12 @@ function normalizeNonNegativeInteger(value: unknown) {
function normalizeInventory(value: unknown) {
return Object.entries(recordOrEmpty(value)).reduce<Record<string, number>>((inventory, [itemId, amount]) => {
const normalizedItemId = itemId.replace(/\s+/g, ' ').trim();
const normalizedAmount = normalizeNonNegativeInteger(amount);
if (itemId && normalizedAmount > 0) {
inventory[itemId] = normalizedAmount;
if (normalizedItemId && normalizedAmount > 0) {
const nextAmount = (inventory[normalizedItemId] ?? 0) + normalizedAmount;
const cap = campaignInventoryCaps[normalizedItemId];
inventory[normalizedItemId] = cap ? Math.min(nextAmount, cap) : nextAmount;
}
return inventory;
}, {});