From a028cf867fb7962c8c46efeade6c46c81bef7ef0 Mon Sep 17 00:00:00 2001 From: Steffen Date: Fri, 8 May 2020 19:33:29 +0200 Subject: [PATCH] menu added, session plugin created --- src/components/Menu.vue | 40 ++++++++++++++++++++++++++++++++++++---- src/store/index.js | 9 +++++++-- src/store/session.js | 8 ++++++++ 3 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 src/store/session.js diff --git a/src/components/Menu.vue b/src/components/Menu.vue index 39ad9ee..24c4794 100644 --- a/src/components/Menu.vue +++ b/src/components/Menu.vue @@ -37,6 +37,16 @@
  • Background image
  • +
  • + Host Live Session +
  • +
  • + Join Live Session +
  • +
  • + {{ grimoire.sessionId.substr(2) }} + Leave Session +
  • @@ -80,10 +90,10 @@ export default { components: { Screenshot }, - computed: mapState({ - grimoire: state => state.grimoire, - players: state => state.players.players - }), + computed: { + ...mapState(["grimoire"]), + ...mapState("players", ["players"]) + }, methods: { takeScreenshot(dimensions = {}) { this.$store.commit("updateScreenshot"); @@ -95,6 +105,28 @@ export default { prompt("Enter custom background URL") ); }, + hostSession() { + const sessionId = prompt( + "Enter a code for your session", + Math.random() + .toString(36) + .substring(2, 7) + ); + if (sessionId) { + this.$store.commit("setSessionId", "h:" + sessionId.substr(0, 5)); + } + }, + joinSession() { + const sessionId = prompt( + "Enter the code of the session you want to join" + ); + if (sessionId) { + this.$store.commit("setSessionId", "j:" + sessionId.substr(0, 5)); + } + }, + leaveSession() { + this.$store.commit("setSessionId", ""); + }, addPlayer() { const name = prompt("Player name"); if (name) { diff --git a/src/store/index.js b/src/store/index.js index e5991cf..7a6b23e 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1,6 +1,7 @@ import Vue from "vue"; import Vuex from "vuex"; import persistence from "./persistence"; +import session from "./session"; import players from "./modules/players"; import editionJSON from "../editions.json"; import rolesJSON from "../roles.json"; @@ -33,7 +34,8 @@ export default new Vuex.Store({ isScreenshotSuccess: false, zoom: 1, background: "", - bluffs: [] + bluffs: [], + sessionId: "" }, modals: { edition: false, @@ -67,6 +69,9 @@ export default new Vuex.Store({ setBackground({ grimoire }, background) { grimoire.background = background; }, + setSessionId({ grimoire }, sessionId) { + grimoire.sessionId = sessionId; + }, setBluff({ grimoire }, { index, role }) { grimoire.bluffs.splice(index, 1, role); }, @@ -88,5 +93,5 @@ export default new Vuex.Store({ state.roles = getRolesByEdition(edition); } }, - plugins: [persistence] + plugins: [persistence, session] }); diff --git a/src/store/session.js b/src/store/session.js new file mode 100644 index 0000000..0077564 --- /dev/null +++ b/src/store/session.js @@ -0,0 +1,8 @@ +module.exports = store => { + // setup + + // listen to mutations + store.subscribe(({ type, payload }, state) => { + console.log(type, payload, state); + }); +};