Migrating UI for new data structures

This commit is contained in:
Stefan Zermatten
2021-10-15 11:12:40 +02:00
parent f3c52999e8
commit ea68cdf86f
35 changed files with 511 additions and 271 deletions

View File

@@ -3,9 +3,9 @@ import walkDown from '/imports/api/engine/computation/utility/walkdown.js';
export default function computeInactiveStatus(node){
const prop = node.node;
if (isActive(prop)) return;
// Unequipped items disable their children, but are not disabled themselves
// All notes do the same
if (prop.type !== 'item' && prop.type !== 'note' ){
// Unequipped items, notes, and actions disable their children,
// but are not disabled themselves
if (prop.type !== 'item' && prop.type !== 'note' && prop.type !== 'action' ){
prop.inactive = true;
prop.deactivatedBySelf = true;
}
@@ -23,6 +23,7 @@ function isActive(prop){
case 'item': return !!prop.equipped;
case 'spell': return !!prop.prepared || !!prop.alwaysPrepared;
case 'note': return false;
case 'action': return false;
default: return true;
}
}

View File

@@ -1,7 +1,7 @@
import INLINE_CALCULATION_REGEX from '/imports/constants/INLINE_CALCULTION_REGEX.js';
import { prettifyParseError, parse } from '/imports/parser/parser.js';
import applyFnToKey from '/imports/api/engine/computation/utility/applyFnToKey.js';
import { get } from 'lodash';
import { get, unset } from 'lodash';
import errorNode from '/imports/parser/parseTree/error.js';
import cyrb53 from '/imports/api/engine/computation/utility/cyrb53.js';
@@ -53,6 +53,11 @@ function parseAllCalculationFields(prop, schemas){
applyFnToKey(prop, calcKey, (prop, key) => {
const calcObj = get(prop, key);
if (!calcObj) return;
// Delete the whole calculation object if the calculation string isn't set
if (!calcObj.calculation){
unset(prop, calcKey);
return;
}
// Store a reference to all the calculations
prop._computationDetails.calculations.push(calcObj);
// Store the level to compute down to later
@@ -64,12 +69,6 @@ function parseAllCalculationFields(prop, schemas){
}
function parseCalculation(calcObj){
// If there is no calculation clear the cached parse node and error
if (!calcObj.calculation){
delete calcObj.hash;
delete calcObj.parseError;
return;
}
const calcHash = cyrb53(calcObj.calculation);
// If the cached parse calculation is equal to the calculation, skip
if (calcHash === calcObj.hash){

View File

@@ -2,6 +2,9 @@ export default function computeAction(computation, node){
const prop = node.data;
if (prop.uses){
prop.usesLeft = prop.uses.value - (prop.usesUsed || 0);
if (!prop.usesLeft){
prop.insufficientResources = true;
}
}
computeResources(computation, node);
if (!prop.resources) return;

View File

@@ -14,7 +14,7 @@ export default function(){
assert.equal(prop.usesLeft, 2);
const rolled = computation.propsById['rolledDescriptionId'];
assert.equal(rolled.summary.value, 'test roll gets compiled 1d4 + 4 properly');
assert.equal(rolled.summary.value, 'test roll gets compiled d4 + 4 properly');
const itemConsumed = prop.resources.itemsConsumed[0];
assert.equal(itemConsumed.quantity.value, 3);
@@ -26,7 +26,6 @@ export default function(){
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');
}