From 43f056ae95632689125df1d46ceace414b696949 Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Tue, 7 Sep 2021 15:48:51 +0200 Subject: [PATCH] more small progress on migration --- app/imports/api/properties/Actions.js | 4 ++ app/imports/api/properties/Attacks.js | 18 +++--- app/imports/api/properties/Attributes.js | 59 ++++++------------- .../server/2.0-beta.33-dbv1.test.js | 2 +- app/imports/ui/pages/Home.vue | 2 +- 5 files changed, 34 insertions(+), 51 deletions(-) diff --git a/app/imports/api/properties/Actions.js b/app/imports/api/properties/Actions.js index 9a23959f..897d2139 100644 --- a/app/imports/api/properties/Actions.js +++ b/app/imports/api/properties/Actions.js @@ -86,6 +86,10 @@ const ComputedOnlyActionSchema = createPropertySchema({ type: Boolean, optional: true, }, + uses: { + type: 'computedOnlyField', + optional: true, + }, }); const ComputedActionSchema = new SimpleSchema() diff --git a/app/imports/api/properties/Attacks.js b/app/imports/api/properties/Attacks.js index e10677b8..b500bb6c 100644 --- a/app/imports/api/properties/Attacks.js +++ b/app/imports/api/properties/Attacks.js @@ -1,18 +1,15 @@ import SimpleSchema from 'simpl-schema'; import { ActionSchema, ComputedOnlyActionSchema } from '/imports/api/properties/Actions.js'; -import { - fieldToCompute, - computedOnlyField, -} from '/imports/api/properties/subSchemas/ComputedFieldSchema.js'; +import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema.js'; import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS.js'; // Attacks are special instances of actions let AttackSchema = new SimpleSchema() .extend(ActionSchema) - .extend({ + .extend(createPropertySchema({ // What gets added to the d20 roll rollBonus: { - type: Object, + type: 'fieldToCompute', optional: true, }, 'rollBonus.calculation': { @@ -34,11 +31,16 @@ let AttackSchema = new SimpleSchema() type: String, max: STORAGE_LIMITS.tagLength, }, - }).extend(fieldToCompute('rollBonus')); + })); const ComputedOnlyAttackSchema = new SimpleSchema() .extend(ComputedOnlyActionSchema) - .extend(computedOnlyField('rollBonus')); + .extend(createPropertySchema({ + rollBonus: { + type: 'computedOnlyField', + optional: true, + }, + })); const ComputedAttackSchema = new SimpleSchema() .extend(AttackSchema) diff --git a/app/imports/api/properties/Attributes.js b/app/imports/api/properties/Attributes.js index b5c1c605..ddaa975e 100644 --- a/app/imports/api/properties/Attributes.js +++ b/app/imports/api/properties/Attributes.js @@ -1,13 +1,12 @@ import SimpleSchema from 'simpl-schema'; -import ErrorSchema from '/imports/api/properties/subSchemas/ErrorSchema.js'; import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX.js'; -import InlineComputationSchema from '/imports/api/properties/subSchemas/InlineComputationSchema.js'; import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS.js'; +import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema.js'; /* * Attributes are numbered stats of a character */ -let AttributeSchema = new SimpleSchema({ +let AttributeSchema = createPropertySchema({ name: { type: String, defaultValue: 'New Attribute', @@ -41,24 +40,22 @@ let AttributeSchema = new SimpleSchema({ // For type hitDice, the size needs to be stored separately hitDiceSize: { type: String, - allowedValues: ['d4', 'd6', 'd8', 'd10', 'd12', 'd20'], + allowedValues: ['d1', 'd2', 'd4', 'd6', 'd8', 'd10', 'd12', 'd20', 'd100'], optional: true, }, // For type spellSlot, the level needs to be stored separately - spellSlotLevelCalculation: { - type: String, + spellSlotLevel: { + type: 'fieldToCompute', optional: true, - max: STORAGE_LIMITS.calculation, }, // The starting value, before effects - baseValueCalculation: { - type: String, + baseValue: { + type: 'fieldToCompute', optional: true, - max: STORAGE_LIMITS.calculation, }, // Description of what the attribute is used for description: { - type: String, + type: 'inlineCalculationFieldToCompute', optional: true, max: STORAGE_LIMITS.description, }, @@ -81,47 +78,27 @@ let AttributeSchema = new SimpleSchema({ }, }); -let ComputedOnlyAttributeSchema = new SimpleSchema({ - descriptionCalculations: { - type: Array, - defaultValue: [], - maxCount: STORAGE_LIMITS.inlineCalculationCount, +let ComputedOnlyAttributeSchema = createPropertySchema({ + description: { + type: 'computedOnlyInlineCalculationField', + optional: true, }, - 'descriptionCalculations.$': InlineComputationSchema, - // The result of baseValueCalculation baseValue: { - type: SimpleSchema.oneOf(Number, String, Boolean), + type: 'computedOnlyField', optional: true, }, - baseValueErrors: { - type: Array, - optional: true, - }, - 'baseValueErrors.$': { - type: ErrorSchema, - maxCount: STORAGE_LIMITS.errorCount, - }, - // The result of spellSlotLevelCalculation - spellSlotLevelValue: { - type: SimpleSchema.oneOf(Number, String, Boolean), - optional: true, - }, - spellSlotLevelErrors: { - type: Array, - optional: true, - maxCount: STORAGE_LIMITS.errorCount, - }, - 'spellSlotLevelErrors.$': { - type: ErrorSchema, + spellSlotLevel: { + type: 'computedOnlyField', + optional: true, }, // The computed value of the attribute - value: { + total: { type: SimpleSchema.oneOf(Number, String, Boolean), defaultValue: 0, optional: true, }, // The computed value of the attribute minus the damage - currentValue: { + value: { type: SimpleSchema.oneOf(Number, String, Boolean), defaultValue: 0, optional: true, diff --git a/app/imports/migrations/server/2.0-beta.33-dbv1.test.js b/app/imports/migrations/server/2.0-beta.33-dbv1.test.js index fd79387c..d74c1896 100644 --- a/app/imports/migrations/server/2.0-beta.33-dbv1.test.js +++ b/app/imports/migrations/server/2.0-beta.33-dbv1.test.js @@ -11,7 +11,7 @@ const exampleAction = { 'itemsConsumed':[], 'attributesConsumed':[{ '_id':'FaK6jXEj3pSe7mNuu', - 'quantity':1, + 'quantity': '1', 'variableName':'HunterTech', 'statId':'qccf9j5tfNJjZ3GGn', 'statName':'Hunter\'s Technique', diff --git a/app/imports/ui/pages/Home.vue b/app/imports/ui/pages/Home.vue index 1b638bc8..171ade01 100644 --- a/app/imports/ui/pages/Home.vue +++ b/app/imports/ui/pages/Home.vue @@ -94,7 +94,7 @@ >