From ad911d6edd0fa76431284ef6283bb07da45d808d Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Thu, 11 Aug 2022 00:03:45 -0400 Subject: A few small fixes --- scripts/client.js | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'scripts/client.js') diff --git a/scripts/client.js b/scripts/client.js index ffba4b5..815d4f2 100644 --- a/scripts/client.js +++ b/scripts/client.js @@ -171,23 +171,32 @@ class Client{ { let m = e.detail; - if(m.type === "nojoin") { + switch (m.type) { + case "nojoin": alert(`Failed to join game. ${m.data}`); - } else if (m.type === "join") { - this.table.openTable(); - this.lobby.setState("In Game", "ok", this.socket.server) - this.inGame = true; - } else if (m.type === "leave") { + break; + case "leave": this.table.reset(); if (this.game.id !== m.data) { this.lobby.setState("Joining...", "loading", this.socket.server); this.socket.send("join", this.game); + } else { + this.lobby.setState("Connected", "ok", this.socket.server); } this.inGame = false; - } else if (TABLE_RPC.includes(m.type)) - this.table[m.type](m.data); + break; + case "join": + this.table.openTable(); + this.lobby.setState("In Game", "ok", this.socket.server); + this.inGame = true; + break; + default: + if (TABLE_RPC.includes(m.type) && this.inGame) + this.table[m.type](m.data); + break; + } } // Callback when a chat event is recieved from the server -- cgit v1.2.3