debug: log raw credits value in Finance Ledger, multi-path read, string corruption guard
This commit is contained in:
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
"id": "zero-engine",
|
"id": "zero-engine",
|
||||||
"title": "Zero Engine (SLA Industries)",
|
"title": "Zero Engine (SLA Industries)",
|
||||||
"description": "A basic game system for SLA Industries using the Zero Engine rules.",
|
"description": "A basic game system for SLA Industries using the Zero Engine rules.",
|
||||||
"version": "1.4.7",
|
"version": "1.4.8",
|
||||||
"compatibility": {
|
"compatibility": {
|
||||||
"minimum": 13,
|
"minimum": 13,
|
||||||
"verified": "14.359"
|
"verified": "14.359"
|
||||||
|
|||||||
+17
-5
@@ -5559,9 +5559,21 @@ class SLAGMFinanceTool extends Application {
|
|||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Parse a credit value safely — NaN, null, undefined all become 0 */
|
/** Parse a credit value safely, trying multiple read paths */
|
||||||
_safeCredits(val) {
|
_safeCredits(actor) {
|
||||||
const n = Number(val);
|
// Try direct access, then foundry safe getter, then toObject fallback
|
||||||
|
let raw = actor.system?.details?.credits;
|
||||||
|
if (raw === undefined || raw === null)
|
||||||
|
raw = foundry.utils.getProperty(actor, 'system.details.credits');
|
||||||
|
if (raw === undefined || raw === null)
|
||||||
|
raw = actor.toObject?.()?.system?.details?.credits;
|
||||||
|
|
||||||
|
// Handle "500,500" string corruption from duplicate form inputs
|
||||||
|
if (typeof raw === 'string' && raw.includes(','))
|
||||||
|
raw = raw.split(',')[0];
|
||||||
|
|
||||||
|
const n = Number(raw);
|
||||||
|
console.log(`Zero Engine | Finance Ledger: ${actor.name} credits raw=${JSON.stringify(raw)} → ${n}`);
|
||||||
return isNaN(n) ? 0 : n;
|
return isNaN(n) ? 0 : n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5577,7 +5589,7 @@ class SLAGMFinanceTool extends Application {
|
|||||||
return {
|
return {
|
||||||
id: a.id,
|
id: a.id,
|
||||||
name: a.name,
|
name: a.name,
|
||||||
credits: this._safeCredits(a.system.details?.credits),
|
credits: this._safeCredits(a),
|
||||||
weeklyIncome,
|
weeklyIncome,
|
||||||
weeklyExpenses,
|
weeklyExpenses,
|
||||||
netWeekly
|
netWeekly
|
||||||
@@ -5594,7 +5606,7 @@ class SLAGMFinanceTool extends Application {
|
|||||||
const weeklyIncome = (inc.salary||0) + (inc.bpnReward||0) + (inc.other||0);
|
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 weeklyExpenses = (exp.accommodation||0) + (exp.drugs||0) + (exp.subscriptions||0) + (exp.other||0) + (exp.bulletTax||0);
|
||||||
const net = weeklyIncome - weeklyExpenses;
|
const net = weeklyIncome - weeklyExpenses;
|
||||||
const current = this._safeCredits(actor.system?.details?.credits);
|
const current = this._safeCredits(actor);
|
||||||
const newBal = current + net;
|
const newBal = current + net;
|
||||||
await actor.update({ 'system.details.credits': newBal });
|
await actor.update({ 'system.details.credits': newBal });
|
||||||
ui.notifications.info(
|
ui.notifications.info(
|
||||||
|
|||||||
Reference in New Issue
Block a user