Class levels can now have conditions

This commit is contained in:
Stefan Zermatten
2020-10-15 15:57:19 +02:00
parent 839f91c3b2
commit 1ba4f76763
3 changed files with 25 additions and 11 deletions

View File

@@ -23,6 +23,11 @@ let ClassLevelSchema = new SimpleSchema({
'nextLevelTags.$': {
type: String,
},
// Same as in SlotFillers.js
slotFillerCondition: {
type: String,
optional: true,
},
});
export { ClassLevelSchema };

View File

@@ -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;
});

View File

@@ -27,6 +27,14 @@
@change="change('variableName', ...arguments)"
/>
</div>
<text-field
label="Condition"
hint="A caclulation to determine if this can be added to the character"
placeholder="Always active"
:value="model.slotFillerCondition"
:error-messages="errors.slotFillerCondition"
@change="change('slotFillerCondition', ...arguments)"
/>
</div>
</template>