Lots of progress testing and fixing computation engine
This commit is contained in:
@@ -6,6 +6,7 @@ export default function computeAction(graph, node, scope){
|
||||
prop.usesLeft = prop.uses.value - (prop.usesUsed || 0);
|
||||
}
|
||||
computeResources(graph, node, scope);
|
||||
if (!prop.resources) return;
|
||||
prop.resources.itemsConsumed.forEach(itemConsumed => {
|
||||
if (!itemConsumed.itemId) return;
|
||||
if (itemConsumed.available < itemConsumed.quantity.value){
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
export default function computeResources(graph, node, scope){
|
||||
const prop = node.data;
|
||||
prop.resources.attributesConsumed.forEach(attConsumed => {
|
||||
const resources = node.data?.resources;
|
||||
if (!resources) return;
|
||||
resources.attributesConsumed.forEach(attConsumed => {
|
||||
if (!attConsumed.variableName) return;
|
||||
const att = scope[attConsumed.variableName];
|
||||
attConsumed.available = att.value;
|
||||
|
||||
@@ -9,14 +9,13 @@ export default function computeVariable(graph, node, scope){
|
||||
if (!node.data) node.data = {};
|
||||
aggregateLinks(graph, node);
|
||||
combineAggregations(node, scope);
|
||||
if (node.definingProp){
|
||||
if (node.data.definingProp){
|
||||
// Add the defining variable to the scope
|
||||
scope[node.id] = node.definingProp
|
||||
scope[node.id] = node.data.definingProp
|
||||
} else {
|
||||
// Otherwise add an implicit variable to the scope
|
||||
scope[node.id] = computeImplicitVariable(node, scope);
|
||||
}
|
||||
console.log('computed variable ', node);
|
||||
}
|
||||
|
||||
function aggregateLinks(graph, node){
|
||||
|
||||
@@ -2,7 +2,6 @@ import getAggregatorResult from './getAggregatorResult.js';
|
||||
|
||||
export default function computeVariableAsAttribute(node, prop, scope){
|
||||
let result = getAggregatorResult(node);
|
||||
console.log('computing variable as attribure ', node);
|
||||
prop.total = result;
|
||||
prop.value = prop.total - (prop.damage || 0);
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { CompilationContext } from '/imports/parser/parser.js';
|
||||
import INLINE_CALCULATION_REGEX from '/imports/constants/INLINE_CALCULTION_REGEX.js';
|
||||
import ConstantNode from '/imports/parser/parseTree/ConstantNode.js';
|
||||
|
||||
export default function computeCalculations(node, scope){
|
||||
if (!node.data) return;
|
||||
@@ -17,7 +18,12 @@ function evaluateCalculation(calculation, scope){
|
||||
const parseNode = calculation._parsedCalculation;
|
||||
const fn = calculation._parseLevel;
|
||||
const calculationScope = {...calculation._localScope, ...scope};
|
||||
calculation.value = parseNode[fn](calculationScope, context);
|
||||
const resultNode = parseNode[fn](calculationScope, context);
|
||||
if (resultNode instanceof ConstantNode){
|
||||
calculation.value = resultNode.value;
|
||||
} else {
|
||||
calculation.value = NaN;
|
||||
}
|
||||
calculation.errors = context.errors;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
import { buildComputationFromProps } from '/imports/api/creature/computation/newEngine/buildCreatureComputation.js';
|
||||
import { assert } from 'chai';
|
||||
import computeCreatureComputation from '../../computeCreatureComputation.js';
|
||||
import clean from '../../utility/cleanProp.testFn.js';
|
||||
|
||||
export default function(){
|
||||
const computation = buildComputationFromProps(testProperties);
|
||||
computeCreatureComputation(computation);
|
||||
|
||||
const prop = computation.propsById['actionId'];
|
||||
assert.equal(prop.summary.value, 'test summary 3 without referencing anything 7');
|
||||
assert.equal(prop.description.value, 'test description 12 with reference 0.25 prop');
|
||||
assert.equal(prop.uses.value, 7);
|
||||
assert.equal(prop.usesLeft, 2);
|
||||
|
||||
const itemConsumed = prop.resources.itemsConsumed[0];
|
||||
assert.equal(itemConsumed.quantity.value, 3);
|
||||
assert.equal(itemConsumed.available, 27);
|
||||
assert.equal(itemConsumed.itemName, 'Arrow');
|
||||
assert.equal(itemConsumed.itemIcon, 'itemIcon');
|
||||
assert.equal(itemConsumed.itemColor, 'itemColor');
|
||||
|
||||
const attConsumed = prop.resources.attributesConsumed[0];
|
||||
assert.equal(attConsumed.quantity.value, 4);
|
||||
assert.equal(attConsumed.available, 9);
|
||||
assert.equal(attConsumed.statId, 'resourceVarId');
|
||||
assert.equal(attConsumed.statName, 'Resource Var');
|
||||
}
|
||||
|
||||
var testProperties = [
|
||||
clean({
|
||||
_id: 'actionId',
|
||||
type: 'action',
|
||||
ancestors: [{id: 'charId'}],
|
||||
summary: {
|
||||
text: 'test summary {1 + 2} without referencing anything {3 + 4}',
|
||||
},
|
||||
description: {
|
||||
text: 'test description {inlineRef * 2} with reference {1/4} prop',
|
||||
},
|
||||
resources: {
|
||||
itemsConsumed: [{
|
||||
_id: 'itemConsumedId',
|
||||
itemId: 'arrowId',
|
||||
tag: 'arrow',
|
||||
quantity: {
|
||||
calculation: 'itemConsumedQuantity',
|
||||
},
|
||||
}],
|
||||
attributesConsumed: [{
|
||||
_id: 'attConsumedId',
|
||||
variableName: 'resourceVar',
|
||||
quantity: {
|
||||
calculation: 'resourceConsumedQuantity'
|
||||
}
|
||||
}],
|
||||
},
|
||||
uses: {
|
||||
calculation: 'nonExistantProperty + 7',
|
||||
},
|
||||
usesUsed: 5,
|
||||
}),
|
||||
clean({
|
||||
_id: 'numItemsConumedId',
|
||||
type: 'attribute',
|
||||
variableName: 'itemConsumedQuantity',
|
||||
baseValue: {
|
||||
calculation: '3',
|
||||
},
|
||||
}),
|
||||
clean({
|
||||
_id: 'numResourceConumedId',
|
||||
type: 'attribute',
|
||||
variableName: 'resourceConsumedQuantity',
|
||||
baseValue: {
|
||||
calculation: '4',
|
||||
},
|
||||
}),
|
||||
clean({
|
||||
_id: 'resourceVarId',
|
||||
name: 'Resource Var',
|
||||
type: 'attribute',
|
||||
variableName: 'resourceVar',
|
||||
baseValue: {
|
||||
calculation: '9',
|
||||
},
|
||||
}),
|
||||
clean({
|
||||
_id: 'inlineRefResourceId',
|
||||
type: 'attribute',
|
||||
variableName: 'inlineRef',
|
||||
baseValue: {
|
||||
calculation: '1 + 5',
|
||||
},
|
||||
}),
|
||||
clean({
|
||||
_id: 'arrowId',
|
||||
type: 'item',
|
||||
name: 'Arrow',
|
||||
quantity: 27,
|
||||
icon: 'itemIcon',
|
||||
color: 'itemColor',
|
||||
}),
|
||||
];
|
||||
Reference in New Issue
Block a user