makes modifier kind-of work, needs refactoring
This commit is contained in:
@@ -12,7 +12,7 @@
|
|||||||
<p v-if="!is_selling">Vendre</p>
|
<p v-if="!is_selling">Vendre</p>
|
||||||
<p v-else>{{ selected_items.length > 0 ? `${totalSelectedValue} po` : 'Annuler' }}</p>
|
<p v-else>{{ selected_items.length > 0 ? `${totalSelectedValue} po` : 'Annuler' }}</p>
|
||||||
</button>
|
</button>
|
||||||
<PercentInput v-show="is_selling"></PercentInput>
|
<PercentInput v-show="is_selling" v-model="modifiers['global']"></PercentInput>
|
||||||
</div>
|
</div>
|
||||||
<div v-else-if="perms.canBuy">
|
<div v-else-if="perms.canBuy">
|
||||||
<button class="button is-danger is-fullwidth"
|
<button class="button is-danger is-fullwidth"
|
||||||
@@ -43,7 +43,7 @@
|
|||||||
:value="item.id"
|
:value="item.id"
|
||||||
v-model="selected_items">
|
v-model="selected_items">
|
||||||
</label>
|
</label>
|
||||||
<PercentInput></PercentInput>
|
<PercentInput v-model="modifiers[item.id]"></PercentInput>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -55,7 +55,6 @@
|
|||||||
<script>
|
<script>
|
||||||
import Request from './Request.vue'
|
import Request from './Request.vue'
|
||||||
import PercentInput from './PercentInput.vue'
|
import PercentInput from './PercentInput.vue'
|
||||||
import Loot from './Loot.vue'
|
|
||||||
/*
|
/*
|
||||||
The chest displays a collection of items.
|
The chest displays a collection of items.
|
||||||
|
|
||||||
@@ -68,7 +67,7 @@
|
|||||||
items: {
|
items: {
|
||||||
type: Array,
|
type: Array,
|
||||||
required: true,
|
required: true,
|
||||||
default: []
|
default () { return []; }
|
||||||
},
|
},
|
||||||
perms: {
|
perms: {
|
||||||
type: Object,
|
type: Object,
|
||||||
@@ -78,21 +77,23 @@
|
|||||||
components: {
|
components: {
|
||||||
Request,
|
Request,
|
||||||
PercentInput,
|
PercentInput,
|
||||||
Loot,
|
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
is_selling: false,
|
is_selling: false,
|
||||||
selected_items: [],
|
selected_items: [],
|
||||||
|
modifiers: {},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
buySelectedItems () {
|
buySelectedItems () {
|
||||||
const items = this.items.filter(i => this.selected_items.includes(i.id));
|
const items = this.items.filter(i => this.selected_items.includes(i.id));
|
||||||
var payload = [];
|
var payload = [];
|
||||||
items.forEach(item => {
|
for (var idx in items) {
|
||||||
payload.push([item.id, null]);
|
var item = items[idx];
|
||||||
});
|
var mod = this._modifierForItem(item.id);
|
||||||
|
payload.push([item.id, mod]);
|
||||||
|
}
|
||||||
this.$emit("buy", payload);
|
this.$emit("buy", payload);
|
||||||
this.selected_items = [];
|
this.selected_items = [];
|
||||||
},
|
},
|
||||||
@@ -105,26 +106,38 @@
|
|||||||
const items = this.items.filter(i => this.selected_items.includes(i.id));
|
const items = this.items.filter(i => this.selected_items.includes(i.id));
|
||||||
var payload = [];
|
var payload = [];
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
payload.push([item.id, null]);
|
const mod = this._modifierForItem(item.id);
|
||||||
|
payload.push([item.id, mod]);
|
||||||
});
|
});
|
||||||
this.$emit("sell", payload);
|
this.$emit("sell", payload);
|
||||||
this.selected_items = [];
|
this.selected_items = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
// TODO: fix this. It breaks reactivity and it's lazy
|
||||||
|
_modifierForItem (itemId) {
|
||||||
|
if (!(itemId in this.modifiers)) {
|
||||||
|
this.modifiers[itemId] = 0;
|
||||||
|
}
|
||||||
|
return 1 + this.modifiers[itemId] / 100;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
showSelectors () { return !this.perms.canGrab && (this.is_selling || this.perms.canBuy); },
|
showSelectors () { return !this.perms.canGrab && (this.is_selling || this.perms.canBuy); },
|
||||||
totalSelectedValue () {
|
totalSelectedValue () {
|
||||||
return this.items
|
const global_mod = this._modifierForItem("global");
|
||||||
|
var total = this.items
|
||||||
.filter(item => this.selected_items.includes(item.id))
|
.filter(item => this.selected_items.includes(item.id))
|
||||||
.map(item => {
|
.map(item => {
|
||||||
|
const mod = this._modifierForItem(item.id);
|
||||||
|
var price = item.base_price * mod;
|
||||||
if (this.is_selling) {
|
if (this.is_selling) {
|
||||||
return item.base_price / 2;
|
price = price / 2;
|
||||||
} else {
|
}
|
||||||
return item.base_price;
|
return price;
|
||||||
}})
|
})
|
||||||
.reduce((total,value) => total + value, 0);
|
.reduce((total,value) => total + value, 0);
|
||||||
|
return global_mod * total;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="field has-addons">
|
<div class="field has-addons">
|
||||||
<div v-show="is_opened" class="control has-icons-left">
|
<div v-show="is_opened" class="control has-icons-left">
|
||||||
<input class="input" type="number" size="3" min=-50 max=50 step=5>
|
<input class="input" :value="value" @input="input" type="number" size="3" min="-50" max=50 step=5>
|
||||||
<span class="icon is-left">
|
<span class="icon is-left">
|
||||||
<i class="fas fa-percent"></i>
|
<i class="fas fa-percent"></i>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<button class="button" @click="is_opened = !is_opened">
|
<button class="button" @click="switchOpenedState">
|
||||||
<small v-if="!is_opened">Mod.</small>
|
<small v-if="!is_opened">Mod.</small>
|
||||||
<span v-else class="icon"><i class="fas fa-times-circle"></i></span>
|
<span v-else class="icon"><i class="fas fa-times-circle"></i></span>
|
||||||
</button>
|
</button>
|
||||||
@@ -17,10 +17,21 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
|
props: ["value"],
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
is_opened: false,
|
is_opened: false,
|
||||||
};
|
};
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
input (event) { this.$emit("input", event.target.value); },
|
||||||
|
switchOpenedState () {
|
||||||
|
this.is_opened = !this.is_opened;
|
||||||
|
// Reset the modifier in closed state
|
||||||
|
if (!this.is_opened) {
|
||||||
|
this.$emit("input", 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user