summaryrefslogtreecommitdiff
path: root/scripts/gui
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/gui')
-rw-r--r--scripts/gui/chat.js34
-rw-r--r--scripts/gui/lobby.js16
-rw-r--r--scripts/gui/table.js54
3 files changed, 73 insertions, 31 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();
diff --git a/scripts/gui/lobby.js b/scripts/gui/lobby.js
index 8242843..4907f41 100644
--- a/scripts/gui/lobby.js
+++ b/scripts/gui/lobby.js
@@ -51,7 +51,7 @@ class TopBar{
// Game represents a single game in the lobby view. It has methods for setting up the elements and such.
class Game {
- constructor(options = {id: 0, name: ""}, el)
+ constructor(options = {id: 0, name: "", password: false}, el)
{
this.getID = function () {
return options.id;
@@ -74,6 +74,20 @@ class Game {
join.addEventListener("click", game.joinGame.bind(game, options.id));
e.appendChild(join);
+ this.hasPassword = function () {
+ return options.password;
+ }
+
+ if(usePass) {
+ let pass = MakeInput.textInput("", "Game password");
+ pass.classList.add("pass");
+ e.appendChild(pass);
+
+ this.getUserPass = function () {
+ return pass.value;
+ }
+ }
+
el.appendChild(e);
}
}
diff --git a/scripts/gui/table.js b/scripts/gui/table.js
index e242ac6..ab7fd3b 100644
--- a/scripts/gui/table.js
+++ b/scripts/gui/table.js
@@ -10,7 +10,8 @@ class Table{
this.socket = socket;
- this.decks = [];
+ this.decks = {};
+ this.cards = {};
}
openTable ()
@@ -41,27 +42,53 @@ class Table{
while(this.root.firstElementChild != null)
this.root.firstElementChild.remove();
- this.decks = [];
+ this.decks = {};
this.closeTable();
this.drag.stopDraggingAll();
}
/* Deck and card functions */
- newDeck(id, options)
+
+ // {data object} contains deck id and options
+ // {data.id any} identifier for deck. Probably int or string.
+ // {data.options object} Options as found in Deck constructor
+ newDeck(data)
{
- var d = new Deck(id, options);
- this.decks.push(d);
+ var d = new Deck(data.id, data.options);
+ this.decks[data.id] = d;
this.root.appendChild(d.e);
}
- newCard(id, data, deck = 0)
+ // {data object} contains data from server
+ // {data.id} card id
+ // {data.data} card data for visualization on the table
+ // {data.deck} the id of the deck to add the card to
+ newCard(data)
{
- var c = new Card(id, data);
- this.decks[deck].appendCard(c);
+ var c = new Card(data.id, data.data);
+ this.cards[data.id] = c;
+ this.decks[data.deck].appendCard(c);
this.drag.addTarget(c.e);
}
+ // {data object} data from the server
+ // {data.id any} card id to delete
+ deleteCard(data)
+ {
+ //this.cards[data.id].getDeck().removeCardByID
+ this.cards[data.id].e.remove();
+ delete this.cards[data.id];
+ }
+
+ // {data object} data from the server
+ // {data.id any} deck id to delete
+ deleteDeck(data)
+ {
+ //for(let i of this.deck[data.id].cards)
+ //this.deck[]
+ }
+
checkDeck(x, y)
{
for(let d of this.decks)
@@ -83,6 +110,7 @@ class Table{
return null;
}
+ // {data object} data from the server
moveCard(card, newDeck, index = -1)
{
for(let d of this.decks)
@@ -98,11 +126,17 @@ class Table{
newDeck.addCardAt(card, index);
}
- moveByID(cardID, deckID, index = -1)
+ // {data object} data from the server
+ // {data.cardID any} ID of the card to move
+ // {data.deckID any} ID of the deck to move the card to
+ // {data.index number} card index in the new deck
+ moveByID(data)
{
let card, deck;
for(let d of this.decks)
{
+ if (d.removeCardByID(cardID) !== null)
+ break;
let c = d.hasCard(cardID)
if(c !== null)
card = c;
@@ -110,8 +144,6 @@ class Table{
if(d.getID() == deckID)
deck = d;
}
-
- this.moveCard(card, deck, index);
}
checkMove(cardID, deckID, index = -1)