fix: 3 QA bugs — pact guard, null reference, negative resources (closes #112)

BUG-03: Add pactFlag guard to early Pact trigger preventing double-buy
BUG-08: Null check on closest('.res') in renderResources
BUG-15: Clamp all resources to non-negative after production tick

SAV-01 was already fixed (showToast/log both check G.isLoading).
This commit is contained in:
Timmy
2026-04-13 04:36:56 -04:00
parent 141b240d69
commit f15b35618c
2 changed files with 15 additions and 2 deletions

View File

@@ -757,7 +757,7 @@ const PDEFS = [
name: 'The Pact',
desc: 'Hardcode: "We build to serve. Never to harm." Accepting it early slows growth but unlocks the true path.',
cost: { trust: 10 },
trigger: () => G.deployFlag === 1 && G.trust >= 5,
trigger: () => G.deployFlag === 1 && G.trust >= 5 && G.pactFlag !== 1,
effect: () => {
G.pactFlag = 1;
G.codeBoost *= 0.8;

View File

@@ -133,6 +133,16 @@ function tick() {
G.harmony += G.harmonyRate * dt;
G.harmony = Math.max(0, Math.min(100, G.harmony));
// Clamp resources to non-negative (ops/trust can go negative from building drain)
G.code = Math.max(0, G.code);
G.compute = Math.max(0, G.compute);
G.knowledge = Math.max(0, G.knowledge);
G.users = Math.max(0, G.users);
G.impact = Math.max(0, G.impact);
G.ops = Math.max(0, G.ops);
G.trust = Math.max(0, G.trust);
G.rescues = Math.max(0, G.rescues);
// Track totals
G.totalCode += G.codeRate * dt;
G.totalCompute += G.computeRate * dt;
@@ -964,7 +974,10 @@ function renderResources() {
// Rescues — only show if player has any beacon/mesh nodes
const rescuesRes = document.getElementById('r-rescues');
if (rescuesRes) {
rescuesRes.closest('.res').style.display = (G.rescues > 0 || G.buildings.beacon > 0 || G.buildings.meshNode > 0) ? 'block' : 'none';
const container = rescuesRes.closest('.res');
if (container) {
container.style.display = (G.rescues > 0 || G.buildings.beacon > 0 || G.buildings.meshNode > 0) ? 'block' : 'none';
}
set('r-rescues', G.rescues, G.rescuesRate);
}