adds requests state for Request component

This commit is contained in:
2019-06-14 15:38:24 +02:00
parent 0e71776f4f
commit dc7a0da95d
4 changed files with 51 additions and 31 deletions

View File

@@ -18,13 +18,15 @@ export const store = {
debug: true, debug: true,
state: { state: {
player_id: 0, player_id: 0,
player_list: [
{id: 0, name: "Groupe", wealth: [0,0,0,0], debt: 0},
{id: 1, name: "Lomion", wealth: [0,0,0,0], debt: 0},
{id: 4, name: "Oilosse", wealth: [0,0,0,0], debt: 0},
{id: 3, name: "Fefi", wealth: [0,0,0,0], debt: 0},
],
show_player_chest: false, show_player_chest: false,
// methods requests: { // TEST: must be initialised with players ids
isPlayer () { 0: [], 1: [], 4: [], 3: []
this.player_id != 0
},
isGroup () {
this.player_id == 0
}, },
}, },
setActivePlayer (newPlayerId) { setActivePlayer (newPlayerId) {
@@ -36,7 +38,12 @@ export const store = {
switchPlayerChestVisibility () { switchPlayerChestVisibility () {
if (this.debug) console.log('switchPlayerChestVisibility', !this.state.show_player_chest) if (this.debug) console.log('switchPlayerChestVisibility', !this.state.show_player_chest)
this.state.show_player_chest = !this.state.show_player_chest this.state.show_player_chest = !this.state.show_player_chest
} },
putRequest (itemId) {
const playerId = this.state.player_id
if (this.debug) console.log('newRequest from', playerId, 'on', itemId)
this.state.requests[playerId].push(itemId);
},
} }
function getCookie(cname) { function getCookie(cname) {

View File

@@ -5,7 +5,7 @@
<thead> <thead>
<tr> <tr>
<th width="100%" >Objets de {{ player }}</th> <th width="100%" >Objets de {{ player }}</th>
<th v-if="canGrab"></th> <th v-if="canGrab" style="min-width: 120px"></th>
<th v-if="canSell" style="min-width: 120px"> <th v-if="canSell" style="min-width: 120px">
<button class="button is-fullwidth" <button class="button is-fullwidth"
:class="is_selling ? 'is-danger' : 'is-warning'" :class="is_selling ? 'is-danger' : 'is-warning'"

View File

@@ -17,7 +17,7 @@
<div class="dropdown-menu" id="dropdown-menu" role="menu" <div class="dropdown-menu" id="dropdown-menu" role="menu"
v-closable="{ exclude: ['dropdown_btn'], handler: 'closeDropdown', visible: show_dropdown }"> v-closable="{ exclude: ['dropdown_btn'], handler: 'closeDropdown', visible: show_dropdown }">
<div class="dropdown-content"> <div class="dropdown-content">
<a v-for="(p,i) in player_list" :key="i" <a v-for="(p,i) in state.player_list" :key="i"
@click="setActivePlayer(i)" @click="setActivePlayer(i)"
href="#" class="dropdown-item"> href="#" class="dropdown-item">
{{ p.name }}</a> {{ p.name }}</a>
@@ -41,9 +41,9 @@
<a href="#" class="card-footer-item disabled">Historique</a> <a href="#" class="card-footer-item disabled">Historique</a>
</footer> </footer>
</div> </div>
<div class="card" v-show="app_state.show_player_chest" style="margin-top: 1em;"> <div class="card" v-show="state.show_player_chest" style="margin-top: 1em;">
<div class="card-content"> <div class="card-content">
<Chest :player="app_state.player_id"></Chest> <Chest :player="state.player_id"></Chest>
</div> </div>
</div> </div>
</div> </div>
@@ -74,13 +74,7 @@
components: { Chest, Wealth }, components: { Chest, Wealth },
data () { data () {
return { return {
app_state: store.state, state: store.state,
player_list: [
{id: 0, name: "Groupe", wealth: [0,0,0,0], debt: 0},
{id: 1, name: "Lomion", wealth: [0,0,0,0], debt: 0},
{id: 4, name: "Oilosse", wealth: [0,0,0,0], debt: 0},
{id: 3, name: "Fefi", wealth: [0,0,0,0], debt: 0},
],
show_dropdown: false, show_dropdown: false,
edit_wealth: false, edit_wealth: false,
handleOutsideClick: null, handleOutsideClick: null,
@@ -88,16 +82,16 @@
}, },
computed: { computed: {
player () { player () {
const id = this.app_state.player_id; const id = this.state.player_id;
const idx = this.player_list.findIndex(p => p.id == id); const idx = this.state.player_list.findIndex(p => p.id == id);
return this.player_list[idx]; return this.state.player_list[idx];
}, },
name () { name () {
return this.player.name; return this.player.name;
}, },
// Check if the active player is the special 'Group' player // Check if the active player is the special 'Group' player
playerIsGroup () { playerIsGroup () {
return this.app_state.player_id == 0; return this.state.player_id == 0;
} }
}, },
methods: { methods: {
@@ -105,15 +99,15 @@
store.switchPlayerChestVisibility(); store.switchPlayerChestVisibility();
}, },
hidePlayerChest () { hidePlayerChest () {
if (this.app_state.show_player_chest) { if (this.state.show_player_chest) {
this.switchPlayerChestVisibility(); this.switchPlayerChestVisibility();
} }
}, },
setActivePlayer (playerIdx) { setActivePlayer (playerIdx) {
const newId = this.player_list[playerIdx].id; const newId = this.state.player_list[playerIdx].id;
store.setActivePlayer(newId); store.setActivePlayer(newId);
if (newId == 0) { this.hidePlayerChest() } if (newId == 0) { this.hidePlayerChest() }
this.player.name = this.player_list[playerIdx].name this.player.name = this.state.player_list[playerIdx].name
}, },
closeDropdown () { closeDropdown () {
this.show_dropdown = false this.show_dropdown = false

View File

@@ -1,21 +1,40 @@
<template> <template>
<button class="button is-primary" disabled> <div>
<button class="button is-primary is-fullwidth"
@click="putRequest"
:disabled="isRequested">
<span class="icon"> <span class="icon">
<i class="fas fa-praying-hands"></i> <i class="fas fa-praying-hands"></i>
</span> </span>
<small>Request pending...</small>
</button> </button>
</div>
</template> </template>
<style> <script>
import { store } from '../App.vue'
export default { export default {
props: ["item"], props: ["item"],
data () { data () {
return { return {
state: store.state,
_requested: false, // Dummy state
}; };
}, },
computed: { computed: {
// Check if item is requested by active player
isRequested () {
const reqs = this.state.requests[this.state.player_id];
return reqs.includes(this.item);
},
// Check if item is requested by multiple players including active one
isInConflict () {
},
},
methods: {
putRequest () {
store.putRequest(this.item)
},
},
} }
} </script>
</style>