-
-
Notifications
You must be signed in to change notification settings - Fork 243
/
Copy pathReminderModal.vue
160 lines (150 loc) · 4.33 KB
/
ReminderModal.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<template>
<Modal
v-if="modals.reminder && availableReminders.length && players[playerIndex]"
@close="toggleModal('reminder')"
>
<h3>Choose a reminder token:</h3>
<ul class="reminders">
<li
v-for="reminder in availableReminders"
class="reminder"
:class="[reminder.role]"
:key="reminder.role + ' ' + reminder.name"
@click="addReminder(reminder)"
>
<span
class="icon"
:style="{
backgroundImage: `url(${
reminder.image && grimoire.isImageOptIn
? reminder.image
: require('../../assets/icons/' +
(reminder.imageAlt || reminder.role) +
'.png')
})`
}"
></span>
<span class="text">{{ reminder.name }}</span>
</li>
</ul>
</Modal>
</template>
<script>
import Modal from "./Modal";
import { mapMutations, mapState } from "vuex";
/**
* Helper function that maps a reminder name with a role-based object that provides necessary visual data.
* @param role The role for which the reminder should be generated
* @return {function(*): {image: string|string[]|string|*, role: *, name: *, imageAlt: string|*}}
*/
const mapReminder = ({ id, image, imageAlt }) => name => ({
role: id,
image,
imageAlt,
name
});
export default {
components: { Modal },
props: ["playerIndex"],
computed: {
availableReminders() {
let reminders = [];
const { players, bluffs } = this.$store.state.players;
this.$store.state.roles.forEach(role => {
// add reminders from player roles
if (players.some(p => p.role.id === role.id)) {
reminders = [...reminders, ...role.reminders.map(mapReminder(role))];
}
// add reminders from bluff/other roles
else if (bluffs.some(bluff => bluff.id === role.id)) {
reminders = [...reminders, ...role.reminders.map(mapReminder(role))];
}
// add global reminders
if (role.remindersGlobal && role.remindersGlobal.length) {
reminders = [
...reminders,
...role.remindersGlobal.map(mapReminder(role))
];
}
});
// add fabled reminders
this.$store.state.players.fabled.forEach(role => {
reminders = [...reminders, ...role.reminders.map(mapReminder(role))];
});
// add out of script traveler reminders
this.$store.state.otherTravelers.forEach(role => {
if (players.some(p => p.role.id === role.id)) {
reminders = [...reminders, ...role.reminders.map(mapReminder(role))];
}
});
reminders.push({ role: "good", name: "Good" });
reminders.push({ role: "evil", name: "Evil" });
reminders.push({ role: "custom", name: "Custom note" });
return reminders;
},
...mapState(["modals", "grimoire"]),
...mapState("players", ["players"])
},
methods: {
addReminder(reminder) {
const player = this.$store.state.players.players[this.playerIndex];
let value;
if (reminder.role === "custom") {
const name = prompt("Add a custom reminder note");
if (!name) return;
value = [...player.reminders, { role: "custom", name }];
} else {
value = [...player.reminders, reminder];
}
this.$store.commit("players/update", {
player,
property: "reminders",
value
});
this.$store.commit("toggleModal", "reminder");
},
...mapMutations(["toggleModal"])
}
};
</script>
<style scoped lang="scss">
ul.reminders .reminder {
background: url("../../assets/reminder.png") center center;
background-size: 100%;
width: 14vh;
height: 14vh;
max-width: 100px;
max-height: 100px;
display: flex;
justify-content: center;
align-items: center;
margin: 1%;
border-radius: 50%;
border: 3px solid black;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
cursor: pointer;
line-height: 100%;
transition: transform 500ms ease;
.icon {
position: absolute;
top: 0;
width: 90%;
height: 90%;
background-size: 100%;
background-position: center center;
background-repeat: no-repeat;
}
.text {
color: black;
font-size: 65%;
font-weight: bold;
text-align: center;
top: 28%;
width: 80%;
line-height: 1;
}
&:hover {
transform: scale(1.2);
}
}
</style>