Added the ability to hide slots when full

This commit is contained in:
Stefan Zermatten
2020-11-05 14:05:17 +02:00
parent 749799d869
commit 7cb65954b5
5 changed files with 48 additions and 22 deletions

View File

@@ -8,6 +8,8 @@ export default function recomputeSlotFullness(ancestorId){
let children = CreatureProperties.find({ let children = CreatureProperties.find({
'parent.id': slot._id, 'parent.id': slot._id,
removed: {$ne: true}, removed: {$ne: true},
}, {
fields: {slotQuantityFilled: 1}
}).fetch(); }).fetch();
let totalFilled = 0; let totalFilled = 0;
children.forEach(child => { children.forEach(child => {
@@ -17,9 +19,15 @@ export default function recomputeSlotFullness(ancestorId){
totalFilled++; totalFilled++;
} }
}); });
if (slot.totalFilled !== totalFilled){ let spaceLeft;
if (slot.quantityExpected === 0){
spaceLeft = null;
} else {
spaceLeft = slot.quantityExpected - totalFilled;
}
if (slot.totalFilled !== totalFilled || slot.spaceLeft !== spaceLeft){
CreatureProperties.update(slot._id, { CreatureProperties.update(slot._id, {
$set: {totalFilled}, $set: {totalFilled, spaceLeft},
}, { }, {
selector: {type: 'propertySlot'} selector: {type: 'propertySlot'}
}); });

View File

@@ -34,6 +34,10 @@ let SlotSchema = new SimpleSchema({
type: String, type: String,
optional: true, optional: true,
}, },
hideWhenFull: {
type: Boolean,
optional: true,
}
}); });
const ComputedOnlySlotSchema = new SimpleSchema({ const ComputedOnlySlotSchema = new SimpleSchema({
@@ -53,7 +57,11 @@ const ComputedOnlySlotSchema = new SimpleSchema({
totalFilled: { totalFilled: {
type: SimpleSchema.Integer, type: SimpleSchema.Integer,
defaultValue: 0, defaultValue: 0,
} },
spaceLeft: {
type: SimpleSchema.Integer,
optional: true,
},
}); });
const ComputedSlotSchema = new SimpleSchema() const ComputedSlotSchema = new SimpleSchema()

View File

@@ -129,10 +129,6 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
numToFill: {
type: Number,
required: true,
},
}, },
data(){return { data(){return {
selectedNode: undefined, selectedNode: undefined,
@@ -194,8 +190,8 @@ export default {
} }
if ( if (
node.type === 'slotFiller' && node.type === 'slotFiller' &&
this.numToFill > 0 && this.model.spaceLeft > 0 &&
node.slotQuantityFilled > this.numToFill node.slotQuantityFilled > this.model.spaceLeft
){ ){
return false; return false;
} }

View File

@@ -38,7 +38,7 @@
</v-list-tile> </v-list-tile>
</v-list> </v-list>
<v-btn <v-btn
v-if="!slot.quantityExpected || slot.quantityExpected > slot.totalFilled" v-if="!slot.quantityExpected || slot.spaceLeft"
icon icon
:data-id="`slot-add-button-${slot._id}`" :data-id="`slot-add-button-${slot._id}`"
style="background-color: inherit;" style="background-color: inherit;"
@@ -73,6 +73,9 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
showHiddenSlots: {
type: Boolean,
},
}, },
methods: { methods: {
clickSlotChild({_id}){ clickSlotChild({_id}){
@@ -85,15 +88,12 @@ export default {
fillSlot(slot){ fillSlot(slot){
let slotId = slot._id; let slotId = slot._id;
let creatureId = this.creatureId; let creatureId = this.creatureId;
let numToFill = slot.quantityExpected === 0 ?
0 : slot.quantityExpected - slot.totalFilled;
this.$store.commit('pushDialogStack', { this.$store.commit('pushDialogStack', {
component: 'slot-fill-dialog', component: 'slot-fill-dialog',
elementId: `slot-add-button-${slotId}`, elementId: `slot-add-button-${slotId}`,
data: { data: {
slotId, slotId,
creatureId, creatureId,
numToFill,
}, },
callback(node){ callback(node){
if(!node) return; if(!node) return;
@@ -136,7 +136,13 @@ export default {
removed: {$ne: true}, removed: {$ne: true},
}).fetch(); }).fetch();
return slot; return slot;
}); }).filter(slot => !( // Hide full and ignored slots
!this.showHiddenSlots &&
slot.hideWhenFull &&
slot.quantityExpected > 0 &&
slot.totalFilled >= slot.quantityExpected ||
slot.ignored
));
}, },
}, },
} }

View File

@@ -54,15 +54,15 @@
name="Advanced" name="Advanced"
standalone standalone
> >
<smart-combobox
label="Tags"
multiple
chips
deletable-chips
:value="model.tags"
@change="change('tags', ...arguments)"
/>
<div class="layout row wrap justify-space-between"> <div class="layout row wrap justify-space-between">
<smart-switch
label="Hide when full"
style="width: 200px; flex-grow: 0;"
class="mx-2"
:value="model.hideWhenFull"
:error-messages="errors.hideWhenFull"
@change="change('hideWhenFull', ...arguments)"
/>
<smart-switch <smart-switch
label="Ignored" label="Ignored"
style="width: 200px; flex-grow: 0;" style="width: 200px; flex-grow: 0;"
@@ -72,6 +72,14 @@
@change="change('ignored', ...arguments)" @change="change('ignored', ...arguments)"
/> />
</div> </div>
<smart-combobox
label="Tags"
multiple
chips
deletable-chips
:value="model.tags"
@change="change('tags', ...arguments)"
/>
</form-section> </form-section>
</div> </div>
</template> </template>