more refactoring, removing imports

This commit is contained in:
2019-07-31 21:48:59 +02:00
parent dae7633c11
commit 15d87e3b47
5 changed files with 74 additions and 73 deletions

View File

@@ -2,7 +2,7 @@
<table class="table is-fullwidth is-striped">
<thead>
<tr>
<th>{{ player == 0 ? 'Coffre de groupe' : 'Objets'}}</th>
<th>Objets</th>
<th v-if="canGrab"></th>
<th v-if="canSell">
<div class="buttons is-right">
@@ -18,7 +18,7 @@
</tr>
</thead>
<tbody v-if="app_state.initiated">
<template v-for="(item, idx) in content">
<template v-for="(item, idx) in items">
<tr :key="`row-${idx}`">
<td>
<strong>{{item.name}}</strong>
@@ -69,11 +69,16 @@
*/
export default {
props: {
items: {
type: Array,
required: true,
default: []
},
player: {
type: Number,
required: true,
default: 0
}
},
},
components: {
Request,
@@ -94,18 +99,13 @@
}
},
computed: {
content () {
const playerId = this.player;
console.log("Refresh chest of", playerId);
return this.app_state.player_loot[playerId];
},
// Can the active user sell items from this chest ?
canSell () {
return this.player == this.app_state.player_id;
},
totalSellValue () {
const selected = this.sell_selected;
return this.content
return this.items
.filter(item => selected.includes(item.id))
.map(item => item.base_price / 2)
.reduce((total,value) => total + value, 0);

View File

@@ -9,27 +9,13 @@
</a>
</div>
<div id="menu" class="navbar-menu">
<div class="navbar-start" v-if="!playerIsGroup">
<a class="navbar-item" @click="switchPlayerChestVisibility">
{{ app_state.show_player_chest ? 'Coffre de groupe' : 'Mon coffre' }}</a>
</div>
<div class="navbar-end">
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link">Autres</a>
<div class="navbar-dropdown is-right">
<slot name="links">
<a class="navbar-item">History of Loot</a>
<template v-if="playerIsGroup">
<hr class="navbar-divider">
<div class="navbar-item heading">Admin</div>
<a class="navbar-item">"Resolve claims"</a>
<a class="navbar-item">"Add player"</a>
</template>
<hr class="navbar-divider">
<div class="navbar-item heading">Changer</div>
<a v-for="(p,i) in app_state.player_list" :key="i"
@click="setActivePlayer(i)"
href="#" class="navbar-item">
{{ p.name }}</a>
</slot>
</div>
</div>
</div>
@@ -37,16 +23,3 @@
</nav>
</template>
<script>
import { AppStorage } from '../AppStorage'
export default {
props: ["app_state"],
methods: {
setActivePlayer (idx) { AppStorage.setActivePlayer(idx); },
switchPlayerChestVisibility () { AppStorage.switchPlayerChestVisibility(); },
},
computed: {
playerIsGroup () { return this.app_state.player_id == 0 },
}
}
</script>

View File

@@ -1,9 +1,10 @@
import { AppStorage } from '../AppStorage'
import { Api, AppStorage } from '../AppStorage'
export default {
props: ["id"],
data () { return {
notifications: [],
loot: [],
}},
methods: {
updateWealth (value) {
@@ -20,6 +21,20 @@ export default {
.then(_ => { if (AppStorage.debug) this.notifications.push("Claim withdrawn")})
},
parseLoot (items) {
this.loot = [];
items.map(item => {
this.loot.push(item);
});
}
},
watch: {
id: {
immediate: true,
handler: function(newId) {
Api.fetchLoot(newId).then(this.parseLoot);
}
},
},
computed: {
player () {
@@ -29,14 +44,14 @@ export default {
cp: '-', sp: '-', gp: '-', pp: '-',
debt: 0 };
} else {
console.log("Update player");
return AppStorage.state.player_list[this.id];
}
}
},
},
render () {
return this.$scopedSlots.default({
player: this.player,
loot: this.loot,
notifications: this.notifications,
actions: {
updateWealth: this.updateWealth,