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:
2026-06-03 00:01:46 +01:00
parent 5a43027ec8
commit b744b91354
3 changed files with 13 additions and 2 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
"id": "zero-engine",
"title": "Zero Engine (SLA Industries)",
"description": "A basic game system for SLA Industries using the Zero Engine rules.",
"version": "1.4.9",
"version": "1.5.0",
"compatibility": {
"minimum": 13,
"verified": "14.359"
+1 -1
View File
@@ -873,7 +873,7 @@
<div class="finances-credits-hero">
<span class="fin-credit-label">CURRENT BALANCE</span>
<span class="fin-credit-value"><input type="number" name="system.details.credits" value="{{system.details.credits}}" placeholder="500" min="0" /> c</span>
<span class="fin-credit-value credits-readonly-wrap"><input type="number" readonly value="{{system.details.credits}}" class="credits-readonly" title="Edit credits in the sheet header" /> c</span>
{{#if system.finances.debt}}<span class="fin-debt-badge">⚠ DEBT {{system.finances.debt}}c</span>{{/if}}
</div>
+11
View File
@@ -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);
}