moves logic to PlayerView, adds simple notifications when debugging
This commit is contained in:
@@ -1,16 +1,20 @@
|
|||||||
<template>
|
<template>
|
||||||
<main id="app" class="container">
|
<main id="app" class="container">
|
||||||
<PlayerView :id="state.player_id" v-slot="{ player, updateWealth }">
|
<PlayerView :id="state.player_id"
|
||||||
|
v-slot="{ player, notifications, actions }">
|
||||||
<section class="section">
|
<section class="section">
|
||||||
<HeaderBar :app_state="state">
|
<HeaderBar :app_state="state">
|
||||||
<template v-slot:title>{{ player.name }}</template>
|
<template v-slot:title>{{ player.name }}</template>
|
||||||
</HeaderBar>
|
</HeaderBar>
|
||||||
|
<p v-if="notifications">{{ 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="updateWealth">
|
@update="actions.updateWealth">
|
||||||
</wealth>
|
</wealth>
|
||||||
<Chest :player="state.show_player_chest ? player.id : 0"></Chest>
|
<Chest :player="state.show_player_chest ? player.id : 0"
|
||||||
|
@claim="actions.putClaim"
|
||||||
|
@unclaim="actions.withdrawClaim"></Chest>
|
||||||
</section>
|
</section>
|
||||||
</PlayerView>
|
</PlayerView>
|
||||||
</main>
|
</main>
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ export const AppStorage = {
|
|||||||
// Put a claim on an item from group chest.
|
// Put a claim on an item from group chest.
|
||||||
putRequest (itemId) {
|
putRequest (itemId) {
|
||||||
const playerId = this.state.player_id
|
const playerId = this.state.player_id
|
||||||
Api.putClaim(playerId, itemId)
|
return Api.putClaim(playerId, itemId)
|
||||||
.then(done => {
|
.then(done => {
|
||||||
// Update cliend-side state
|
// Update cliend-side state
|
||||||
this.state.player_claims[playerId].push(itemId);
|
this.state.player_claims[playerId].push(itemId);
|
||||||
@@ -139,7 +139,7 @@ export const AppStorage = {
|
|||||||
// Withdraws a claim.
|
// Withdraws a claim.
|
||||||
cancelRequest(itemId) {
|
cancelRequest(itemId) {
|
||||||
const playerId = this.state.player_id
|
const playerId = this.state.player_id
|
||||||
Api.unClaim(playerId, itemId)
|
return Api.unClaim(playerId, itemId)
|
||||||
.then(done => {
|
.then(done => {
|
||||||
var idx = this.state.player_claims[playerId].indexOf(itemId);
|
var idx = this.state.player_claims[playerId].indexOf(itemId);
|
||||||
if (idx > -1) {
|
if (idx > -1) {
|
||||||
|
|||||||
@@ -24,7 +24,10 @@
|
|||||||
<strong>{{item.name}}</strong>
|
<strong>{{item.name}}</strong>
|
||||||
</td>
|
</td>
|
||||||
<td v-if="canGrab">
|
<td v-if="canGrab">
|
||||||
<Request :item="item.id"></Request>
|
<Request :item="item.id"
|
||||||
|
@claim="(data) => $emit('claim', data)"
|
||||||
|
@unclaim="(data) => $emit('unclaim', data)"
|
||||||
|
></Request>
|
||||||
</td>
|
</td>
|
||||||
<td v-if="canSell">
|
<td v-if="canSell">
|
||||||
<div class="field is-grouped is-pulled-right" v-show="is_selling">
|
<div class="field is-grouped is-pulled-right" v-show="is_selling">
|
||||||
|
|||||||
@@ -2,13 +2,24 @@ import { AppStorage } from '../AppStorage'
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: ["id"],
|
props: ["id"],
|
||||||
data () { return {}},
|
data () { return {
|
||||||
|
notifications: [],
|
||||||
|
}},
|
||||||
methods: {
|
methods: {
|
||||||
updateWealth (value) {
|
updateWealth (value) {
|
||||||
AppStorage.updatePlayerWealth(value)
|
AppStorage.updatePlayerWealth(value)
|
||||||
.then(_ => {if (AppStorage.debug) console.log("Wealth updated")})
|
.then(_ => {if (AppStorage.debug) this.notifications.push("Wealth updated")})
|
||||||
.catch(e => {if (AppStorage.debug) console.error("wealthUpdate Error", e)})
|
.catch(e => {if (AppStorage.debug) console.error("wealthUpdate Error", e)})
|
||||||
}
|
},
|
||||||
|
putClaim (itemId) {
|
||||||
|
AppStorage.putRequest(itemId)
|
||||||
|
.then(_ => { if (AppStorage.debug) this.notifications.push("Claim put")})
|
||||||
|
},
|
||||||
|
withdrawClaim (itemId) {
|
||||||
|
AppStorage.cancelRequest(itemId)
|
||||||
|
.then(_ => { if (AppStorage.debug) this.notifications.push("Claim withdrawn")})
|
||||||
|
|
||||||
|
},
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
player () {
|
player () {
|
||||||
@@ -26,7 +37,12 @@ export default {
|
|||||||
render () {
|
render () {
|
||||||
return this.$scopedSlots.default({
|
return this.$scopedSlots.default({
|
||||||
player: this.player,
|
player: this.player,
|
||||||
|
notifications: this.notifications,
|
||||||
|
actions: {
|
||||||
updateWealth: this.updateWealth,
|
updateWealth: this.updateWealth,
|
||||||
|
putClaim: this.putClaim,
|
||||||
|
withdrawClaim: this.withdrawClaim,
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,11 +60,11 @@
|
|||||||
methods: {
|
methods: {
|
||||||
// The active player claims the item
|
// The active player claims the item
|
||||||
putRequest () {
|
putRequest () {
|
||||||
AppStorage.putRequest(this.item)
|
this.$emit("claim", this.item);
|
||||||
},
|
},
|
||||||
// The active player withdraws his request
|
// The active player withdraws his request
|
||||||
cancelRequest () {
|
cancelRequest () {
|
||||||
AppStorage.cancelRequest(this.item)
|
this.$emit("unclaim", this.item);
|
||||||
},
|
},
|
||||||
// The active player insist on his claim
|
// The active player insist on his claim
|
||||||
// TODO: Find a simple and fun system to express
|
// TODO: Find a simple and fun system to express
|
||||||
|
|||||||
Reference in New Issue
Block a user