From e1d670fe9fa8e18d8696d0801811ef54379e4142 Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Wed, 24 Feb 2021 15:05:53 +0200 Subject: [PATCH] Fixed: buffs --- app/imports/api/creature/actions/applyBuff.js | 8 +++++++- .../api/creature/actions/applyProperties.js | 15 ++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/app/imports/api/creature/actions/applyBuff.js b/app/imports/api/creature/actions/applyBuff.js index 2bde6c85..cfed0cd6 100644 --- a/app/imports/api/creature/actions/applyBuff.js +++ b/app/imports/api/creature/actions/applyBuff.js @@ -4,6 +4,7 @@ import { } from '/imports/api/parenting/parenting.js'; import {setDocToLastOrder} from '/imports/api/parenting/order.js'; import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js'; +import { recomputeCreatureByDoc } from '/imports/api/creature/computation/methods/recomputeCreature.js'; export default function applyBuff({ prop, @@ -57,5 +58,10 @@ function copyNodeListToTarget(propList, target, oldParent){ collection: CreatureProperties, doc: propList[0], }); - CreatureProperties.batchInsert(propList); + + CreatureProperties.batchInsert(propList, () => { + // This insert is racing the main recompute, recmpute again after it's + // certainly finished + recomputeCreatureByDoc(target); + }); } diff --git a/app/imports/api/creature/actions/applyProperties.js b/app/imports/api/creature/actions/applyProperties.js index c078f87a..a1f69b74 100644 --- a/app/imports/api/creature/actions/applyProperties.js +++ b/app/imports/api/creature/actions/applyProperties.js @@ -52,23 +52,24 @@ function applyProperty(options){ return true; } -function applyPropertyAndWalkChildren({prop, child, targets, ...options}){ - let shouldKeepWalking = applyProperty({ prop, targets, ...options }); +function applyPropertyAndWalkChildren({prop, children, targets, ...options}){ + let shouldKeepWalking = applyProperty({ prop, children, targets, ...options }); if (shouldKeepWalking){ - applyProperties({ forest: child.children, targets, ...options,}); + applyProperties({ forest: children, targets, ...options,}); } } export default function applyProperties({ forest, targets, ...options}){ - forest.forEach(child => { - let prop = child.node; + forest.forEach(node => { + let prop = node.node; + let children = node.children; if (shouldSplit(prop) && targets.length){ targets.forEach(target => { let targets = [target] - applyPropertyAndWalkChildren({ targets, prop, child, ...options}); + applyPropertyAndWalkChildren({ targets, prop, children, ...options}); }); } else { - applyPropertyAndWalkChildren({prop, child, targets, ...options}); + applyPropertyAndWalkChildren({prop, children, targets, ...options}); } }); }