adds simple cookie to store active player_id
This commit is contained in:
@@ -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 <ca.length; i++) {
|
||||
var c = ca[i];
|
||||
while (c.charAt(0) == ' ') {
|
||||
c = c.substring(1);
|
||||
}
|
||||
if (c.indexOf(name) == 0) {
|
||||
return c.substring(name.length, c.length);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
export default {
|
||||
name: 'app',
|
||||
components: {
|
||||
Player,
|
||||
GroupChest
|
||||
},
|
||||
created () {
|
||||
const cookie = getCookie("player_id");
|
||||
if (cookie == "") {
|
||||
return;
|
||||
} else {
|
||||
var newPlayerId = Number(cookie);
|
||||
console.log("initiated with id", newPlayerId);
|
||||
store.setActivePlayer(newPlayerId);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -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;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user