From 93e839e40e5950d3e6c621fe4069f414faab3596 Mon Sep 17 00:00:00 2001 From: Artus Date: Thu, 13 Jun 2019 21:46:48 +0200 Subject: [PATCH] adds simple cookie to store active player_id --- lootalot_front/src/App.vue | 28 ++++++++++++++++++++++++ lootalot_front/src/components/Player.vue | 19 ++++++++-------- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/lootalot_front/src/App.vue b/lootalot_front/src/App.vue index cd7c52d..0f7f5d9 100644 --- a/lootalot_front/src/App.vue +++ b/lootalot_front/src/App.vue @@ -30,6 +30,8 @@ export const store = { setActivePlayer (newPlayerId) { if (this.debug) console.log('setActivePlayer to ', newPlayerId) this.state.player_id = newPlayerId + document.cookie = `player_id=${newPlayerId};`; + if (this.debug) console.log('setCookie', document.cookie); }, switchPlayerChestVisibility () { if (this.debug) console.log('switchPlayerChestVisibility', !this.state.show_player_chest) @@ -37,11 +39,37 @@ export const store = { } } +function getCookie(cname) { + var name = cname + "="; + var decodedCookie = decodeURIComponent(document.cookie); + var ca = decodedCookie.split(';'); + for(var i = 0; i diff --git a/lootalot_front/src/components/Player.vue b/lootalot_front/src/components/Player.vue index 70c8566..d68c873 100644 --- a/lootalot_front/src/components/Player.vue +++ b/lootalot_front/src/components/Player.vue @@ -75,16 +75,11 @@ data () { return { app_state: store.state, - player: { - name: "Groupe", - wealth: [100,240,145000,134], - debt: 0, - }, player_list: [ - {id: 0, name: "Groupe"}, - {id: 1, name: "Lomion"}, - {id: 4, name: "Oilosse"}, - {id: 3, name: "Fefi"}, + {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, edit_wealth: false, @@ -92,6 +87,12 @@ }; }, computed: { + player () { + const id = this.app_state.player_id; + const idx = this.player_list.findIndex(p => p.id == id); + console.log(id, idx); + return this.player_list[idx]; + }, name () { return this.player.name; },