diff options
author | Kyle Gunger <kgunger12@gmail.com> | 2022-07-19 00:31:02 -0400 |
---|---|---|
committer | Kyle Gunger <kgunger12@gmail.com> | 2022-07-19 00:31:02 -0400 |
commit | 5207f04d5b775bf4805d83c81aaad1cfcf3fe68a (patch) | |
tree | 66b31b953af2df99f2b74e296b4f77555b234642 /scripts/gui | |
parent | 1dab192a329b1ad966b0c1e0401eeaa78d5b752e (diff) |
Change how card id's are held, add swapCard
Diffstat (limited to 'scripts/gui')
-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(); } |