Computations now occupy their own nodes on the dependency graph
This mitigates most issues with properties having self-loops, particularly in cases like Strength where the value `strength` is used in the description of Strength
This commit is contained in:
@@ -4,9 +4,11 @@ import attribute from './computeByType/computeAttribute.js';
|
||||
import skill from './computeByType/computeSkill.js';
|
||||
import slot from './computeByType/computeSlot.js';
|
||||
import container from './computeByType/computeContainer.js';
|
||||
import _calculation from './computeByType/computeCalculation.js';
|
||||
|
||||
export default Object.freeze({
|
||||
_variable,
|
||||
_calculation,
|
||||
action,
|
||||
attribute,
|
||||
container,
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
import evaluateCalculation from '../../utility/evaluateCalculation.js';
|
||||
|
||||
export default function computeCalculation(computation, node){
|
||||
const calcObj = node.data;
|
||||
evaluateCalculation(calcObj, computation.scope);
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import embedInlineCalculations from '../utility/embedInlineCalculations.js';
|
||||
import evaluateCalculation from '../utility/evaluateCalculation.js';
|
||||
|
||||
export default function computeCalculations(computation, node){
|
||||
if (!node.data) return;
|
||||
// evaluate all the calculations
|
||||
node.data._computationDetails?.calculations?.forEach(calcObj => {
|
||||
evaluateCalculation(calcObj, computation.scope)
|
||||
});
|
||||
node.data._computationDetails?.inlineCalculations?.forEach(inlineCalcObj => {
|
||||
embedInlineCalculations(inlineCalcObj);
|
||||
});
|
||||
}
|
||||
@@ -8,13 +8,13 @@ export default function(){
|
||||
computeCreatureComputation(computation);
|
||||
const prop = id => computation.propsById[id];
|
||||
const scope = variableName => computation.scope[variableName];
|
||||
assert.equal(prop('emptyId').value, 0);
|
||||
assert.equal(prop('noVariableNameId').value, 8);
|
||||
assert.equal(prop('strengthId').value, 12);
|
||||
assert.equal(prop('strengthId').modifier, 1);
|
||||
assert.equal(scope('strength').modifier, 1);
|
||||
assert.equal(prop('referencesDexId').value, 4);
|
||||
assert.equal(prop('hitDiceId').constitutionMod, 5);
|
||||
assert.equal(prop('emptyId').value, 0, 'calculates empty props to zero');
|
||||
assert.equal(prop('noVariableNameId').value, 8, 'Calculates props without a variable name');
|
||||
assert.equal(prop('strengthId').value, 12, 'applies base values');
|
||||
assert.equal(prop('strengthId').modifier, 1, 'calculates modifiers for basic properties');
|
||||
assert.equal(scope('strength').modifier, 1, 'Access properties via variables');
|
||||
assert.equal(prop('referencesDexId').value, 4, 'Access variable properties in calculations');
|
||||
assert.equal(prop('hitDiceId').constitutionMod, 5, 'Hit dice get constitution modifier');
|
||||
assert.equal(prop('overriddenDexId').overridden, true, 'override properties with the same variable name');
|
||||
assert.equal(
|
||||
prop('parseErrorId').baseValue.value, null,
|
||||
|
||||
Reference in New Issue
Block a user