fix: prevent duplicate credits submission causing NaN corruption
The non-Mk2 sheet had two inputs named system.details.credits (header + finances tab). Foundry concatenates duplicate names as "500,500" which is not a valid number, causing the field to show blank/grey after saving. Fix: finances tab input made readonly with no name attribute — header is now the sole authoritative credits field. Also: on-boot sanitization now covers credits, fixing any actors already storing the corrupted comma-string value.
This commit is contained in:
@@ -3522,6 +3522,17 @@ Hooks.once('ready', function() {
|
||||
updates['system.flux.value'] = parseInt(rawFlux) || 0;
|
||||
console.warn(`Zero Engine | Sanitizing corrupt flux on actor "${actor.name}": "${rawFlux}" → ${updates['system.flux.value']}`);
|
||||
}
|
||||
// Fix credits corrupted by the duplicate-input "500,500" bug
|
||||
const rawCredits = actor._source?.system?.details?.credits ?? actor.system?.details?.credits;
|
||||
const creditsCorrupt = (typeof rawCredits === 'string' && (rawCredits.includes(',') || rawCredits === 'NaN' || isNaN(Number(rawCredits))))
|
||||
|| (typeof rawCredits === 'number' && isNaN(rawCredits));
|
||||
if (creditsCorrupt) {
|
||||
const fixed = typeof rawCredits === 'string' && rawCredits.includes(',')
|
||||
? parseInt(rawCredits.split(',')[0]) || 0
|
||||
: 0;
|
||||
updates['system.details.credits'] = fixed;
|
||||
console.warn(`Zero Engine | Sanitizing corrupt credits on actor "${actor.name}": "${rawCredits}" → ${fixed}`);
|
||||
}
|
||||
if (Object.keys(updates).length > 0) {
|
||||
await actor.update(updates);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user