added role selection

This commit is contained in:
Steffen 2020-04-04 17:06:45 +02:00
parent 7f5ae5f8e5
commit dae4c6465e
No known key found for this signature in database
GPG Key ID: 764D74E98267DFC6
4 changed files with 104 additions and 30 deletions

View File

@ -43,7 +43,7 @@
overflow-x: auto; overflow-x: auto;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
max-width: 70%; max-width: 60%;
} }
.modal-fade-enter, .modal-fade-enter,

View File

@ -3,14 +3,14 @@
<div class="player" <div class="player"
:class="{ dead: player.hasDied, 'no-vote': player.hasVoted }"> :class="{ dead: player.hasDied, 'no-vote': player.hasVoted }">
<div class="shroud" @click="toggleStatus()"></div> <div class="shroud" @click="toggleStatus()"></div>
<div class="token" @click="changeRole()" :class="[player.role]"> <div class="token" @click="changeRole()" :class="[player.role.id]">
<span class="leaf-left" v-if="role.firstNight"></span> <span class="leaf-left" v-if="player.role.firstNight"></span>
<span class="leaf-right" v-if="role.otherNight"></span> <span class="leaf-right" v-if="player.role.otherNight"></span>
<span v-if="role.reminders.length" v-bind:class="['leaf-top' + role.reminders.length]"></span> <span v-if="player.role.reminders.length" v-bind:class="['leaf-top' + player.role.reminders.length]"></span>
<span class="leaf-orange" v-if="role.setup"></span> <span class="leaf-orange" v-if="player.role.setup"></span>
<div>{{ role.name }}</div> <div>{{ player.role.name }}</div>
</div> </div>
<div class="ability" v-if="role.ability">{{ role.ability }}</div> <div class="ability" v-if="player.role.ability">{{ player.role.ability }}</div>
<div class="name">{{ player.name }}</div> <div class="name">{{ player.name }}</div>
</div> </div>
<div class="reminder" <div class="reminder"
@ -39,9 +39,7 @@
} }
}, },
data () { data () {
return { return {}
role: this.roles.get(this.player.role) || { reminders: [] }
}
}, },
methods: { methods: {
toggleStatus () { toggleStatus () {
@ -56,7 +54,7 @@
}, },
changeRole () { changeRole () {
if (!this.isPublic) { if (!this.isPublic) {
console.log('role change'); this.$emit('set-role', this.player);
} else { } else {
this.toggleStatus(); this.toggleStatus();
} }

View File

@ -8,6 +8,7 @@
:roles="roles" :roles="roles"
:is-public="isPublic" :is-public="isPublic"
@add-reminder="openReminderModal" @add-reminder="openReminderModal"
@set-role="openRoleModal"
></Player> ></Player>
</ul> </ul>
<Modal v-show="availableReminders.length" @close="closeModal"> <Modal v-show="availableReminders.length" @close="closeModal">
@ -19,14 +20,25 @@
</li> </li>
</ul> </ul>
</Modal> </Modal>
<Modal v-show="availableRoles.length" @close="closeModal">
<ul class="tokens">
<li v-for="role in availableRoles" class="token"
v-bind:class="[role.id, role.team]"
@click="setRole(role)">
{{ role.name }}
</li>
</ul>
</Modal>
</div> </div>
</template> </template>
<script> <script>
import roles from '../roles.json' import rolesJSON from '../roles.json'
import Player from './Player' import Player from './Player'
import Modal from "./Modal"; import Modal from "./Modal";
const roles = new Map(rolesJSON.sort((a, b) => b.team.localeCompare(a.team)).map(role => [role.id, role]));
export default { export default {
components: { components: {
Modal, Modal,
@ -36,18 +48,18 @@
data () { data () {
return { return {
players: [ players: [
{ name: "Steffen", role: "baron", reminders: [{ role: 'imp', name: 'Die' }] }, { name: "Steffen", role: roles.get('baron'), reminders: [{ role: 'imp', name: 'Die' }] },
{ name: "Tino", role: "imp" }, { name: "Tino", role: roles.get("imp") },
{ name: "Basti", role: "chef", reminders: [] }, { name: "Basti", role: roles.get("chef"), reminders: [] },
{ name: "Bernd", role: "ravenkeeper", reminders: [] }, { name: "Bernd", role: roles.get("ravenkeeper"), reminders: [] },
{ name: "Tim", role: "drunk", reminders: [] }, { name: "Tim", role: roles.get("drunk"), reminders: [] },
{ name: "Yann", role: "librarian", reminders: [] }, { name: "Yann", role: roles.get("librarian"), reminders: [] },
{ name: "Marie", role: "empath", reminders: [] }, { name: "Marie", role: roles.get("empath"), reminders: [] },
{ name: "Bogdan", role: "scarletwoman", reminders: [] }, { name: "Bogdan", role: roles.get("scarletwoman"), reminders: [] },
{ name: "Sean", role: "recluse", reminders: [] }, { name: "Sean", role: roles.get("recluse"), reminders: [] },
{ name: "Petra", role: "undertaker", reminders: [] }, { name: "Petra", role: roles.get("undertaker"), reminders: [] },
], ],
roles: new Map(roles.map(role => [role.id, role])), roles,
selectedPlayer: false, selectedPlayer: false,
availableReminders: [], availableReminders: [],
availableRoles: [], availableRoles: [],
@ -58,19 +70,31 @@
this.selectedPlayer = player; this.selectedPlayer = player;
this.availableReminders = []; this.availableReminders = [];
this.roles.forEach(role => { this.roles.forEach(role => {
if (this.players.some(p => p.role === role.id)) { if (this.players.some(p => p.role.id === role.id)) {
this.availableReminders = [ this.availableReminders = [
...this.availableReminders, ...this.availableReminders,
...role.reminders.map(name => ({role: role.id, name})) ...role.reminders.map(name => ({role: role.id, name}))
]; ];
} }
}); });
console.log('open', player.reminders); },
openRoleModal (player) {
this.selectedPlayer = player;
this.availableRoles = [];
this.roles.forEach(role => {
if(role.id !== player.role) {
this.availableRoles.push(role);
}
});
}, },
addReminder (reminder) { addReminder (reminder) {
this.selectedPlayer.reminders.push(reminder); this.selectedPlayer.reminders.push(reminder);
this.closeModal(); this.closeModal();
}, },
setRole (role) {
this.selectedPlayer.role = role;
this.closeModal();
},
closeModal () { closeModal () {
this.selectedPlayer = false; this.selectedPlayer = false;
this.availableReminders = []; this.availableReminders = [];
@ -166,8 +190,8 @@
background-image: url('../assets/demon-head.png'); background-image: url('../assets/demon-head.png');
} }
/***** Reminder token modal ******/ /***** Role token modal ******/
ul.reminders { ul.tokens {
list-style-type: none; list-style-type: none;
margin: 0; margin: 0;
padding: 0; padding: 0;
@ -177,6 +201,58 @@
align-items: center; align-items: center;
overflow: hidden; overflow: hidden;
justify-content: center; justify-content: center;
font-size: 75%;
line-height: 100%;
.token {
border-radius: 50%;
height: 120px;
width: 120px;
background: url('../assets/token.png') center center;
background-size: 100%;
text-align: center;
position: relative;
color: black;
margin: 5px;
font-weight: 600;
text-shadow:
-1px -1px 0 #fff,
1px -1px 0 #fff,
-1px 1px 0 #fff,
1px 1px 0 #fff,
0 0 5px rgba(0,0,0,0.75);
padding-top: 85px;
box-sizing: border-box;
font-family: 'Papyrus', serif;
border: 3px solid black;
box-shadow: 0 0 10px rgba(0,0,0,0.5);
cursor: pointer;
transition: transform 500ms ease;
&.townsfolk { box-shadow: 0 0 10px #004cff, 0 0 10px #004cff; }
&.outsider { box-shadow: 0 0 10px #00D6FF, 0 0 10px #00d6ff; }
&.minion { box-shadow: 0 0 10px #ff6900, 0 0 10px #ff6900; }
&.demon { box-shadow: 0 0 10px #ff0000, 0 0 10px #ff0000; }
&:before {
content: " ";
background-size: 100%;
position: absolute;
width: 100%;
height: 100%;
left: 0;
top: 0;
}
&:hover {
transform: scale(1.2);
}
}
}
/***** Reminder token modal ******/
ul.reminders {
@extend .tokens;
.reminder { .reminder {
background: url('../assets/reminder.png') center center; background: url('../assets/reminder.png') center center;

View File

@ -4,7 +4,7 @@ $roles:
'chef', 'chef',
'drunk', 'drunk',
'empath', 'empath',
'fortuneteller', 'fortuneteller' 80%,
'imp', 'imp',
'investigator', 'investigator',
'librarian', 'librarian',
@ -17,7 +17,7 @@ $roles:
'slayer', 'slayer',
'soldier', 'soldier',
'spy', 'spy',
'scarletwoman' 80%, 'scarletwoman' 75%,
'undertaker' 85%, 'undertaker' 85%,
'virgin', 'virgin',
'washerwoman' 75%; 'washerwoman' 75%;