summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2021-10-16 21:43:21 -0400
committerKyle Gunger <kgunger12@gmail.com>2021-10-16 21:43:21 -0400
commit84e33c394a9611dfde7472b0d651d0f3b4600352 (patch)
tree1ab0f458b80e05c46f64c0ba327e7b54513b0369
parent606de4038bfa3be22a9c24cf5010f03572b87598 (diff)
[REFACTOR] RPC API
-rw-r--r--scripts/client.js48
1 files changed, 3 insertions, 45 deletions
diff --git a/scripts/client.js b/scripts/client.js
index c612175..1e7bacc 100644
--- a/scripts/client.js
+++ b/scripts/client.js
@@ -80,13 +80,11 @@ class Client{
// Callbacks for if the socket fails or closes
socketError() {
- alert("Connection error");
this.lobby.setState("Error", "closed", this.socket.server);
this.table.handleClose();
}
socketClose() {
- alert("Connection closed by server");
this.lobby.setState("Closed", "closed", this.socket.server);
this.table.handleClose();
}
@@ -133,61 +131,21 @@ class Client{
menu (e)
{
let m = e.detail;
- switch (m.type) {
- case "plist":
- this.lobby.packList(m.data);
- break;
- case "glist":
- this.lobby.gameList(m.data, this.game);
- this.game = null;
- break;
- case "players":
- this.lobby.players(m.data);
- break;
- case "gdel":
- this.lobby.removeGame(m.data);
- break;
- case "gadd":
- this.lobby.addGame(m.data);
- break;
- case "pdel":
- this.lobby.removePlayer(m.data);
- break;
- case "padd":
- this.lobby.addPlayer(m.data);
- break;
- case "pmove":
- this.lobby.movePlayer(m.data);
- break;
- }
+ this.lobby[m.type](m.data);
}
// Game switch, called when in game and a message arrives from the server
game (e)
{
let m = e.detail;
- switch (m.type) {
- case "move":
- this.table.moveByID(m.data.card, m.data.deck, m.data.pos);
- break;
- }
+ this.table[m.type](m.data);
}
// Callback when a chat event is recieved from the server
chat (e)
{
let m = e.detail;
- switch (m.type) {
- case "delchan":
- this.chat.deleteChannel(m.data);
- break;
- case "newchan":
- this.chat.addChannel(m.data);
- break;
-
- case "message":
- this.chat.recieveMessage(m.data.type, m.data.data);
- }
+ this.chat[m.type](m.data);
}
// Reset the lobby and table, then attempt to reopen the connection to the server.