From 5adefc7df347aab1c9e7480804df78941f74a0ef Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Sat, 2 Jan 2021 13:34:04 -0700 Subject: [PATCH] Implement StartGame caller and listener. --- web/src/views/Lobby.vue | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/web/src/views/Lobby.vue b/web/src/views/Lobby.vue index 9283c5f..3bc0836 100644 --- a/web/src/views/Lobby.vue +++ b/web/src/views/Lobby.vue @@ -30,7 +30,7 @@ @@ -56,7 +56,10 @@ export default { return this.$store.state.name; }, gameURL() { - return `${window.location.protocol}//${window.location.host}/?game=${this.$store.state.game_code}`; + return `${window.location.protocol}//${window.location.host}/?game=${this.gameCode}`; + }, + gameCode() { + return this.$store.state.game_code; }, }, methods: { @@ -75,17 +78,22 @@ export default { // everyone from the game. if (this.$store.state.is_host) { this.$socket.client.emit(`DeleteGame`, { - game_code: this.$store.state.game_code + game_code: this.gameCode }); } // Just a normal user, they can leave the game just fine else { this.$socket.client.emit(`LeaveGame`, { - game_code: this.$store.state.game_code + game_code: this.gameCode }); }; }, + startGame() { + this.$socket.client.emit(`StartGame`, { + game_code: this.gameCode + }) + }, }, sockets: { GameLeft(data) { @@ -94,6 +102,12 @@ export default { }; this.$store.commit(`resetState`); }, + GameStarted(data) { + if (data.status < 200 || 300 <= data.status) { + return this.$emit(`error`, data); + }; + this.$store.commit(`view`, `in-game`); + }, }, }