From 1ba4f76763bcf085704436f0fcf57d5c39d25e66 Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Thu, 15 Oct 2020 15:57:19 +0200 Subject: [PATCH] Class levels can now have conditions --- app/imports/api/properties/ClassLevels.js | 5 ++++ .../ui/creature/slots/SlotFillDialog.vue | 23 ++++++++++--------- .../ui/properties/forms/ClassLevelForm.vue | 8 +++++++ 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/app/imports/api/properties/ClassLevels.js b/app/imports/api/properties/ClassLevels.js index 97295080..ed1c41e7 100644 --- a/app/imports/api/properties/ClassLevels.js +++ b/app/imports/api/properties/ClassLevels.js @@ -23,6 +23,11 @@ let ClassLevelSchema = new SimpleSchema({ 'nextLevelTags.$': { type: String, }, + // Same as in SlotFillers.js + slotFillerCondition: { + type: String, + optional: true, + }, }); export { ClassLevelSchema }; diff --git a/app/imports/ui/creature/slots/SlotFillDialog.vue b/app/imports/ui/creature/slots/SlotFillDialog.vue index 1276774d..57cc3c1d 100644 --- a/app/imports/ui/creature/slots/SlotFillDialog.vue +++ b/app/imports/ui/creature/slots/SlotFillDialog.vue @@ -179,17 +179,18 @@ export default { // Filter out slotFillers whose condition isn't met or are too big to fit // the quantity to fill nodes = nodes.filter(node => { - if (node.type === 'slotFiller'){ - if (node.slotFillerCondition){ - let context = new CompilationContext(); - let conditionResult = parse(node.slotFillerCondition) - .reduce(this.creature.variables, context); - if (conditionResult && !conditionResult.value) return false; - } - console.log({numToFill: this.numToFill, node}); - if (this.numToFill > 0 && node.slotQuantityFilled > this.numToFill){ - return false; - } + if (node.slotFillerCondition){ + let context = new CompilationContext(); + let conditionResult = parse(node.slotFillerCondition) + .reduce(this.creature.variables, context); + if (conditionResult && !conditionResult.value) return false; + } + if ( + node.type === 'slotFiller' && + this.numToFill > 0 && + node.slotQuantityFilled > this.numToFill + ){ + return false; } return true; }); diff --git a/app/imports/ui/properties/forms/ClassLevelForm.vue b/app/imports/ui/properties/forms/ClassLevelForm.vue index 160bb5ea..9b48318a 100644 --- a/app/imports/ui/properties/forms/ClassLevelForm.vue +++ b/app/imports/ui/properties/forms/ClassLevelForm.vue @@ -27,6 +27,14 @@ @change="change('variableName', ...arguments)" /> +