0
0
Fork 0

Implement StartGame caller and listener.

This commit is contained in:
Oliver-Akins 2021-01-02 13:34:04 -07:00
parent 2a18c59f1a
commit 5adefc7df3

View file

@ -30,7 +30,7 @@
</button>
<button
class="clickable"
@click.stop=""
@click.stop="startGame()"
>
Click to Start the Game
</button>
@ -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`);
},
},
}
</script>