Continued iterating on calculations, added failing test for bugs found

This commit is contained in:
Stefan Zermatten
2021-09-27 17:26:52 +02:00
parent 85e8756d1d
commit b0ee5cd304
9 changed files with 67 additions and 16 deletions

View File

@@ -4,10 +4,13 @@ import { unset } from 'lodash';
export default function removeSchemaFields(schemas, prop){
schemas.forEach(schema => {
schema._schemaKeys.forEach(key => {
// Skip object and array keys
// Skip object and array keys, except the errors array
if (
schema.getQuickTypeForKey(key) === 'object' ||
schema.getQuickTypeForKey(key) === 'objectArray'
(
schema.getQuickTypeForKey(key) === 'objectArray' &&
key.slice(-6)!== 'errors'
)
) return;
// Unset other computed only keys
applyFnToKey(prop, key, unset)

View File

@@ -29,6 +29,9 @@ function evaluateCalculation(calculation, scope){
} else {
calculation.errors = context.errors
}
// remove the working fields
delete calculation._parseLevel;
delete calculation._parsedCalculation;
}
function embedInlineCalculations(inlineCalcObj){

View File

@@ -6,13 +6,16 @@ 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 rolled = computation.propsById['rolledDescriptionId'];
assert.equal(rolled.summary.value, 'test roll gets compiled {1d4 + 4} properly');
const itemConsumed = prop.resources.itemsConsumed[0];
assert.equal(itemConsumed.quantity.value, 3);
assert.equal(itemConsumed.available, 27);
@@ -60,6 +63,14 @@ var testProperties = [
},
usesUsed: 5,
}),
clean({
_id: 'rolledDescriptionId',
type: 'action',
ancestors: [{id: 'charId'}],
summary: {
text: 'test roll gets compiled {1d4 + (2 + 2)} properly',
},
}),
clean({
_id: 'numItemsConumedId',
type: 'attribute',

View File

@@ -1,12 +1,12 @@
import { Meteor } from 'meteor/meteor'
import { isEqual, forOwn } from 'lodash';
import { isEqual } from 'lodash';
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
import propertySchemasIndex from '/imports/api/properties/computedOnlyPropertySchemasIndex.js';
export default function writeAlteredProperties(computation){
let bulkWriteOperations = [];
// Loop through all properties on the memo
forOwn(computation.propsById, changed => {
computation.props.forEach(changed => {
let schema = propertySchemasIndex[changed.type];
if (!schema){
console.warn('No schema for ' + changed.type);
@@ -36,6 +36,9 @@ function addChangedKeysToOp(op, keys, original, changed) {
// and compile an operation that sets all those keys
for (let key of keys){
if (!isEqual(original[key], changed[key])){
console.log('not equal: ', key);
console.log(original[key])
console.log(changed[key])
if (!op) op = newOperation(original._id, changed.type);
let value = changed[key];
if (value === undefined){
@@ -83,6 +86,7 @@ function addUnsetOp(op, key){
// compensation without needing to roll back changes, which causes multiple
// expensive redraws of the character sheet
function writePropertiesSequentially(bulkWriteOps){
console.log({opsLength: bulkWriteOps.length});
bulkWriteOps.forEach(op => {
let updateOneOrMany = op.updateOne || op.updateMany;
CreatureProperties.update(updateOneOrMany.filter, updateOneOrMany.update, {
@@ -91,6 +95,7 @@ function writePropertiesSequentially(bulkWriteOps){
bypassCollection2: true,
});
});
console.log('finished writing ops');
}
// This is more efficient on the database, but significantly less efficient