Start of action system re-write
This commit is contained in:
@@ -27,7 +27,6 @@ function computeResources(computation, node){
|
||||
const att = computation.scope[attConsumed.variableName];
|
||||
if (!att._id) return;
|
||||
attConsumed.available = att.value;
|
||||
attConsumed.statId = att._id;
|
||||
attConsumed.statName = att.name;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import resolve, { toString } from '/imports/parser/resolve.js';
|
||||
import INLINE_CALCULATION_REGEX from '/imports/constants/INLINE_CALCULTION_REGEX.js';
|
||||
import embedInlineCalculations from '../utility/embedInlineCalculations.js';
|
||||
import evaluateCalculation from '../utility/evaluateCalculation.js';
|
||||
|
||||
export default function computeCalculations(computation, node){
|
||||
if (!node.data) return;
|
||||
@@ -11,32 +11,3 @@ export default function computeCalculations(computation, node){
|
||||
embedInlineCalculations(inlineCalcObj);
|
||||
});
|
||||
}
|
||||
|
||||
function evaluateCalculation(calculation, scope){
|
||||
const parseNode = calculation.parseNode;
|
||||
const fn = calculation._parseLevel;
|
||||
const calculationScope = {...calculation._localScope, ...scope};
|
||||
const {result: resultNode, context} = resolve(fn, parseNode, calculationScope);
|
||||
calculation.errors = context.errors;
|
||||
if (resultNode?.parseType === 'constant'){
|
||||
calculation.value = resultNode.value;
|
||||
} else if (resultNode?.parseType === 'error'){
|
||||
calculation.value = null;
|
||||
} else {
|
||||
calculation.value = toString(resultNode);
|
||||
}
|
||||
// remove the working fields
|
||||
delete calculation._parseLevel;
|
||||
delete calculation._localScope;
|
||||
}
|
||||
|
||||
function embedInlineCalculations(inlineCalcObj){
|
||||
const string = inlineCalcObj.text;
|
||||
const calculations = inlineCalcObj.inlineCalculations;
|
||||
if (!string || !calculations) return;
|
||||
let index = 0;
|
||||
inlineCalcObj.value = string.replace(INLINE_CALCULATION_REGEX, substring => {
|
||||
let calc = calculations[index++];
|
||||
return (calc && 'value' in calc) ? calc.value : substring;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import INLINE_CALCULATION_REGEX from '/imports/constants/INLINE_CALCULTION_REGEX.js';
|
||||
|
||||
export default function embedInlineCalculations(inlineCalcObj){
|
||||
const string = inlineCalcObj.text;
|
||||
const calculations = inlineCalcObj.inlineCalculations;
|
||||
if (!string || !calculations) return;
|
||||
let index = 0;
|
||||
inlineCalcObj.value = string.replace(INLINE_CALCULATION_REGEX, substring => {
|
||||
let calc = calculations[index++];
|
||||
return (calc && 'value' in calc) ? calc.value : substring;
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import resolve, { toString } from '/imports/parser/resolve.js';
|
||||
|
||||
export default function evaluateCalculation(calculation, scope){
|
||||
const parseNode = calculation.parseNode;
|
||||
const fn = calculation._parseLevel;
|
||||
const calculationScope = {...calculation._localScope, ...scope};
|
||||
const {result: resultNode, context} = resolve(fn, parseNode, calculationScope);
|
||||
calculation.errors = context.errors;
|
||||
if (resultNode?.parseType === 'constant'){
|
||||
calculation.value = resultNode.value;
|
||||
} else if (resultNode?.parseType === 'error'){
|
||||
calculation.value = null;
|
||||
} else {
|
||||
calculation.value = toString(resultNode);
|
||||
}
|
||||
// remove the working fields
|
||||
delete calculation._parseLevel;
|
||||
delete calculation._localScope;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import Creatures from '/imports/api/creature/creatures/Creatures.js';
|
||||
|
||||
export default function writeScope(creatureId, scope){
|
||||
Creatures.update(creatureId, {$set: {variables: scope}});
|
||||
}
|
||||
Reference in New Issue
Block a user