Files
DiceCloud/app/imports/api/engine/computation/buildComputation/computeSlotQuantityFilled.js
2021-09-27 14:28:32 +02:00

22 lines
637 B
JavaScript

/**
* Only computes `totalFilled`, need to compute `quantityExpected.value`
* before `spacesLeft` can be computed
*/
export default function computeSlotQuantityFilled(node, dependencyGraph){
let slot = node.node;
if (slot.type !== 'propertySlot') return;
slot.totalFilled = 0;
node.children.forEach(child => {
let childProp = child.node;
dependencyGraph.addLink(slot._id, childProp._id, 'slotFill');
if (
childProp.type === 'slotFiller' &&
Number.isFinite(childProp.slotQuantityFilled)
){
slot.totalFilled += childProp.slotQuantityFilled;
} else {
slot.totalFilled++;
}
});
}