Computation engine rewrite continues

This commit is contained in:
Stefan Zermatten
2021-09-10 19:51:03 +02:00
parent 28ec7082ee
commit b877a8b45f
15 changed files with 235 additions and 28 deletions

View File

@@ -0,0 +1,13 @@
/**
* Iterate through all the defining properties and choose the highest
* `baseValue.value`
*/
export default function aggregateBaseValue({node, linkedNode, link}){
if (link.data !== 'definition') return;
const propBaseValue = linkedNode.data.baseValue?.value;
if (propBaseValue === undefined) return;
if (node.baseValue === undefined || propBaseValue > node.baseValue){
node.baseValue = propBaseValue;
}
}

View File

@@ -0,0 +1,24 @@
export default function aggregateDefinitions({node, linkedNode, link}){
// Look at all definition links
if (link.data !== 'definition') return;
const prop = linkedNode.data;
// get current defining prop
const definingProp = node.data.definingProp;
// Find the last defining prop
if (!definingProp || prop.order > definingProp.order){
// override the current defining prop
overrideProp(definingProp, node);
// set this prop as the new defining prop
node.data.definingProp = prop;
} else {
overrideProp(prop, node);
}
}
function overrideProp(prop, node){
if (!prop) return;
prop.overriden = true;
if (!node.data.overridenProps) node.data.overridenProps = [];
node.data.overridenProp.push(prop);
}

View File

@@ -0,0 +1,17 @@
import definitions from '/imports/api/creature/computation/newEngine/computeComputation/aggregateProps/aggregateDefinitions.js';
import baseValue from '/imports/api/creature/computation/newEngine/computeComputation/aggregateProps/aggregateBaseValue.js';
import damageMultipliers from '/imports/api/creature/computation/newEngine/computeComputation/aggregateProps/aggregateDamageMultipliers.js';
import effects from '/imports/api/creature/computation/newEngine/computeComputation/aggregateProps/aggregateEffects.js';
import proficiencies from '/imports/api/creature/computation/newEngine/computeComputation/aggregateProps/aggregateProficiencies.js';
import skills from '/imports/api/creature/computation/newEngine/computeComputation/aggregateProps/aggregateProficiencies.js';
import toggles from '/imports/api/creature/computation/newEngine/computeComputation/aggregateProps/aggregateToggles.js';
export default Object.freeze({
definitions,
baseValue,
damageMultipliers,
effects,
proficiencies,
skills,
toggles,
});

View File

@@ -0,0 +1,33 @@
import aggregate from '/imports/api/creature/computation/newEngine/computeComputation/aggregateProps/index.js';
export default function computeVariable(graph, node){
if (!node.data) node.data = {};
aggregateLinks(graph, node);
}
function aggregateLinks(graph, node){
let definingProp;
let overridenProps = [];
graph.forEachLinkedNode(
node.id,
(linkedNode, link) => {
if (!linkedNode.data) linkedNode.data = {};
// Ignore inactive props
if (linkedNode.data.inactive) return;
// Apply all the aggregations
let arg = {node, linkedNode, link};
aggregate.definitions(arg);
aggregate.baseValue(arg);
aggregate.damageMultipliers(arg);
aggregate.effects(arg);
aggregate.proficiencies(arg);
aggregate.skills(arg);
aggregate.toggles(arg);
},
true // enumerate only outbound links
);
// store the defining and overriden props on the node
if (!node.data) node.data = {};
node.data.definingProp = definingProp;
node.data.overridenProps = overridenProps;
}

View File

@@ -0,0 +1,11 @@
import { CompilationContext } from '/imports/parser/parser.js';
export default function evaluateCalculation(calculation, scope){
const context = new CompilationContext();
const parseNode = calculation._parsedCalculation;
const fn = calculation._parseLevel || 'reduce';
const calculationScope = {...calculation._localScope, ...scope};
const result = parseNode[fn](calculationScope, context);
calculation.value = result;
calculation.errors = context.errors;
}