From 2945f66d9a512c6a67a00f48cb17ac27d566a7b1 Mon Sep 17 00:00:00 2001 From: Tim Evans Date: Tue, 2 Jun 2026 23:20:03 +0100 Subject: [PATCH] fix: guard against NaN credits in GM Finance Ledger --- system.json | 2 +- zero-engine.mjs | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/system.json b/system.json index e3e081b..8443011 100644 --- a/system.json +++ b/system.json @@ -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.6", + "version": "1.4.7", "compatibility": { "minimum": 13, "verified": "14.359" diff --git a/zero-engine.mjs b/zero-engine.mjs index 4188d62..a238c94 100644 --- a/zero-engine.mjs +++ b/zero-engine.mjs @@ -5559,6 +5559,12 @@ class SLAGMFinanceTool extends Application { return $html; } + /** Parse a credit value safely — NaN, null, undefined all become 0 */ + _safeCredits(val) { + const n = Number(val); + return isNaN(n) ? 0 : n; + } + _getPCData() { return (game.actors ?? []) .filter(a => a.type === 'character' && a.system?.details?.isPlayerCharacter) @@ -5571,7 +5577,7 @@ class SLAGMFinanceTool extends Application { return { id: a.id, name: a.name, - credits: Number(a.system.details?.credits ?? 0), + credits: this._safeCredits(a.system.details?.credits), weeklyIncome, weeklyExpenses, netWeekly @@ -5588,7 +5594,7 @@ class SLAGMFinanceTool extends Application { const weeklyIncome = (inc.salary||0) + (inc.bpnReward||0) + (inc.other||0); const weeklyExpenses = (exp.accommodation||0) + (exp.drugs||0) + (exp.subscriptions||0) + (exp.other||0) + (exp.bulletTax||0); const net = weeklyIncome - weeklyExpenses; - const current = Number(actor.system?.details?.credits ?? 0); + const current = this._safeCredits(actor.system?.details?.credits); const newBal = current + net; await actor.update({ 'system.details.credits': newBal }); ui.notifications.info(