removes Chest use of AppStorage, various fixes

This commit is contained in:
2019-08-01 14:46:25 +02:00
parent 15d87e3b47
commit dde7dc3770
4 changed files with 67 additions and 76 deletions

View File

@@ -1,8 +1,8 @@
<template> <template>
<main id="app" class="container">
<PlayerView :id="state.player_id" <PlayerView :id="state.player_id"
v-slot="{ player, loot, notifications, actions }"> v-slot="{ player, loot, notifications, actions }">
<section class="section"> <main id="app" class="container">
<header class="section">
<HeaderBar :app_state="state"> <HeaderBar :app_state="state">
<template v-slot:title>{{ player.name }}</template> <template v-slot:title>{{ player.name }}</template>
<template v-slot:links> <template v-slot:links>
@@ -21,27 +21,38 @@
{{ p.name }}</a> {{ p.name }}</a>
</template> </template>
</HeaderBar> </HeaderBar>
<p v-if="notifications.length > 0">{{ notifications }}</p> <p v-show="notifications.length > 0">{{ notifications }}</p>
<Wealth <Wealth
:wealth="[player.cp, player.sp, player.gp, player.pp]" :wealth="[player.cp, player.sp, player.gp, player.pp]"
:debt="player.debt" :debt="player.debt"
@update="actions.updateWealth"> @update="actions.updateWealth">
</wealth> </wealth>
<div class="tabs is-centered is-boxed is-medium" v-show="!playerIsGroup"> </header>
<nav>
<div class="tabs is-centered is-boxed is-medium">
<ul> <ul>
<li :class="{ 'is-active': !state.show_player_chest }"> <li :class="{ 'is-active': !state.show_player_chest }">
<a @click="switchPlayerChestVisibility">Coffre de groupe</a></li> <a @click="switchPlayerChestVisibility">Coffre de groupe</a></li>
<li :class="{ 'is-active': state.show_player_chest }"> <li :class="{ 'is-active': state.show_player_chest }" v-show="!playerIsGroup">
<a @click="switchPlayerChestVisibility">Mon coffre</a></li> <a @click="switchPlayerChestVisibility">Mon coffre</a></li>
<li>
<a class="disabled">
+ {{ playerIsGroup ? 'Nouveau Loot' : 'Acheter' }}
</a>
</li>
</ul> </ul>
</div> </div>
<Chest :items="state.show_player_chest ? loot : state.group_loot" </nav>
:player="state.show_player_chest ? player.id : 0" <main class="">
<Chest
:items="state.show_player_chest ? loot : state.group_loot"
:perms="permissions"
@claim="actions.putClaim" @claim="actions.putClaim"
@unclaim="actions.withdrawClaim"></Chest> @unclaim="actions.withdrawClaim">
</section> </Chest>
</PlayerView>
</main> </main>
</main>
</PlayerView>
</template> </template>
<script> <script>
@@ -97,6 +108,12 @@ export default {
switchPlayerChestVisibility () { AppStorage.switchPlayerChestVisibility(); }, switchPlayerChestVisibility () { AppStorage.switchPlayerChestVisibility(); },
}, },
computed: { computed: {
permissions () {
return {
canGrab: this.state.player_id != 0 && !this.state.show_player_chest,
canSell: this.state.show_player_chest || this.state.player_id == 0,
};
},
playerIsGroup () { return this.state.player_id == 0 }, playerIsGroup () { return this.state.player_id == 0 },
} }
} }

View File

@@ -3,9 +3,9 @@
<thead> <thead>
<tr> <tr>
<th>Objets</th> <th>Objets</th>
<th v-if="canGrab"></th> <th>Valeur</th>
<th v-if="canSell"> <th>
<div class="buttons is-right"> <div v-show="perms.canSell" class="buttons is-right" :class="{'has-addons': is_selling}">
<button class="button" :class="is_selling ? 'is-danger' : 'is-warning'" <button class="button" :class="is_selling ? 'is-danger' : 'is-warning'"
@click="is_selling = !is_selling"> @click="is_selling = !is_selling">
<span class="icon"><i class="fas fa-coins"></i></span> <span class="icon"><i class="fas fa-coins"></i></span>
@@ -14,58 +14,50 @@
</button> </button>
<PercentInput v-show="is_selling"></PercentInput> <PercentInput v-show="is_selling"></PercentInput>
</div> </div>
<div v-show="perms.canBuy">
<button class="button is-primary">Acheter</button>
</div>
</th> </th>
</tr> </tr>
</thead> </thead>
<tbody v-if="app_state.initiated"> <tbody>
<template v-for="(item, idx) in items"> <template v-for="(item, idx) in items">
<tr :key="`row-${idx}`"> <tr :key="`row-${idx}`">
<td><strong>{{item.name}}</strong></td>
<td>{{ item.base_price }}po</td>
<td> <td>
<strong>{{item.name}}</strong> <Request v-show="perms.canGrab"
</td> :item="item.id"
<td v-if="canGrab">
<Request :item="item.id"
@claim="(data) => $emit('claim', data)" @claim="(data) => $emit('claim', data)"
@unclaim="(data) => $emit('unclaim', data)" @unclaim="(data) => $emit('unclaim', data)">
></Request> </Request>
</td> <div v-show="is_selling || perms.canBuy" class="field is-grouped is-pulled-right" >
<td v-if="canSell"> <input type="checkbox" class="checkbox"
<div class="field is-grouped is-pulled-right" v-show="is_selling"> id="`select-${idx}`"
<div class="control">
<label class="label">
<input type="checkbox"
id="`item-${idx}`"
:value="item.id" :value="item.id"
v-model="sell_selected"> v-model="selected_items">
<label for="`select-${idx}`">
{{item.base_price / 2}} GP {{item.base_price / 2}} GP
</label> </label>
</div>
<PercentInput></PercentInput> <PercentInput></PercentInput>
</div> </div>
</td> </td>
</tr> </tr>
</template> </template>
</tbody> </tbody>
<p v-else>Loading...</p>
</table> </table>
</template> </template>
<script> <script>
import { AppStorage } from '../AppStorage'
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' import Loot from './Loot.vue'
/* /*
The chest displays the collection of items owned by a player The chest displays a collection of items.
TO TEST : A set of permissions is passed as props, to update
- Possible interactions depends on player_id and current chest the possible actions of active user upon these items.
- Objects are displayed as a table
Sell workflow :
1. Click sell (sell becomes danger)
2. Check objects to sell (sell button displays total value)
3. Click sell to confirm
*/ */
export default { export default {
props: { props: {
@@ -74,10 +66,9 @@
required: true, required: true,
default: [] default: []
}, },
player: { perms: {
type: Number, type: Object,
required: true, required: true,
default: 0
}, },
}, },
components: { components: {
@@ -87,42 +78,22 @@
}, },
data () { data () {
return { return {
app_state: AppStorage.state,
is_selling: false, is_selling: false,
is_adding: false, is_adding: false,
sell_selected: [], selected_items: [],
}; };
}, },
methods: {
fetchLoot () {
}
},
computed: { computed: {
// Can the active user sell items from this chest ?
canSell () {
return this.player == this.app_state.player_id;
},
totalSellValue () { totalSellValue () {
const selected = this.sell_selected;
return this.items return this.items
.filter(item => selected.includes(item.id)) .filter(item => this.selected_items.includes(item.id))
.map(item => item.base_price / 2) .map(item => item.base_price / 2)
.reduce((total,value) => total + value, 0); .reduce((total,value) => total + value, 0);
}, },
// Can the user grab items from this chest ?
canGrab () {
return (this.app_state.player_id != 0 // User is not the group
&& this.player == 0); // This is the group chest
},
canAdd () {
return (this.app_state.player_id == 0
&& this.player == 0);
},
}, },
} }
</script> </script>
<style scoped> <style scoped>
.table td, .table th { vertical-align: middle; } .table td, .table th { vertical-align: bottom; }
</style> </style>

View File

@@ -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 is-small" type="number" size="3" min=-50 max=50 step=5> <input class="input" type="number" size="3" min=-50 max=50 step=5>
<span class="icon is-small 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 is-small is-outlined" @click="is_opened = !is_opened"> <button class="button is-outlined" @click="is_opened = !is_opened">
<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>
@@ -24,3 +24,7 @@
} }
} }
</script> </script>
<style scoped>
.input { width: 6em; }
</style>

View File

@@ -16,7 +16,6 @@
</template> </template>
<button class="button is-primary" <button class="button is-primary"
@click="putRequest" @click="putRequest"
:class="{'is-small': isRequested}"
:disabled="isRequested"> :disabled="isRequested">
<span class="icon is-small"> <span class="icon is-small">
<i class="fas fa-praying-hands"></i> <i class="fas fa-praying-hands"></i>