diff --git a/src/public/index.html b/src/public/index.html
index 3d446d8..8cddc75 100644
--- a/src/public/index.html
+++ b/src/public/index.html
@@ -40,6 +40,7 @@
v-if="state.view === 'game'"
:game-state="state.gameState"
:game-connection="state.gameConnection"
+ :sfx-disabled="state.sfxDisabled"
>
diff --git a/src/public/js/game-view.vue b/src/public/js/game-view.vue
index a7d6bcd..569d3d8 100644
--- a/src/public/js/game-view.vue
+++ b/src/public/js/game-view.vue
@@ -195,6 +195,10 @@ export default {
type: Object,
required: true,
},
+ sfxDisabled: {
+ type: Boolean,
+ required: true,
+ },
},
data() {
return {
@@ -202,7 +206,7 @@ export default {
stroke: strokeTracker,
drawingPad: drawingPad,
promptVisible: true,
- menuItems: this.generateMenuOptions(),
+ menuItems: [],
playerStatusesListMaxWidth: 0,
currentDialog: undefined,
};
@@ -241,6 +245,12 @@ export default {
['gameState.phase']() {
this.menuItems = this.generateMenuOptions();
},
+ ['sfxDisabled']() {
+ this.menuItems = this.generateMenuOptions();
+ },
+ promptVisible() {
+ this.menuItems = this.generateMenuOptions();
+ },
},
methods: {
reset() {
@@ -345,6 +355,9 @@ export default {
togglePrompt() {
this.promptVisible = !this.promptVisible;
},
+ toggleSfx() {
+ Store.toggleSfx();
+ },
showDialog(name) {
this.currentDialog = name;
},
@@ -373,9 +386,13 @@ export default {
};
return [
{
- text: 'Toggle prompt',
+ text: this.promptVisible ? 'Hide prompt' : 'Show prompt',
action: this.togglePrompt,
},
+ {
+ text: this.sfxDisabled ? 'Unmute sound' : 'Mute sound',
+ action: this.toggleSfx,
+ },
{
text: 'Game status',
action: () => {
@@ -403,6 +420,7 @@ export default {
this.resizePlayerStatusesList();
this.reset();
});
+ this.menuItems = this.generateMenuOptions();
window.addEventListener('resize', this.onWindowResize);
},
beforeDestroy() {
diff --git a/src/public/js/state.js b/src/public/js/state.js
index 27f9c7b..b2eeca6 100644
--- a/src/public/js/state.js
+++ b/src/public/js/state.js
@@ -11,6 +11,7 @@ const sfx = new Audio('static/notification_simple-01.wav');
const Store = {
state: {
username: localStorage.username || '',
+ sfxDisabled: localStorage.sfxDisabled === 'true',
view: VIEW.HOME,
previousView: VIEW.HOME,
gameState: undefined,
@@ -22,6 +23,10 @@ const Store = {
this.state.username = username;
localStorage.username = username;
},
+ toggleSfx() {
+ this.state.sfxDisabled = !this.state.sfxDisabled;
+ localStorage.sfxDisabled = this.state.sfxDisabled;
+ },
setView(view) {
this.state.previousView = this.state.view;
this.state.view = view;
@@ -88,7 +93,7 @@ function handleSocket(messageName, handler, errHandler) {
? Store.state.gameState.strokes.length
: 0;
Store.setGameState(data.roomState);
- if (prevStrokesLength < data.roomState.strokes.length) {
+ if (!Store.state.sfxDisabled && prevStrokesLength < data.roomState.strokes.length) {
sfx.play();
}
}