Fixed error where dependency loops including classLevels break the sheet

This commit is contained in:
Stefan Zermatten
2022-02-26 13:06:00 +02:00
parent 59c69a46a8
commit 7ee4a22d77
9 changed files with 57 additions and 7 deletions

View File

@@ -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);
}