Fixed error where dependency loops including classLevels break the sheet
This commit is contained in:
@@ -10,6 +10,7 @@ export default class CreatureComputation {
|
||||
this.scope = {};
|
||||
this.props = properties;
|
||||
this.dependencyGraph = createGraph();
|
||||
this.errors = [];
|
||||
|
||||
// Store properties for easy access later
|
||||
properties.forEach(prop => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export default function aggregateClassLevel({node, linkedNode, link}){
|
||||
if (node.data.inactive) return;
|
||||
if (link.data === 'classLevel'){
|
||||
if (node.data.inactive) return;
|
||||
if (!node.data.classLevelAggregator) node.data.classLevelAggregator = {
|
||||
levelsFilled: [true], // Level 0 is always filled
|
||||
level: 0,
|
||||
@@ -11,6 +11,6 @@ export default function aggregateClassLevel({node, linkedNode, link}){
|
||||
aggregator.levelsFilled[linkedProp.level] = true;
|
||||
} else if (link.data === 'level'){
|
||||
node.data.baseValue = (node.data.baseValue || 0) +
|
||||
linkedNode.data.classLevelAggregator.level;
|
||||
(linkedNode.data.classLevelAggregator?.level || 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import computeToggles from '/imports/api/engine/computation/computeComputation/computeToggles.js';
|
||||
import computeByType from '/imports/api/engine/computation/computeComputation/computeByType.js';
|
||||
import embedInlineCalculations from './utility/embedInlineCalculations.js';
|
||||
import path from 'ngraph.path';
|
||||
|
||||
export default function computeCreatureComputation(computation){
|
||||
const stack = [];
|
||||
@@ -27,7 +28,7 @@ export default function computeCreatureComputation(computation){
|
||||
} else {
|
||||
top._visitedChildren = true;
|
||||
// Push dependencies to graph to be computed first
|
||||
pushDependenciesToStack(top.id, graph, stack);
|
||||
pushDependenciesToStack(top.id, graph, stack, computation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,8 +43,20 @@ function compute(computation, node){
|
||||
computeByType[node.data?.type || '_variable']?.(computation, node);
|
||||
}
|
||||
|
||||
function pushDependenciesToStack(nodeId, graph, stack){
|
||||
function pushDependenciesToStack(nodeId, graph, stack, computation){
|
||||
graph.forEachLinkedNode(nodeId, linkedNode => {
|
||||
if (linkedNode._visitedChildren && !linkedNode._visited){
|
||||
const pather = path.nba(graph, {
|
||||
oriented: true
|
||||
});
|
||||
const loop = pather.find(nodeId, nodeId);
|
||||
computation.errors.push({
|
||||
type: 'dependencyLoop',
|
||||
details: {
|
||||
nodes: loop.map(node => node.id)
|
||||
},
|
||||
});
|
||||
}
|
||||
stack.push(linkedNode);
|
||||
}, true);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import Creatures from '/imports/api/creature/creatures/Creatures.js';
|
||||
|
||||
export default function(creatureId, errors = []){
|
||||
if (errors.length){
|
||||
Creatures.update(creatureId, {$set: {computeErrors: errors}});
|
||||
} else {
|
||||
Creatures.update(creatureId, {$unset: {computeErrors: 1}});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user