menu added, session plugin created

This commit is contained in:
Steffen 2020-05-08 19:33:29 +02:00
parent 61860d86d4
commit a028cf867f
No known key found for this signature in database
GPG Key ID: 764D74E98267DFC6
3 changed files with 51 additions and 6 deletions

View File

@ -37,6 +37,16 @@
<li @click="setBackground"> <li @click="setBackground">
Background image Background image
</li> </li>
<li @click="hostSession" v-if="!grimoire.sessionId">
Host Live Session
</li>
<li @click="joinSession" v-if="!grimoire.sessionId">
Join Live Session
</li>
<li @click="leaveSession" v-if="grimoire.sessionId">
<em>{{ grimoire.sessionId.substr(2) }}</em>
Leave Session
</li>
<!-- Users --> <!-- Users -->
<li class="headline"> <li class="headline">
@ -80,10 +90,10 @@ export default {
components: { components: {
Screenshot Screenshot
}, },
computed: mapState({ computed: {
grimoire: state => state.grimoire, ...mapState(["grimoire"]),
players: state => state.players.players ...mapState("players", ["players"])
}), },
methods: { methods: {
takeScreenshot(dimensions = {}) { takeScreenshot(dimensions = {}) {
this.$store.commit("updateScreenshot"); this.$store.commit("updateScreenshot");
@ -95,6 +105,28 @@ export default {
prompt("Enter custom background URL") 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() { addPlayer() {
const name = prompt("Player name"); const name = prompt("Player name");
if (name) { if (name) {

View File

@ -1,6 +1,7 @@
import Vue from "vue"; import Vue from "vue";
import Vuex from "vuex"; import Vuex from "vuex";
import persistence from "./persistence"; import persistence from "./persistence";
import session from "./session";
import players from "./modules/players"; import players from "./modules/players";
import editionJSON from "../editions.json"; import editionJSON from "../editions.json";
import rolesJSON from "../roles.json"; import rolesJSON from "../roles.json";
@ -33,7 +34,8 @@ export default new Vuex.Store({
isScreenshotSuccess: false, isScreenshotSuccess: false,
zoom: 1, zoom: 1,
background: "", background: "",
bluffs: [] bluffs: [],
sessionId: ""
}, },
modals: { modals: {
edition: false, edition: false,
@ -67,6 +69,9 @@ export default new Vuex.Store({
setBackground({ grimoire }, background) { setBackground({ grimoire }, background) {
grimoire.background = background; grimoire.background = background;
}, },
setSessionId({ grimoire }, sessionId) {
grimoire.sessionId = sessionId;
},
setBluff({ grimoire }, { index, role }) { setBluff({ grimoire }, { index, role }) {
grimoire.bluffs.splice(index, 1, role); grimoire.bluffs.splice(index, 1, role);
}, },
@ -88,5 +93,5 @@ export default new Vuex.Store({
state.roles = getRolesByEdition(edition); state.roles = getRolesByEdition(edition);
} }
}, },
plugins: [persistence] plugins: [persistence, session]
}); });

8
src/store/session.js Normal file
View File

@ -0,0 +1,8 @@
module.exports = store => {
// setup
// listen to mutations
store.subscribe(({ type, payload }, state) => {
console.log(type, payload, state);
});
};