mirror of https://github.com/bra1n/townsquare.git
fixed localstorage
This commit is contained in:
parent
78b0b49e01
commit
58802ffb5b
54
src/App.vue
54
src/App.vue
|
@ -1,6 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<div id="app" @keyup="keyup" tabindex="-1">
|
<div id="app" @keyup="keyup" tabindex="-1">
|
||||||
<TownInfo :players="players"></TownInfo>
|
<TownInfo :players="players" :set="set"></TownInfo>
|
||||||
<TownSquare
|
<TownSquare
|
||||||
:is-public="isPublic"
|
:is-public="isPublic"
|
||||||
:players="players"
|
:players="players"
|
||||||
|
@ -9,16 +9,19 @@
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<font-awesome-icon icon="cogs" @click="isControlOpen = !isControlOpen" />
|
<font-awesome-icon icon="cogs" @click="isControlOpen = !isControlOpen" />
|
||||||
<ul v-if="isControlOpen">
|
<ul v-if="isControlOpen">
|
||||||
<li v-on:click="togglePublic">Toggle <em>G</em>rimoire</li>
|
<li @click="togglePublic">Toggle <em>G</em>rimoire</li>
|
||||||
<li v-on:click="addPlayer" v-if="players.length < 20">
|
<li @click="addPlayer" v-if="players.length < 20">
|
||||||
<em>A</em>dd Player
|
<em>A</em>dd Player
|
||||||
</li>
|
</li>
|
||||||
<li v-on:click="togglePublic" v-if="players.length > 4">
|
<li @click="togglePublic" v-if="players.length > 4">
|
||||||
Select Roles
|
Select Roles
|
||||||
</li>
|
</li>
|
||||||
<li v-on:click="randomizeSeatings" v-if="players.length > 2">
|
<li @click="randomizeSeatings" v-if="players.length > 2">
|
||||||
<em>R</em>andomize Seatings
|
<em>R</em>andomize Seatings
|
||||||
</li>
|
</li>
|
||||||
|
<li @click="clearPlayers" v-if="players.length">
|
||||||
|
Clear Players
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -44,24 +47,9 @@ export default {
|
||||||
data: () => ({
|
data: () => ({
|
||||||
isPublic: true,
|
isPublic: true,
|
||||||
isControlOpen: false,
|
isControlOpen: false,
|
||||||
players: [
|
players: [],
|
||||||
// {
|
|
||||||
// name: "Steffen",
|
|
||||||
// role: roles.get("baron"),
|
|
||||||
// reminders: [{ role: "imp", name: "Die" }]
|
|
||||||
// },
|
|
||||||
// { name: "Tino", role: roles.get("beggar"), reminders: [] },
|
|
||||||
// { name: "Basti", role: roles.get("chef"), reminders: [] },
|
|
||||||
// { name: "Bernd", role: roles.get("ravenkeeper"), reminders: [] },
|
|
||||||
// { name: "Tim", role: roles.get("drunk"), reminders: [] },
|
|
||||||
// { name: "Yann", role: roles.get("librarian"), reminders: [] },
|
|
||||||
// { name: "Marie", role: roles.get("empath"), reminders: [] },
|
|
||||||
// { name: "Bogdan", role: roles.get("scarletwoman"), reminders: [] },
|
|
||||||
// { name: "Sean", role: roles.get("recluse"), reminders: [] },
|
|
||||||
// { name: "Petra", role: roles.get("undertaker"), reminders: [] }
|
|
||||||
],
|
|
||||||
roles,
|
roles,
|
||||||
set: "TB"
|
set: "BMR"
|
||||||
}),
|
}),
|
||||||
methods: {
|
methods: {
|
||||||
togglePublic() {
|
togglePublic() {
|
||||||
|
@ -86,6 +74,9 @@ export default {
|
||||||
.map(a => a[1]);
|
.map(a => a[1]);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
clearPlayers() {
|
||||||
|
this.players = [];
|
||||||
|
},
|
||||||
keyup({ key }) {
|
keyup({ key }) {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case "g":
|
case "g":
|
||||||
|
@ -102,16 +93,29 @@ export default {
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
if (localStorage.players) {
|
if (localStorage.players) {
|
||||||
this.players = JSON.parse(localStorage.players);
|
this.players = JSON.parse(localStorage.players).map(player => ({
|
||||||
|
...player,
|
||||||
|
role: roles.get(player.role) || {}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
if (localStorage.set) {
|
||||||
|
this.set = localStorage.set;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
players: {
|
players: {
|
||||||
handler(newPlayers) {
|
handler(newPlayers) {
|
||||||
console.log("new player", newPlayers);
|
localStorage.players = JSON.stringify(
|
||||||
localStorage.players = JSON.stringify(newPlayers);
|
newPlayers.map(player => ({
|
||||||
|
...player,
|
||||||
|
role: player.role.id || {}
|
||||||
|
}))
|
||||||
|
);
|
||||||
},
|
},
|
||||||
deep: true
|
deep: true
|
||||||
|
},
|
||||||
|
set(newSet) {
|
||||||
|
localStorage.set = newSet;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<ul class="info">
|
<ul class="info">
|
||||||
|
<li class="set" v-bind:class="['set-' + set]"></li>
|
||||||
<li v-if="players.length < 5">Please add more players!</li>
|
<li v-if="players.length < 5">Please add more players!</li>
|
||||||
<li>
|
<li>
|
||||||
{{ players.length }} <font-awesome-icon class="players" icon="users" />
|
{{ players.length }} <font-awesome-icon class="players" icon="users" />
|
||||||
|
@ -43,6 +44,10 @@ export default {
|
||||||
players: {
|
players: {
|
||||||
type: Array,
|
type: Array,
|
||||||
required: true
|
required: true
|
||||||
|
},
|
||||||
|
set: {
|
||||||
|
type: String,
|
||||||
|
required: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
@ -79,7 +84,7 @@ export default {
|
||||||
height: 20%;
|
height: 20%;
|
||||||
margin-left: -10%;
|
margin-left: -10%;
|
||||||
margin-top: -5%;
|
margin-top: -5%;
|
||||||
padding: 0;
|
padding: 100px 0 0;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
align-content: center;
|
align-content: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
@ -125,5 +130,24 @@ export default {
|
||||||
color: $traveller;
|
color: $traveller;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
li.set {
|
||||||
|
width: 220px;
|
||||||
|
height: 200px;
|
||||||
|
background: 0 center no-repeat;
|
||||||
|
background-size: 100% auto;
|
||||||
|
position: absolute;
|
||||||
|
top: -50px;
|
||||||
|
|
||||||
|
&.set-TB {
|
||||||
|
background-image: url("../assets/set-tb.png");
|
||||||
|
}
|
||||||
|
&.set-BMR {
|
||||||
|
background-image: url("../assets/set-bmr.png");
|
||||||
|
}
|
||||||
|
&.set-SNV {
|
||||||
|
background-image: url("../assets/set-snv.png");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
Loading…
Reference in New Issue