From ae5b4b7d5c5be39707d6e60dddb1bc127020d23c Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Mon, 11 Jan 2021 22:03:54 +0200 Subject: [PATCH] Made inactive toggle decendants specifically included when recomputing active properties --- .../creature/computation/recomputeCreature.js | 19 +++++++++++++++++-- .../recomputeInactiveProperties.js | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/app/imports/api/creature/computation/recomputeCreature.js b/app/imports/api/creature/computation/recomputeCreature.js index 53cc02af..6e4babd6 100644 --- a/app/imports/api/creature/computation/recomputeCreature.js +++ b/app/imports/api/creature/computation/recomputeCreature.js @@ -97,12 +97,26 @@ export function recomputeCreatureById(creatureId){ */ export function recomputeCreatureByDoc(creature){ const creatureId = creature._id; - recomputeInactiveProperties(creatureId); + // find all toggles that have conditions, even if they are inactive + let toggleIds = CreatureProperties.find({ + 'ancestors.id': creatureId, + type: 'toggle', + removed: {$ne: true}, + condition: { $exists: true }, + }, { + fields: {_id: 1}, + }).map(t => t._id); + // Find all the active properties let props = CreatureProperties.find({ 'ancestors.id': creatureId, - inactive: {$ne: true}, removed: {$ne: true}, type: {$in: calculationPropertyTypes}, + $or: [ + {inactive: {$ne: true}}, + // But also the inactive computed toggles and their decendants + {'ancestors.id': {$in: toggleIds}}, + {_id: {$in: toggleIds}}, + ] }, { fields: { // Filter out potentially large fields icon: 0, @@ -114,6 +128,7 @@ export function recomputeCreatureByDoc(creature){ } }).fetch(); let computationMemo = new ComputationMemo(props, creature); + recomputeInactiveProperties(creatureId); computeMemo(computationMemo); writeAlteredProperties(computationMemo); writeCreatureVariables(computationMemo, creatureId); diff --git a/app/imports/api/creature/denormalise/recomputeInactiveProperties.js b/app/imports/api/creature/denormalise/recomputeInactiveProperties.js index 87fb1d64..eb988f8b 100644 --- a/app/imports/api/creature/denormalise/recomputeInactiveProperties.js +++ b/app/imports/api/creature/denormalise/recomputeInactiveProperties.js @@ -7,6 +7,7 @@ export default function recomputeInactiveProperties(ancestorId){ {disabled: true}, // Everything can be disabled {type: 'buff', applied: false}, // Buffs can be applied {type: 'item', equipped: {$ne: true}}, + {type: 'toggle', toggleResult: false}, {type: 'spell', prepared: {$ne: true}, alwaysPrepared: {$ne: true}}, ], };