From ff6edd398b8248776d681561a9d749ff6b3c8ecc Mon Sep 17 00:00:00 2001 From: Thaum Rystra <9525416+ThaumRystra@users.noreply.github.com> Date: Sat, 21 Oct 2023 11:49:50 +0200 Subject: [PATCH] Added denormalized computation fields --- .../properties/subSchemas/computedField.js | 60 ++++++++++++++----- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/app/imports/api/properties/subSchemas/computedField.js b/app/imports/api/properties/subSchemas/computedField.js index 0d7ad114..6ff3d20b 100644 --- a/app/imports/api/properties/subSchemas/computedField.js +++ b/app/imports/api/properties/subSchemas/computedField.js @@ -4,7 +4,7 @@ import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS.js'; // Get schemas that apply fields directly so they can be gracefully extended // because {type: Schema} fields can't be extended -function fieldToCompute(field){ +function fieldToCompute(field) { const schemaObj = { [`${field}.calculation`]: { type: String, @@ -17,22 +17,52 @@ function fieldToCompute(field){ return new SimpleSchema(schemaObj); } -function computedOnlyField(field){ +function computedOnlyField(field) { const schemaObj = { - [`${field}.value`]: { + // The parseNode of the compiled value before any effects are applied or rolls made + [`${field}.unaffected`]: { + type: Object, + optional: true, + blackbox: true, + }, + /* + // toString(.baseValue) + [`${field}.baseValueString`]: { type: SimpleSchema.oneOf(String, Number), optional: true, removeBeforeCompute: true, }, - // A list of effects targeting this calculation - [`${field}.effects`]: { + */ + // The compiled parseNode after applying all effects + [`${field}.value`]: { + type: Object, + optional: true, + blackbox: true, + }, + /* + // toString(.value) + [`${field}.valueString`]: { + type: SimpleSchema.oneOf(String, Number), + optional: true, + removeBeforeCompute: true, + }, + */ + // A list of effect Ids targeting this calculation + [`${field}.effectIds`]: { type: Array, optional: true, removeBeforeCompute: true, }, - [`${field}.effects.$`]: { - type: Object, - blackbox: true, + [`${field}.effectIds.$`]: { + type: String, + }, + [`${field}.proficiencyIds`]: { + type: Array, + optional: true, + removeBeforeCompute: true, + }, + [`${field}.proficiencyIds.$`]: { + type: String, }, // A cache of the parse result of the calculation [`${field}.parseNode`]: { @@ -56,7 +86,7 @@ function computedOnlyField(field){ maxCount: STORAGE_LIMITS.errorCount, removeBeforeCompute: true, }, - [`${field}.errors.$`]:{ + [`${field}.errors.$`]: { type: ErrorSchema, }, } @@ -65,9 +95,9 @@ function computedOnlyField(field){ } // We must include parent array and object fields for the schema to be valid -function includeParentFields(field, schemaObj){ +function includeParentFields(field, schemaObj) { const splitField = field.split('.'); - if (splitField.length === 1){ + if (splitField.length === 1) { schemaObj[field] = { type: Object, optional: true, @@ -78,8 +108,8 @@ function includeParentFields(field, schemaObj){ let key = ''; splitField.push(''); splitField.forEach((value, index) => { - if (key){ - if (value === '$'){ + if (key) { + if (value === '$') { schemaObj[key] = { type: Array, optional: true @@ -90,7 +120,7 @@ function includeParentFields(field, schemaObj){ optional: true, }; // the last object is the computed field - if (index === splitField.length - 1){ + if (index === splitField.length - 1) { schemaObj[key].computedField = true; } } @@ -102,7 +132,7 @@ function includeParentFields(field, schemaObj){ // This should rarely be used, since the other two will merge correctly when // uncomputed and computedOnly schemas are merged -function computedField(field){ +function computedField(field) { return computedField(field).extend(computedOnlyField(field)); }