diff options
Diffstat (limited to 'scripts/gui/table.js')
-rw-r--r-- | scripts/gui/table.js | 22 |
1 files changed, 19 insertions, 3 deletions
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(); } |