diff --git a/lootalot_db/db.sqlite3 b/lootalot_db/db.sqlite3 index 7fd6da7..5f85b46 100644 Binary files a/lootalot_db/db.sqlite3 and b/lootalot_db/db.sqlite3 differ 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 @@
- -PA
-{{ wealth[1] }}
-PP
+{{ wealth[3] }}
+PO
-{{ wealth[2] }}
-PG
+{{ wealth[2] }}
+PP
-{{ wealth[3] }}
-PA
+{{ wealth[1] }}
+ +PC
+{{ wealth[0] }}
+