diff options
author | Kyle Gunger <kgunger12@gmail.com> | 2021-10-19 00:18:37 -0400 |
---|---|---|
committer | Kyle Gunger <kgunger12@gmail.com> | 2021-10-19 00:18:37 -0400 |
commit | 811571e23b68f4318794de3d34aa15cb91ec3d2d (patch) | |
tree | 56c1a5648a06aac8c59125d0af7669c0a9688547 /scripts/gui/chat.js | |
parent | fb231e3c6f3afbd40de5a94187221b788656cb5c (diff) |
[Refactor] Lots of little patches
+ Make chatbox code a little cleaner
+ Add a bit of documentation
+ Begin prep for passwords
+ Function to easily grab decks from cards
~ I am going to have to completely re-do cards and decks probably.
Diffstat (limited to 'scripts/gui/chat.js')
-rw-r--r-- | scripts/gui/chat.js | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/scripts/gui/chat.js b/scripts/gui/chat.js index 4bd6933..428403a 100644 --- a/scripts/gui/chat.js +++ b/scripts/gui/chat.js @@ -4,6 +4,7 @@ class Chat { constructor(e, soc) { this.chats = []; + this.active = null; this.root = e; this.socket = soc; e.getElementsByClassName("toggle-chat")[0].onclick = this.toggle.bind(this); @@ -29,15 +30,8 @@ class Chat { isActive (name) { - for(let i in this.chats) - { - if (this.chats[i].name == name) - { - if(this.chats[i].btn.getAttribute("active") == "true") - return true; - return false; - } - } + if(this.active !== null) + return this.active.name === name; return false; } @@ -68,20 +62,13 @@ class Chat { getActiveChannel () { - for(let i in this.chats) - { - if (this.chats[i].btn.getAttribute("active") == "true") - { - return this.chats[i]; - } - } - - return null; + return this.active; } switchChannel (name) { let c = this.getChannel(name); + this.active = c; if(c == null) return; @@ -111,7 +98,7 @@ class Chat { if(str == "") return; this.chatInput.value = ""; - this.socket.send("chat", str); + this.socket.send("chat", {str}); } recieveMessage (channel, msg) @@ -163,6 +150,15 @@ class Chat { if(c == null) return; + let id = this.chats.indexOf(c); + if(this.isActive(name)) { + if(id == 0 && this.chats.length > 1) + this.switchChannel(this.chats[1].name); + else + this.switchChannel(this.chats[id - 1].name); + } + + while(c.e.firstElementChild != null) c.e.firstElementChild.remove(); |