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 | |
| parent | 1dab192a329b1ad966b0c1e0401eeaa78d5b752e (diff) | |
Change how card id's are held, add swapCard
| -rw-r--r-- | scripts/cards/card.js | 4 | ||||
| -rw-r--r-- | scripts/cards/deck.js | 4 | ||||
| -rw-r--r-- | scripts/gui/table.js | 22 | 
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();  		} |