Skip to content
This repository has been archived by the owner on Aug 19, 2021. It is now read-only.

Commit

Permalink
Add mute option; Update game menu
Browse files Browse the repository at this point in the history
  • Loading branch information
kcgidw committed May 22, 2020
1 parent 19656ae commit d5e61f0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
v-if="state.view === 'game'"
:game-state="state.gameState"
:game-connection="state.gameConnection"
:sfx-disabled="state.sfxDisabled"
></game-view>
</div>

Expand Down
22 changes: 20 additions & 2 deletions src/public/js/game-view.vue
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,18 @@ export default {
type: Object,
required: true,
},
sfxDisabled: {
type: Boolean,
required: true,
},
},
data() {
return {
canvasState: CanvasState.SPECTATE,
stroke: strokeTracker,
drawingPad: drawingPad,
promptVisible: true,
menuItems: this.generateMenuOptions(),
menuItems: [],
playerStatusesListMaxWidth: 0,
currentDialog: undefined,
};
Expand Down Expand Up @@ -241,6 +245,12 @@ export default {
['gameState.phase']() {
this.menuItems = this.generateMenuOptions();
},
['sfxDisabled']() {
this.menuItems = this.generateMenuOptions();
},
promptVisible() {
this.menuItems = this.generateMenuOptions();
},
},
methods: {
reset() {
Expand Down Expand Up @@ -345,6 +355,9 @@ export default {
togglePrompt() {
this.promptVisible = !this.promptVisible;
},
toggleSfx() {
Store.toggleSfx();
},
showDialog(name) {
this.currentDialog = name;
},
Expand Down Expand Up @@ -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: () => {
Expand Down Expand Up @@ -403,6 +420,7 @@ export default {
this.resizePlayerStatusesList();
this.reset();
});
this.menuItems = this.generateMenuOptions();
window.addEventListener('resize', this.onWindowResize);
},
beforeDestroy() {
Expand Down
7 changes: 6 additions & 1 deletion src/public/js/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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();
}
}
Expand Down

0 comments on commit d5e61f0

Please sign in to comment.