Fixed slots and slot fillers not calculating their conditions correctly

Also fixes slot fullness calculation
This commit is contained in:
Stefan Zermatten
2022-02-22 17:59:12 +02:00
parent 4c6d70b084
commit 8f30c1419c
6 changed files with 35 additions and 22 deletions

View File

@@ -14,7 +14,7 @@ const linkDependenciesByType = {
effect: linkEffects,
proficiency: linkProficiencies,
roll: linkRoll,
slot: linkSlot,
propertySlot: linkSlot,
skill: linkSkill,
spell: linkAction,
spellList: linkSpellList,

View File

@@ -2,7 +2,7 @@ import _variable from './computeByType/computeVariable.js';
import action from './computeByType/computeAction.js';
import attribute from './computeByType/computeAttribute.js';
import skill from './computeByType/computeSkill.js';
import slot from './computeByType/computeSlot.js';
import propertySlot from './computeByType/computeSlot.js';
import container from './computeByType/computeContainer.js';
import _calculation from './computeByType/computeCalculation.js';
@@ -13,6 +13,6 @@ export default Object.freeze({
attribute,
container,
skill,
slot,
propertySlot,
spell: action,
});

View File

@@ -1,6 +1,6 @@
export default function computSlot(computation, node){
const prop = node.data;
if (prop.quantityExpected){
prop.spaceLeft = prop.quantityExpected - prop.totalFilled;
if (prop.quantityExpected && prop.quantityExpected.value){
prop.spaceLeft = prop.quantityExpected.value - prop.totalFilled;
}
}

View File

@@ -188,6 +188,8 @@ import LibraryNodes from '/imports/api/library/LibraryNodes.js';
import DialogBase from '/imports/ui/dialogStack/DialogBase.vue';
import TreeNodeView from '/imports/ui/properties/treeNodeViews/TreeNodeView.vue';
import PropertyDescription from '/imports/ui/properties/viewers/shared/PropertyDescription.vue'
import resolve, { toString } from '/imports/parser/resolve.js';
import { prettifyParseError, parse } from '/imports/parser/parser.js';
// import evaluateString from '/imports/api/creature/computation/afterComputation/evaluateString.js';
import getSlotFillFilter from '/imports/api/creature/creatureProperties/methods/getSlotFillFilter.js'
import Libraries from '/imports/api/library/Libraries.js';
@@ -291,8 +293,9 @@ export default {
return CreatureProperties.findOne(this.slotId);
} else if (this.dummySlot) {
let model = clone(this.dummySlot)
model.quantityExpectedResult = +model.quantityExpected;
model.spaceLeft = model.quantityExpectedResult;
if (!model.quantityExpected) model.quantityExpected = {};
model.quantityExpected.value = +model.quantityExpected.calculation;
model.spaceLeft = model.quantityExpected.value;
return model;
}
},
@@ -342,7 +345,7 @@ export default {
return quantitySelected;
},
spaceLeft(){
if (this.model.quantityExpectedResult === 0) return undefined;
if (!this.model.quantityExpected || this.model.quantityExpected.value === 0) return undefined;
return this.model.spaceLeft - this.totalQuantitySelected;
},
libraryNames(){
@@ -360,13 +363,23 @@ export default {
// the quantity to fill
nodes.forEach(node => {
if (node.slotFillerCondition){
let {result} = evaluateString({
string: node.slotFillerCondition,
scope: this.creature.variables,
fn: 'reduce',
});
if (!result.value){
try {
let parseNode = parse(node.slotFillerCondition);
const {result: resultNode} = resolve('reduce', parseNode, this.creature.variables);
if (resultNode?.parseType === 'constant'){
if (!resultNode.value){
node._disabledBySlotFillerCondition = true;
disabledNodeCount += 1;
}
} else {
node._disabledBySlotFillerCondition = true;
node._conditionError = toString(resultNode);
disabledNodeCount += 1;
}
} catch (e){
let error = prettifyParseError(e);
node._disabledBySlotFillerCondition = true;
node._conditionError = error;
disabledNodeCount += 1;
}
}

View File

@@ -8,8 +8,8 @@
<h3 class="layout align-center">
{{ slot.name }}
<v-spacer />
<span v-if="slot.quantityExpectedResult > 1">
{{ slot.totalFilled }} / {{ slot.quantityExpectedResult }}
<span v-if="slot.quantityExpected && slot.quantityExpected.value > 1">
{{ slot.totalFilled }} / {{ slot.quantityExpected.value }}
</span>
</h3>
<v-list v-if="slot.children.length">
@@ -37,7 +37,7 @@
</v-list-item>
</v-list>
<v-btn
v-if="!slot.quantityExpectedResult || slot.spaceLeft"
v-if="!slot.quantityExpected || !slot.quantityExpected.value || slot.spaceLeft"
icon
:data-id="`slot-add-button-${slot._id}`"
class="slot-add-button"
@@ -120,8 +120,8 @@ export default {
'ancestors.id': this.creatureId,
type: 'propertySlot',
$or: [
{slotConditionResult: {$nin: [false, 0, '']}},
{slotConditionResult: {$exists: false}},
{'slotCondition.value': {$nin: [false, 0, '']}},
{'slotCondition.value': {$exists: false}},
],
removed: {$ne: true},
inactive: {$ne: true},
@@ -130,7 +130,7 @@ export default {
}).map(slot => {
if (
!this.showHiddenSlots &&
slot.quantityExpectedResult === 0 &&
(slot.quantityExpected && slot.quantityExpected.value) === 0 &&
slot.hideWhenFull
){
slot.children = []
@@ -146,7 +146,7 @@ export default {
}).filter(slot => !( // Hide full and ignored slots
!this.showHiddenSlots && (
slot.hideWhenFull &&
slot.quantityExpectedResult > 0 &&
(slot.quantityExpected && slot.quantityExpected.value) > 0 &&
slot.spaceLeft <= 0 ||
slot.ignored
)

View File

@@ -1,6 +1,6 @@
<template lang="html">
<markdown-text
v-if="text"
v-if="text && model"
:markdown="model.value || model.text"
/>
<property-field