From 5207f04d5b775bf4805d83c81aaad1cfcf3fe68a Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Tue, 19 Jul 2022 00:31:02 -0400 Subject: Change how card id's are held, add swapCard --- scripts/gui/table.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'scripts/gui') 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(); } -- cgit v1.2.3