From 5f0e6624e0a6c9199aef4b42316edfc0416eaae8 Mon Sep 17 00:00:00 2001 From: Artus Date: Thu, 4 Jul 2019 16:02:05 +0200 Subject: [PATCH] going on, reactivity is not properly working --- lootalot_db/db.sqlite3 | Bin 28672 -> 28672 bytes lootalot_front/src/AppStorage.js | 62 +++++++++----- lootalot_front/src/components/Player.vue | 25 +++--- lootalot_front/src/components/Wealth.vue | 102 ++++++++++++----------- 4 files changed, 107 insertions(+), 82 deletions(-) diff --git a/lootalot_db/db.sqlite3 b/lootalot_db/db.sqlite3 index 7fd6da7668595dd1005dadf9b52a39d0d13a1df5..5f85b4634ec27f85bc757e2378b6c53470f788a1 100644 GIT binary patch delta 102 zcmZp8z}WDBae_3X%0wAwMwN{T%ltV`Gw`40f5(4!v!KF8en&+H1Q1~0V36eC;9z8Q tFUl`1NEPSjXX0QG1&J`ZrKV+iGIR+rf|W2ba`@!uX6EOyDlIY)008;66@~x+ delta 85 zcmZp8z}WDBae_3X^h6nFM(K?S%ltVmFz|oif53lXv!KBtegi%x4hB&UAYgJ!P0M8H f;bY`rkOc8LeDZTM^Yi!^V0`zY{L+HdMFs)@`EV5c diff --git a/lootalot_front/src/AppStorage.js b/lootalot_front/src/AppStorage.js index 39e6be4..9651017 100644 --- a/lootalot_front/src/AppStorage.js +++ b/lootalot_front/src/AppStorage.js @@ -1,6 +1,6 @@ -const Api = { +export const Api = { fetchPlayerList () { return fetch("http://localhost:8088/players") .then(r => r.json()) @@ -19,15 +19,16 @@ const Api = { }, putClaim (playerId, itemId) { console.log('newRequest from', playerId, 'on', itemId); - return true; + return Promise.resolve(true); }, unClaim (playerId, itemId) { console.log('cancelRequest of', playerId, 'on', itemId); - return true; + return Promise.resolve(true); }, updateWealth (playerId, goldValue) { - console.log('Update wealth', goldValue); - return true; + return fetch("http://localhost:8088/update-wealth/" + playerId + "/" + goldValue) + .then(r => r.json()) + .catch(e => console.error("Fetch error", e)); } }; @@ -92,31 +93,46 @@ export const AppStorage = { if (this.debug) console.log('switchPlayerChestVisibility', !this.state.show_player_chest) this.state.show_player_chest = !this.state.show_player_chest }, + updatePlayerWealth (goldValue) { + if (this.debug) console.log('updatePlayerWealth', goldValue, this.state.player_id) + return Api.updateWealth(this.state.player_id, goldValue) + .then(done => { + if (done) { + // Update player wealth + this.state.player_list[this.state.player_id].cp += 1; + } + return done; + }); + }, // Put a claim on an item from group chest. putRequest (itemId) { const playerId = this.state.player_id - const done = Api.putClaim(playerId, itemId); - if (done) { - // Update cliend-side state - this.state.requests[playerId].push(itemId); - } else { - if (this.debug) console.log("API responded with 'false'") - } + Api.putClaim(playerId, itemId) + .then(done => { + if (done) { + // Update cliend-side state + this.state.requests[playerId].push(itemId); + } else { + if (this.debug) console.log("API responded with 'false'") + } + }); }, // Withdraws a claim. cancelRequest(itemId) { const playerId = this.state.player_id - const done = Api.unClaim(playerId, itemId); - if (done) { - var idx = this.state.requests[playerId].indexOf(itemId); - if (idx > -1) { - this.state.requests[playerId].splice(idx, 1); - } else { - if (this.debug) console.log("cancel a non-existent request") - } - } else { - if (this.debug) console.log("API responded with 'false'") - } + Api.unClaim(playerId, itemId) + .then(done => { + if (done) { + var idx = this.state.requests[playerId].indexOf(itemId); + if (idx > -1) { + this.state.requests[playerId].splice(idx, 1); + } else { + if (this.debug) console.log("cancel a non-existent request") + } + } else { + if (this.debug) console.log("API responded with 'false'") + } + }); } } diff --git a/lootalot_front/src/components/Player.vue b/lootalot_front/src/components/Player.vue index aeecf3a..551afac 100644 --- a/lootalot_front/src/components/Player.vue +++ b/lootalot_front/src/components/Player.vue @@ -27,25 +27,22 @@
+ @updated="console.log('updated wealth')">

Dette : {{ player.debt }}gp

+ + Coffre +
- -
+ +
+ Historique
@@ -86,7 +83,11 @@ return this.state.player_list[idx]; }, wealth () { - return [this.player.cp, this.player.sp, this.player.gp, this.player.pp]; + const cp = this.player.cp + const sp = this.player.sp + const gp = this.player.gp + const pp = this.player.pp + return [cp, sp, gp, pp]; }, // Check if the active player is the special 'Group' player playerIsGroup () { diff --git a/lootalot_front/src/components/Wealth.vue b/lootalot_front/src/components/Wealth.vue index 97fe0b0..a7798a2 100644 --- a/lootalot_front/src/components/Wealth.vue +++ b/lootalot_front/src/components/Wealth.vue @@ -1,82 +1,90 @@