From d69ada0db4d58ea2a9fbab0efd1eef5ae970846e Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Tue, 23 Feb 2021 14:53:47 +0200 Subject: [PATCH] Slot quantity is now a computed value, added property viewer for slots --- .../engine/computeEndStepProperty.js | 1 + .../computation/engine/evaluateCalculation.js | 3 ++ .../denormalise/recomputeSlotFullness.js | 8 +++-- app/imports/api/properties/Slots.js | 6 ++-- app/imports/ui/creature/slots/Slots.vue | 6 ++-- app/imports/ui/properties/forms/SlotForm.vue | 2 -- .../ui/properties/viewers/SlotViewer.vue | 36 +++++++++++++++++++ .../viewers/shared/PropertyField.vue | 10 +++--- .../viewers/shared/propertyViewerIndex.js | 2 ++ 9 files changed, 59 insertions(+), 15 deletions(-) create mode 100644 app/imports/ui/properties/viewers/SlotViewer.vue diff --git a/app/imports/api/creature/computation/engine/computeEndStepProperty.js b/app/imports/api/creature/computation/engine/computeEndStepProperty.js index 931b3d16..e6f1a705 100644 --- a/app/imports/api/creature/computation/engine/computeEndStepProperty.js +++ b/app/imports/api/creature/computation/engine/computeEndStepProperty.js @@ -23,6 +23,7 @@ export default function computeEndStepProperty(prop, memo){ computePropertyField(prop, memo, 'maxPrepared'); break; case 'propertySlot': + computePropertyField(prop, memo, 'quantityExpected'); computePropertyField(prop, memo, 'slotCondition'); break; case 'roll': diff --git a/app/imports/api/creature/computation/engine/evaluateCalculation.js b/app/imports/api/creature/computation/engine/evaluateCalculation.js index bf071622..02028063 100644 --- a/app/imports/api/creature/computation/engine/evaluateCalculation.js +++ b/app/imports/api/creature/computation/engine/evaluateCalculation.js @@ -21,6 +21,9 @@ export default function evaluateCalculation({ context, dependencies, }; + if (typeof string !== 'string'){ + string = string.toString(); + } // Parse the string let calc; try { diff --git a/app/imports/api/creature/denormalise/recomputeSlotFullness.js b/app/imports/api/creature/denormalise/recomputeSlotFullness.js index 2b4e60ba..a99731c7 100644 --- a/app/imports/api/creature/denormalise/recomputeSlotFullness.js +++ b/app/imports/api/creature/denormalise/recomputeSlotFullness.js @@ -23,10 +23,14 @@ export default function recomputeSlotFullness(ancestorId){ } }); let spaceLeft; - if (slot.quantityExpected === 0){ + let expected = slot.quantityExpectedResult; + if (typeof expected !== 'number'){ + expected = 1; + } + if (expected === 0){ spaceLeft = null; } else { - spaceLeft = slot.quantityExpected - totalFilled; + spaceLeft = expected - totalFilled; } if (slot.totalFilled !== totalFilled || slot.spaceLeft !== spaceLeft){ CreatureProperties.update(slot._id, { diff --git a/app/imports/api/properties/Slots.js b/app/imports/api/properties/Slots.js index b07db858..872d6171 100644 --- a/app/imports/api/properties/Slots.js +++ b/app/imports/api/properties/Slots.js @@ -22,9 +22,9 @@ let SlotSchema = new SimpleSchema({ type: String, }, quantityExpected: { - type: SimpleSchema.Integer, - defaultValue: 1, - min: 0, + type: String, + optional: true, + defaultValue: '1', }, ignored: { type: Boolean, diff --git a/app/imports/ui/creature/slots/Slots.vue b/app/imports/ui/creature/slots/Slots.vue index 569888cd..834c6261 100644 --- a/app/imports/ui/creature/slots/Slots.vue +++ b/app/imports/ui/creature/slots/Slots.vue @@ -8,8 +8,8 @@

{{ slot.name }} - - {{ slot.totalFilled }} / {{ slot.quantityExpected }} + + {{ slot.totalFilled }} / {{ slot.quantityExpectedResult }}

@@ -38,7 +38,7 @@ +
+ + + + + + +
+ + + diff --git a/app/imports/ui/properties/viewers/shared/PropertyField.vue b/app/imports/ui/properties/viewers/shared/PropertyField.vue index fa7b6dd9..ab21be4c 100644 --- a/app/imports/ui/properties/viewers/shared/PropertyField.vue +++ b/app/imports/ui/properties/viewers/shared/PropertyField.vue @@ -1,11 +1,11 @@