From ca91112b2633ab06adff819ed636da510a21ff72 Mon Sep 17 00:00:00 2001 From: Steffen Date: Sun, 3 May 2020 23:05:17 +0200 Subject: [PATCH] further adjustments to store --- src/App.vue | 25 +-- src/components/Menu.vue | 28 +-- src/components/Player.vue | 11 +- src/components/Token.vue | 2 +- src/components/TownInfo.vue | 26 +-- src/components/TownSquare.vue | 209 ++++-------------- .../EditionModal.vue} | 14 +- src/components/{ => modals}/Modal.vue | 0 src/components/modals/ReminderModal.vue | 103 +++++++++ src/components/modals/RoleModal.vue | 103 +++++++++ .../RolesModal.vue} | 70 +++--- src/store/index.js | 10 +- src/store/modules/players.js | 52 ++++- src/store/persistence.js | 50 ++++- 14 files changed, 417 insertions(+), 286 deletions(-) rename src/components/{EditionSelectionModal.vue => modals/EditionModal.vue} (77%) rename src/components/{ => modals}/Modal.vue (100%) create mode 100644 src/components/modals/ReminderModal.vue create mode 100644 src/components/modals/RoleModal.vue rename src/components/{RoleSelectionModal.vue => modals/RolesModal.vue} (73%) diff --git a/src/App.vue b/src/App.vue index 927b9b9..41baadf 100644 --- a/src/App.vue +++ b/src/App.vue @@ -11,11 +11,11 @@ }" > - - - - - + + + + + @@ -24,26 +24,23 @@ import { mapState } from "vuex"; import TownSquare from "./components/TownSquare"; import TownInfo from "./components/TownInfo"; import Menu from "./components/Menu"; -import RoleSelectionModal from "./components/RoleSelectionModal"; -import EditionSelectionModal from "./components/EditionSelectionModal"; +import RolesModal from "./components/modals/RolesModal"; +import EditionModal from "./components/modals/EditionModal"; import Intro from "./components/Intro"; export default { components: { Intro, - EditionSelectionModal, - Menu, - TownSquare, TownInfo, - RoleSelectionModal + TownSquare, + Menu, + EditionModal, + RolesModal }, computed: mapState({ grimoire: state => state.grimoire, players: state => state.players.players }), - data: function() { - return {}; - }, methods: { takeScreenshot(dimensions) { this.$refs.menu.takeScreenshot(dimensions); diff --git a/src/components/Menu.vue b/src/components/Menu.vue index 6743e04..fd07d26 100644 --- a/src/components/Menu.vue +++ b/src/components/Menu.vue @@ -80,11 +80,10 @@ export default { components: { Screenshot }, - props: ["players"], - data: function() { - return {}; - }, - computed: mapState(["grimoire"]), + computed: mapState({ + grimoire: state => state.grimoire, + players: state => state.players.players + }), methods: { takeScreenshot(dimensions = {}) { this.$store.commit("updateScreenshot"); @@ -99,34 +98,23 @@ export default { addPlayer() { const name = prompt("Player name"); if (name) { - this.players.push({ - name, - role: {}, - reminders: [] - }); + this.$store.commit("players/add", name); } }, randomizeSeatings() { if (confirm("Are you sure you want to randomize seatings?")) { - this.players = this.players - .map(a => [Math.random(), a]) - .sort((a, b) => a[0] - b[0]) - .map(a => a[1]); + this.$store.dispatch("players/randomize"); } }, clearPlayers() { if (confirm("Are you sure you want to remove all players?")) { - this.players = []; + this.$store.commit("players/clear"); } }, clearRoles() { this.$store.commit("showGrimoire"); if (confirm("Are you sure you want to remove all player roles?")) { - this.players.forEach(player => { - player.role = {}; - player.hasDied = false; - player.reminders = []; - }); + this.$store.dispatch("players/clearRoles"); } }, ...mapMutations([ diff --git a/src/components/Player.vue b/src/components/Player.vue index b1c00c6..243c1c2 100644 --- a/src/components/Player.vue +++ b/src/components/Player.vue @@ -31,7 +31,7 @@ }} - +
@@ -40,7 +40,7 @@ {{ player.name }} - +
@@ -64,7 +64,7 @@ {{ reminder.name }} -
+
@@ -97,7 +97,7 @@ export default { this.$emit("screenshot", { width, height, x, y }); }, toggleStatus() { - if (this.$store.state.grimoire.isPublic) { + if (this.grimoire.isPublic) { if (!this.player.hasDied) { this.$set(this.player, "hasDied", true); } else if (this.player.hasVoted) { @@ -110,9 +110,6 @@ export default { this.$set(this.player, "hasDied", !this.player.hasDied); } }, - setRole() { - this.$emit("set-role", this.player); - }, changeName() { const name = prompt("Player name", this.player.name); this.player.name = name || this.player.name; diff --git a/src/components/Token.vue b/src/components/Token.vue index ee34579..00ae2e8 100644 --- a/src/components/Token.vue +++ b/src/components/Token.vue @@ -50,7 +50,7 @@ export default { props: { role: { type: Object, - required: true + default: () => ({}) } }, data() { diff --git a/src/components/TownInfo.vue b/src/components/TownInfo.vue index bd648f3..f1a737e 100644 --- a/src/components/TownInfo.vue +++ b/src/components/TownInfo.vue @@ -43,32 +43,26 @@ import gameJSON from "./../game"; import { mapState } from "vuex"; export default { - props: { - players: { - type: Array, - required: true - } - }, computed: { teams: function() { - const nontravelers = Math.min( - this.players.filter(player => player.role.team !== "traveler").length, - 15 - ); - const alive = this.players.filter(player => player.hasDied !== true) - .length; + const { players } = this.$store.state.players; + const nonTravelers = this.$store.getters["players/nonTravelers"]; + const alive = players.filter(player => player.hasDied !== true).length; return { - ...gameJSON[nontravelers - 5], - traveler: this.players.length - nontravelers, + ...gameJSON[nonTravelers - 5], + traveler: players.length - nonTravelers, alive, votes: alive + - this.players.filter( + players.filter( player => player.hasDied === true && player.hasVoted !== true ).length }; }, - ...mapState(["edition"]) + ...mapState({ + edition: state => state.edition, + players: state => state.players.players + }) } }; diff --git a/src/components/TownSquare.vue b/src/components/TownSquare.vue index cdfe6e1..6e5f56c 100644 --- a/src/components/TownSquare.vue +++ b/src/components/TownSquare.vue @@ -10,97 +10,54 @@ v-for="(player, index) in players" :key="index" :player="player" - @add-reminder="openReminderModal" - @set-role="openRoleModal" - @remove-player="removePlayer" + @add-reminder="openReminderModal(index)" + @set-role="openRoleModal(index)" + @remove-player="removePlayer(index)" @screenshot="$emit('screenshot', $event)" > +

Demon bluffs

    -
  • - -
  • -
  • - -
  • -
  • - +
  • +
- -

Choose a reminder token:

-
    -
  • - - {{ reminder.name }} -
  • -
-
- - -

Choose a new character:

-
    -
  • - -
  • -
-
+ +
diff --git a/src/components/EditionSelectionModal.vue b/src/components/modals/EditionModal.vue similarity index 77% rename from src/components/EditionSelectionModal.vue rename to src/components/modals/EditionModal.vue index cc9df71..b2c777b 100644 --- a/src/components/EditionSelectionModal.vue +++ b/src/components/modals/EditionModal.vue @@ -20,7 +20,7 @@ diff --git a/src/components/modals/RoleModal.vue b/src/components/modals/RoleModal.vue new file mode 100644 index 0000000..903189c --- /dev/null +++ b/src/components/modals/RoleModal.vue @@ -0,0 +1,103 @@ + + + + + diff --git a/src/components/RoleSelectionModal.vue b/src/components/modals/RolesModal.vue similarity index 73% rename from src/components/RoleSelectionModal.vue rename to src/components/modals/RolesModal.vue index 26d9822..f4a8ea9 100644 --- a/src/components/RoleSelectionModal.vue +++ b/src/components/modals/RolesModal.vue @@ -3,9 +3,9 @@ class="roles" v-show="modals.roles" @close="toggleModal('roles')" - v-if="nontravelerPlayers >= 5" + v-if="nonTravelers >= 5" > -

Select the characters for {{ nontravelerPlayers }} players:

+

Select the characters for {{ nonTravelers }} players:

  • {{ teamRoles.filter(role => role.selected).length }} / - {{ game[nontravelerPlayers - 5][team] }} + {{ game[nonTravelers - 5][team] }}
  • @@ -49,9 +49,9 @@ -