Skip to content

Commit

Permalink
refactor(GameLobby): Dedicated popover for explaining game start cond…
Browse files Browse the repository at this point in the history
…itions. Closes #71
  • Loading branch information
antoinezanardi committed Nov 21, 2020
1 parent 6e32b39 commit 467208f
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 33 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
### ♻️ Refactoring

* [#66](https://github.com/antoinezanardi/werewolves-assistant-web/issues/66) - `SubmitButton` component uses default template for button inner text.
* [#71](https://github.com/antoinezanardi/werewolves-assistant-web/issues/71) - Dedicated popover for explaining game start conditions.

### 📦 Packages

Expand All @@ -24,6 +25,7 @@
* `@vue/cli-plugin-unit-mocha` updated to version `4.5.9`.
* `@vue/cli-plugin-vuex` updated to version `4.5.9`.
* `@vue/cli-service` updated to version `4.5.9`.
* `eslint` updated to version `7.14.0`.
* `sweetalert2` updated to version `10.10.1`.
* `vee-validate` updated to version `3.4.5`.
* `vee-i18n` updated to version `8.22.2`.
Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"@vue/eslint-config-airbnb": "^5.1.0",
"@vue/test-utils": "^1.1.1",
"chai": "^4.1.2",
"eslint": "^7.13.0",
"eslint": "^7.14.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-vue": "^7.1.0",
"vue-template-compiler": "^2.6.12"
Expand Down
1 change: 1 addition & 0 deletions src/assets/scss/_v-tooltip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
$border-color: rgba(160, 160, 160, 0.56);
background-color: $border-color;
border-color: $border-color;
max-width: 450px !important;

.popover-inner {
background: $color;
Expand Down
2 changes: 1 addition & 1 deletion src/classes/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Game {
}

get allPlayersHaveRole() {
return !this.players.filter(player => player.role.current === undefined).length;
return this.players.length && !this.players.filter(player => player.role.current === undefined).length;
}

get canStartGame() {
Expand Down
30 changes: 12 additions & 18 deletions src/components/GameLobby/GameLobby.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,20 @@
</h3>
</div>
<transition-group v-else id="players" tag="div" name="fade-list"
class="row justify-content-center align-items-center flex-grow-1 visible-scrollbar py-2 mx-2ser">
class="row justify-content-center align-items-center flex-grow-1 visible-scrollbar py-2 mx-2">
<PlayerCard v-for="player in game.players" :key="player.name" :game="game" :player="player"
class="player-item col-lg-2 col-4" @choose-role="showRolePickerModal"
@unset-role="unsetRole" @unset-player="unsetPlayer"/>
</transition-group>
</transition>
</div>
<div>
<hr class="bg-dark"/>
<hr class="bg-dark my-2"/>
<div class="row justify-content-center align-items-center my-3">
<div class="col-12 text-center">
<GameLobbyStartConditions :game="game"/>
</div>
</div>
<div id="game-lobby-footer" class="row justify-content-between align-items-center">
<div class="col-lg-4 col-sm-6">
<form @submit.prevent="getGameRepartition">
Expand All @@ -79,8 +84,7 @@
<div class="col-lg-4 col-sm-6 mt-lg-0 mt-2 mt-sm-0">
<form @submit.prevent="createGame">
<SubmitButton classes="btn btn-primary btn-lg btn-block text-uppercase font-weight-bold"
:disabled-tooltip-text="createGameButtonDisabledText" :loading="loading.createGame"
:disabled="loading.getGameRepartition || !game.canStartGame">
:loading="loading.createGame" :disabled="loading.getGameRepartition || !game.canStartGame">
<i class="fa fa-play-circle mr-2"/>
<span v-html="$t('GameLobby.launchParty')"/>
</SubmitButton>
Expand Down Expand Up @@ -116,10 +120,12 @@ import GameLobbyTutorial from "@/components/GameLobby/GameLobbyTutorial";
import PlayerCard from "@/components/shared/Game/PlayerCard";
import { filterOutHTMLTags } from "@/helpers/functions/String";
import GameLobbyRolePickerModal from "@/components/GameLobby/GameLobbyRolePickerModal";
import GameLobbyStartConditions from "@/components/GameLobby/GameLobbyStartConditions";
export default {
name: "GameLobby",
components: {
GameLobbyStartConditions,
GameLobbyRolePickerModal,
PlayerCard,
GameLobbyTutorial,
Expand Down Expand Up @@ -158,19 +164,6 @@ export default {
playerNameInputPlaceholder() {
return this.game.isMaxPlayerReached ? this.$t("GameLobby.maxPlayerReached") : this.$t("GameLobby.playerName");
},
createGameButtonDisabledText() {
if (!this.game.areThereEnoughPlayers) {
const missingCount = 4 - this.game.players.length;
return this.$tc("GameLobby.missingPlayersToStart", missingCount, { missingCount });
} else if (!this.game.areThereEnoughWerewolves) {
return this.$t("GameLobby.missingOneWerewolfToStart");
} else if (!this.game.areThereEnoughVillagers) {
return this.$t("GameLobby.missingOneVillagerToStart");
} else if (!this.game.allPlayersHaveRole) {
return this.$t("GameLobby.allPlayerDontHaveARole");
}
return "";
},
sanitizedPlayerName() {
return filterOutHTMLTags(this.playerName.trim());
},
Expand Down Expand Up @@ -300,10 +293,11 @@ export default {
#players {
overflow-y: scroll;
overflow-x: hidden !important;
}
#player-name-input-error {
height: 45px;
height: 15px;
}
#game-lobby-players-container {
Expand Down
8 changes: 4 additions & 4 deletions src/components/GameLobby/GameLobbyComposition.vue
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<template>
<div id="game-lobby-composition" class="row">
<div class="col-md-4 text-center d-none d-md-block">
<div id="game-lobby-composition" class="row d-none d-md-flex">
<div class="col-md-4 text-center">
<span v-html="$tc('GameLobbyComposition.villagersCount', game.villagerPlayers.length, { count: game.villagerPlayers.length })"/>
<div class="text-muted font-italic">
<i class="fa mr-2" :class="villagersMinToStartIconClass"/>
<span v-html="$t('GameLobbyComposition.minToStart', { min: 1 })"/>
</div>
</div>
<div class="col-md-4 text-center d-none d-md-block">
<div class="col-md-4 text-center">
<span class="font-weight-bold"
v-html="$tc('GameLobbyComposition.playerCount', game.players.length, { count: game.players.length })"/>
<div class="text-muted font-italic">
<i class="fa mr-2" :class="playersMinToStartIconClass"/>
<span v-html="$t('GameLobbyComposition.minToStart', { min: 4 })"/>
</div>
</div>
<div class="col-md-4 text-center d-none d-md-block">
<div class="col-md-4 text-center">
<span v-html="$tc('GameLobbyComposition.werewolvesCount', game.werewolfPlayers.length, { count: game.werewolfPlayers.length })"/>
<div class="text-muted font-italic">
<i class="fa mr-2" :class="werewolvesMinToStartIconClass"/>
Expand Down
73 changes: 73 additions & 0 deletions src/components/GameLobby/GameLobbyStartConditions.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<template>
<transition name="fade" mode="out-in">
<div id="game-lobby-start-conditions" :key="canStartGameText">
<div class="animate__animated animate__pulse animate__repeat-2 d-flex justify-content-center align-items-center">
<i :class="conditionIcon(game.canStartGame)" class="mr-2"/>
<div class="mr-2 font-weight-bold" v-html="canStartGameText"/>
<div>
<v-popover class="d-inline" :disabled="game.canStartGame">
<WhatToDoButton v-if="!game.canStartGame"/>
<template #popover>
<div v-for="(condition, index) in conditions" :key="condition.text">
<div class="d-flex align-items-center">
<i class="mx-3 condition-icon" :class="conditionIcon(condition.isMet)"/>
<span v-html="condition.text"/>
</div>
<hr v-if="index + 1 !== conditions.length" class="bg-secondary my-2"/>
</div>
</template>
</v-popover>
</div>
</div>
</div>
</transition>
</template>

<script>
import Game from "@/classes/Game";
import WhatToDoButton from "@/components/shared/Game/WhatToDoButton/WhatToDoButton";
export default {
name: "GameLobbyStartConditions",
components: { WhatToDoButton },
props: {
game: {
type: Game,
required: true,
},
},
computed: {
canStartGameText() {
return this.game.canStartGame ? this.$t("GameLobbyStartConditions.gameCanStart") : this.$t("GameLobbyStartConditions.gameCannotStart");
},
conditions() {
return [
{ text: this.$t("GameLobbyStartConditions.gameHasMinimumFourPlayers"), isMet: this.game.areThereEnoughPlayers },
{ text: this.$t("GameLobbyStartConditions.allPlayersMustHaveARole"), isMet: this.game.allPlayersHaveRole },
{ text: this.$t("GameLobbyStartConditions.gameHasMinimumOneVillager"), isMet: this.game.areThereEnoughVillagers },
{ text: this.$t("GameLobbyStartConditions.gameHasMinimumOneWerewolf"), isMet: this.game.areThereEnoughWerewolves },
];
},
},
methods: {
conditionIcon(isMet) {
return isMet ? "fa fa-check text-success" : "fa fa-times text-danger";
},
},
};
</script>

<style lang="scss" scoped>
@import "../../../node_modules/bootstrap/scss/bootstrap-grid";
#game-lobby-start-conditions {
font-size: 1rem;
@include media-breakpoint-up(md) {
font-size: 1.15rem;
}
}
.condition-icon {
font-size: 1.35rem;
}
</style>
8 changes: 8 additions & 0 deletions src/plugins/vue-i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@
"minToStart": "Minimum {min} pour commencer",
"minPlayerRequirementsToStart": "Minimum 4 joueurs avec un rôle pour commencer dont 1 loup-garou et 1 villageois"
},
"GameLobbyStartConditions": {
"gameCanStart": "La partie peut commencer !",
"gameCannotStart": "Toutes les conditions ne sont pas réunies pour commencer une partie",
"gameHasMinimumFourPlayers": "La partie possède au minimum 4 joueurs.",
"allPlayersMustHaveARole": "Tous les joueurs doivent avoir un rôle.",
"gameHasMinimumOneVillager": "La partie possède au minimum 1 joueur dans le camp des villageois.",
"gameHasMinimumOneWerewolf": "La partie possède au minimum 1 joueur dans le camp des loups-garous."
},
"GameLobbyRolePickerModal": {
"noRole": "Aucun rôle",
"pickRoleFor": "Choisir un rôle pour",
Expand Down

0 comments on commit 467208f

Please sign in to comment.