From 2c89323764dbdd3c58d2b9ebe8c9440a36f9b385 Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Fri, 23 Jun 2023 12:21:51 +0200 Subject: [PATCH] Fixed errors with empty quantity ammo resources --- .../api/engine/actions/applyPropertyByType/applyAction.js | 5 +++-- .../computation/buildComputation/linkTypeDependencies.js | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/imports/api/engine/actions/applyPropertyByType/applyAction.js b/app/imports/api/engine/actions/applyPropertyByType/applyAction.js index 3551bf0b..3aa87df9 100644 --- a/app/imports/api/engine/actions/applyPropertyByType/applyAction.js +++ b/app/imports/api/engine/actions/applyPropertyByType/applyAction.js @@ -225,7 +225,7 @@ function spendResources(prop, actionContext) { throw 'The prop\'s ammo was not found on the creature'; } if ( - !itemConsumed.quantity.value || + !itemConsumed?.quantity?.value || !isFinite(itemConsumed.quantity.value) ) return; itemQuantityAdjustments.push({ @@ -247,8 +247,9 @@ function spendResources(prop, actionContext) { } catch (e) { actionContext.addLog({ name: 'Error', - value: e, + value: e.toString(), }); + console.error(e); return true; } // No more errors should be thrown after this line diff --git a/app/imports/api/engine/computation/buildComputation/linkTypeDependencies.js b/app/imports/api/engine/computation/buildComputation/linkTypeDependencies.js index 0a856386..4a83ab62 100644 --- a/app/imports/api/engine/computation/buildComputation/linkTypeDependencies.js +++ b/app/imports/api/engine/computation/buildComputation/linkTypeDependencies.js @@ -29,9 +29,9 @@ export default function linkTypeDependencies(dependencyGraph, prop, computation) function dependOnCalc({ dependencyGraph, prop, key }) { let calc = get(prop, key); - if (!calc) return; + if (!calc?.type) return; if (calc.type !== '_calculation') { - throw `Expected calculation got ${calc.type}` + throw `Failed to dependOnCal for prop: ${prop._id}, key: ${key}. Expected calculation got ${calc.type}` } dependencyGraph.addLink(prop._id, `${prop._id}.${key}`, 'calculation'); }