Skip to content

Commit

Permalink
Add game leave to Game (for real this time)
Browse files Browse the repository at this point in the history
  • Loading branch information
NKY5223 committed Apr 14, 2024
1 parent c1aeb7c commit b20e336
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 9 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,15 +622,21 @@ createGameBtn.addEventListener("click", _ => {

// #region Join
const gameDiv = document.getElementById("gameDiv");
game.once("join", _ => {
game.on("join", _ => {
document.activeElement?.blur();
changeScreen(gameDiv, 0);
});
game.on("join", _ => {
chatAsClient("Joined game");
});
// #endregion

// #region Leave
game.on("leave", _ => {
document.activeElement?.blur();
changeScreen(titleScreen, 1);
chatAsClient("Left game");
});
// #endregion

// #region Player List
const playerList = document.getElementById("playerList");
game.on("updateState", state => {
Expand Down
5 changes: 5 additions & 0 deletions js/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default class Game {

this.socket.on("initMap", msg => this.initMap(msg.m));
this.socket.on("updateMap", msg => this.updateMap(msg.m));
this.socket.on("leave", msg => this.emit("leave"));
this.socket.on("join", msg => {
this.initMap(msg.i.map);
this.updateState(msg.i.states);
Expand Down Expand Up @@ -332,6 +333,10 @@ export default class Game {
});
});
}
leave() {
this.socket.send({ e: "leave" });
this.emit("leave");
}
// #endregion

// #region Map, State
Expand Down

0 comments on commit b20e336

Please sign in to comment.