summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/cards/card.js4
-rw-r--r--scripts/cards/deck.js4
-rw-r--r--scripts/gui/table.js22
3 files changed, 22 insertions, 8 deletions
diff --git a/scripts/cards/card.js b/scripts/cards/card.js
index 3ca435c..7246db3 100644
--- a/scripts/cards/card.js
+++ b/scripts/cards/card.js
@@ -15,9 +15,7 @@ class Card {
this.e.style.top = "0px";
this.e.card = this;
- this.getID = function() {
- return id;
- }
+ this.id = id;
}
// Generate a card with basic text only
diff --git a/scripts/cards/deck.js b/scripts/cards/deck.js
index 0c88821..8d38186 100644
--- a/scripts/cards/deck.js
+++ b/scripts/cards/deck.js
@@ -144,7 +144,7 @@ class Deck {
{
for(let i in this.cards)
{
- if(this.cards[i].getID() == id)
+ if(this.cards[i].id === id)
return this.removeCard(i);
}
@@ -186,7 +186,7 @@ class Deck {
{
for(let c of this.cards)
{
- if(c.getID() === id)
+ if(c.id === id)
return c;
}
return null;
diff --git a/scripts/gui/table.js b/scripts/gui/table.js
index 5e69f3e..46a520b 100644
--- a/scripts/gui/table.js
+++ b/scripts/gui/table.js
@@ -88,7 +88,7 @@ class Table{
this.decks[id].e.remove();
for(let i in this.decks[id].cards)
{
- delete this.cards[this.decks[id].cards[i].getID()];
+ delete this.cards[this.decks[id].cards[i].id];
this.decks[id].removeCard(i);
}
delete this.deck[id];
@@ -114,6 +114,22 @@ class Table{
this.decks[data.deckID].addCardAt(this.cards[data.cardID], data.index);
}
+ // Swap card data with new data
+ // {data object} data from the server
+ // {data.cardID any} ID of the card to swap
+ // {data.newID any} New ID for the card
+ // {data.data object} visualization data
+ swapCard(data)
+ {
+ // Can't swap a card into a an id of a pre-existing card.
+ if (this.cards[data.newID] != null) {
+ return false;
+ }
+ this.cards[data.newID] = this.cards[data.cardID];
+ delete this.cards[data.cardID];
+ this.cards[data.newID].generateElements(data.data);
+ }
+
/* Internal functions */
@@ -154,8 +170,8 @@ class Table{
if(c !== null)
{
- if(d !== null)
- this.checkMove(c.getID(), d);
+ if(d !== null && !this.decks[d].hasCard(c.id))
+ this.checkMove(c.id, d);
else
c.resetPos();
}