Skip to content

Commit

Permalink
Leaving game no longer continues to play game sounds
Browse files Browse the repository at this point in the history
Especially important for observing games
  • Loading branch information
Zomis committed Mar 23, 2019
1 parent 0b7e491 commit f8e239d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/socketStore.js
Expand Up @@ -194,9 +194,11 @@ export default {
};

if (type === "ADIO") {
let audio = audios[param]();
audio.volume = parseInt(localStorage.volume, 10) / 100;
audio.play();
if (context.rootState.games.activeGameId !== null) {
let audio = audios[param]();
audio.volume = parseInt(localStorage.volume, 10) / 100;
audio.play();
}
return;
}
if (type === "USRK") {
Expand Down
3 changes: 3 additions & 0 deletions src/views/games/ActiveGame.vue
Expand Up @@ -8,6 +8,9 @@ import { mapState } from "vuex";
export default {
name: "ActiveGame",
components: { GameScreen },
beforeDestroy() {
this.$store.commit("games/leaveActiveGame");
},
computed: {
...mapState("games", ["activeGameId"])
}
Expand Down
3 changes: 3 additions & 0 deletions src/views/games/gamesStore.js
Expand Up @@ -115,6 +115,9 @@ export default {
let game = state.activeGames[data.gameId];
gameTools.setPlayerNames(game, [data.player1, data.player2]);
},
leaveActiveGame(state) {
state.activeGameId = null;
},
newGame(state, gameInfo) {
// Use gameId as String
Vue.set(
Expand Down
6 changes: 4 additions & 2 deletions src/views/lobby/Lobby.vue
Expand Up @@ -90,8 +90,10 @@ export default {
...mapState("lobby", ["messages", "onlineUsers", "lobbyGames"])
},
watch: {
activeGame() {
this.$router.push("/activeGame");
activeGame(value) {
if (value) {
this.$router.push("/activeGame");
}
}
},
methods: {
Expand Down

0 comments on commit f8e239d

Please sign in to comment.