townsquare/src/components/TownSquare.vue

364 lines
7.8 KiB
Vue
Raw Normal View History

2020-04-01 22:57:14 +02:00
<template>
<div
id="townsquare"
class="square"
v-bind:class="{
public: grimoire.isPublic,
2020-06-03 22:25:23 +02:00
spectator: session.isSpectator,
vote: session.nomination
}"
>
<ul class="circle" v-bind:class="['size-' + players.length]">
<Player
2020-04-05 21:50:06 +02:00
v-for="(player, index) in players"
:key="index"
2020-04-05 19:50:33 +02:00
:player="player"
2020-04-19 22:54:25 +02:00
@screenshot="$emit('screenshot', $event)"
2020-05-31 00:18:31 +02:00
@trigger="handleTrigger(index, $event)"
2020-05-12 22:22:36 +02:00
v-bind:class="{
2020-05-19 15:19:19 +02:00
from: Math.max(swap, move, nominate) === index,
swap: swap > -1,
move: move > -1,
nominate: nominate > -1
2020-05-12 22:22:36 +02:00
}"
></Player>
</ul>
2020-05-03 23:05:17 +02:00
<div
class="bluffs"
v-if="players.length > 6"
ref="bluffs"
:class="{ closed: !isBluffsOpen }"
>
<h3>
<font-awesome-icon icon="camera" @click.stop="takeScreenshot" />
<span v-if="session.isSpectator">Other characters</span>
<span v-else>Demon bluffs</span>
<font-awesome-icon icon="times-circle" @click.stop="toggleBluffs" />
<font-awesome-icon icon="plus-circle" @click.stop="toggleBluffs" />
</h3>
2020-04-18 21:03:58 +02:00
<ul>
2020-04-05 19:50:33 +02:00
<li
2020-05-03 23:05:17 +02:00
v-for="index in bluffs"
:key="index"
@click="openRoleModal(index * -1)"
2020-04-05 19:50:33 +02:00
>
2020-05-03 23:05:17 +02:00
<Token :role="grimoire.bluffs[index - 1]"></Token>
</li>
</ul>
2020-05-03 23:05:17 +02:00
</div>
2020-05-02 21:33:44 +02:00
2020-05-03 23:05:17 +02:00
<ReminderModal :player-index="selectedPlayer"></ReminderModal>
<RoleModal :player-index="selectedPlayer"></RoleModal>
</div>
2020-04-01 22:57:14 +02:00
</template>
<script>
2020-05-03 23:05:17 +02:00
import { mapState } from "vuex";
2020-04-05 19:50:33 +02:00
import Player from "./Player";
import Token from "./Token";
2020-05-03 23:05:17 +02:00
import ReminderModal from "./modals/ReminderModal";
import RoleModal from "./modals/RoleModal";
2020-04-01 22:57:14 +02:00
2020-04-05 19:50:33 +02:00
export default {
components: {
2020-05-03 23:05:17 +02:00
Player,
Token,
2020-05-03 23:05:17 +02:00
RoleModal,
ReminderModal
2020-04-05 19:50:33 +02:00
},
2020-05-03 23:05:17 +02:00
computed: {
...mapState(["grimoire", "roles", "session"]),
2020-05-03 23:05:17 +02:00
...mapState("players", ["players"])
},
2020-04-05 19:50:33 +02:00
data() {
return {
2020-05-03 23:05:17 +02:00
selectedPlayer: 0,
2020-05-12 22:22:36 +02:00
bluffs: 3,
2020-05-19 15:19:19 +02:00
swap: -1,
move: -1,
nominate: -1,
isBluffsOpen: true
2020-04-05 19:50:33 +02:00
};
},
methods: {
2020-04-19 22:54:25 +02:00
takeScreenshot() {
const { width, height, x, y } = this.$refs.bluffs.getBoundingClientRect();
this.$emit("screenshot", { width, height, x, y });
},
toggleBluffs() {
this.isBluffsOpen = !this.isBluffsOpen;
},
2020-05-31 00:18:31 +02:00
handleTrigger(playerIndex, [method, params]) {
if (typeof this[method] === "function") {
this[method](playerIndex, params);
}
},
claimSeat(playerIndex) {
if (!this.session.isSpectator) return;
if (this.session.playerId === this.players[playerIndex].id) {
this.$store.commit("session/claimSeat", -1);
} else {
this.$store.commit("session/claimSeat", playerIndex);
}
},
2020-05-03 23:05:17 +02:00
openReminderModal(playerIndex) {
this.selectedPlayer = playerIndex;
this.$store.commit("toggleModal", "reminder");
2020-04-05 19:50:33 +02:00
},
2020-05-03 23:05:17 +02:00
openRoleModal(playerIndex) {
const player = this.players[playerIndex];
if (this.session.isSpectator && player && player.role.team === "traveler")
return;
2020-05-03 23:05:17 +02:00
this.selectedPlayer = playerIndex;
this.$store.commit("toggleModal", "role");
},
2020-05-03 23:05:17 +02:00
removePlayer(playerIndex) {
if (this.session.isSpectator) return;
2020-05-03 23:05:17 +02:00
if (
confirm(
`Do you really want to remove ${this.players[playerIndex].name}?`
)
) {
this.$store.commit("players/remove", playerIndex);
}
2020-05-12 22:22:36 +02:00
},
2020-05-19 15:19:19 +02:00
swapPlayer(from, to) {
2020-05-12 22:22:36 +02:00
if (to === undefined) {
2020-05-19 15:19:19 +02:00
this.cancel();
this.swap = from;
2020-05-12 22:22:36 +02:00
} else {
this.$store.commit("players/swap", [
2020-05-19 15:19:19 +02:00
this.swap,
2020-05-12 22:22:36 +02:00
this.players.indexOf(to)
]);
2020-05-19 15:19:19 +02:00
this.cancel();
2020-05-12 22:22:36 +02:00
}
2020-05-19 15:19:19 +02:00
},
movePlayer(from, to) {
if (to === undefined) {
this.cancel();
this.move = from;
} else {
this.$store.commit("players/move", [
this.move,
this.players.indexOf(to)
]);
this.cancel();
}
},
2020-05-31 23:42:08 +02:00
nominatePlayer(from, to) {
2020-06-05 22:46:54 +02:00
if (to === undefined) {
2020-05-31 23:42:08 +02:00
this.cancel();
if (from !== this.nominate) {
this.nominate = from;
}
} else {
this.$store.commit("session/nomination", [
this.nominate,
this.players.indexOf(to)
]);
this.cancel();
}
},
2020-05-19 15:19:19 +02:00
cancel() {
this.move = -1;
this.swap = -1;
this.nominate = -1;
2020-04-01 22:57:14 +02:00
}
}
2020-04-05 19:50:33 +02:00
};
2020-04-01 22:57:14 +02:00
</script>
<style lang="scss">
2020-06-11 00:37:17 +02:00
#townsquare {
width: 100%;
height: 100%;
padding: 20px;
display: flex;
align-items: center;
align-content: center;
justify-content: center;
}
2020-04-05 19:50:33 +02:00
.circle {
padding: 0;
width: 100%;
height: 100%;
list-style: none;
margin: 0;
2020-04-01 22:57:14 +02:00
2020-05-12 22:22:36 +02:00
> li {
2020-04-05 19:50:33 +02:00
position: absolute;
left: 50%;
height: 50%;
transform-origin: 0 100%;
pointer-events: none;
2020-04-02 22:23:40 +02:00
2020-04-05 19:50:33 +02:00
&:hover {
z-index: 25 !important;
2020-04-01 22:57:14 +02:00
}
2020-06-07 23:43:26 +02:00
> .player {
margin-left: -50%;
width: 100%;
pointer-events: all;
2020-06-07 23:43:26 +02:00
}
> .reminder {
margin-left: -25%;
width: 50%;
pointer-events: all;
2020-04-02 22:23:40 +02:00
}
}
2020-04-05 19:50:33 +02:00
}
2020-04-01 22:57:14 +02:00
2020-04-05 21:50:06 +02:00
@mixin on-circle($item-count) {
$angle: (360 / $item-count);
$rot: 0;
// rotation and tooltip placement
2020-04-05 21:50:06 +02:00
@for $i from 1 through $item-count {
&:nth-child(#{$i}) {
transform: rotate($rot * 1deg);
@if $i - 1 <= $item-count / 2 {
z-index: $item-count - $i + 1;
} @else {
z-index: $i - 1;
2020-04-25 22:19:47 +02:00
.ability {
2020-04-22 23:07:25 +02:00
right: 120%;
left: auto;
2020-04-18 20:21:26 +02:00
&:before {
border-right-color: transparent;
border-left-color: black;
right: auto;
left: 100%;
2020-04-05 21:50:06 +02:00
}
}
}
> * {
transform: rotate($rot * -1deg);
}
// animation cascade
2020-04-08 22:42:51 +02:00
.life,
2020-04-10 11:21:27 +02:00
.token,
2020-04-22 23:07:25 +02:00
.shroud,
.night {
2020-04-10 11:21:27 +02:00
transition-delay: ($i - 1) * 50ms;
2020-04-08 21:30:55 +02:00
}
2020-04-22 21:21:54 +02:00
// move reminders closer to the sides of the circle
$q: $item-count / 4;
$x: $i - 1;
@if $x < $q or ($x >= $item-count / 2 and $x < $q * 3) {
.player {
2020-06-11 00:37:17 +02:00
margin-bottom: -10% + 20% * (1 - ($x % $q / $q));
2020-04-22 21:21:54 +02:00
}
} @else {
.player {
2020-06-11 00:37:17 +02:00
margin-bottom: -10% + 20% * ($x % $q / $q);
2020-04-22 21:21:54 +02:00
}
}
2020-04-05 21:50:06 +02:00
}
$rot: $rot + $angle;
}
}
@for $i from 1 through 20 {
2020-05-12 22:22:36 +02:00
.circle.size-#{$i} > li {
2020-04-05 19:50:33 +02:00
@include on-circle($item-count: $i);
}
2020-04-05 19:50:33 +02:00
}
2020-04-18 21:03:58 +02:00
/***** Demon bluffs *******/
.bluffs {
position: absolute;
bottom: 10px;
left: 10px;
background: rgba(0, 0, 0, 0.5);
border-radius: 10px;
border: 3px solid black;
filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.5));
transform-origin: bottom left;
transform: scale(1);
opacity: 1;
transition: all 200ms ease-in-out;
2020-04-22 21:21:54 +02:00
#townsquare.public & {
opacity: 0;
transform: scale(0.1);
}
2020-04-19 22:54:25 +02:00
> svg {
position: absolute;
top: 10px;
right: 10px;
cursor: pointer;
&:hover {
color: red;
}
2020-04-22 21:21:54 +02:00
#app.screenshot & {
display: none;
}
2020-04-19 22:54:25 +02:00
}
2020-04-18 21:03:58 +02:00
h3 {
margin: 5px 1vh 0;
display: flex;
align-items: center;
align-content: center;
justify-content: center;
span {
flex-grow: 1;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
svg {
cursor: pointer;
flex-grow: 0;
&.fa-camera {
margin-right: 1vh;
}
&.fa-times-circle {
margin-left: 1vh;
}
&.fa-plus-circle {
margin-left: 1vh;
display: none;
}
&:hover path {
fill: url(#demon);
stroke-width: 30px;
stroke: white;
}
}
2020-04-18 21:03:58 +02:00
}
2020-06-11 00:37:17 +02:00
ul {
display: flex;
align-items: center;
justify-content: center;
2020-06-11 00:37:17 +02:00
li {
width: 14vh;
height: 14vh;
margin: 0 0.5%;
display: inline-block;
transition: all 250ms;
}
}
&.closed {
svg.fa-camera {
display: none;
}
svg.fa-times-circle {
display: none;
}
svg.fa-plus-circle {
display: block;
}
ul li {
width: 0;
height: 0;
2020-06-11 00:37:17 +02:00
}
2020-04-18 21:03:58 +02:00
}
}
2020-04-01 22:57:14 +02:00
</style>