Move all card from different location back to deck

Game development with Board Game Arena Studio
Post Reply
User avatar
Ilmion
Posts: 30
Joined: 28 March 2020, 03:26

Move all card from different location back to deck

Post by Ilmion »

I have multiple locations for cards in my deck and I would like to move all the card from all the location back to the deck.
I'm lucky that all those cards are of the same type, so this seem to be working well

Code: Select all

$distributedCards = array_map(function($card){ return $card['id']; }, $this->maptiles_deck->getCardsOfType( 'mapTiles' ));
$this->maptiles_deck->moveCards($distributedCards , 'maptiles_deck');
But for getCardsOfType, it it written in the wiki as "rarely use". Is there a better way ? Would there be a way if all the card where of a different type ?
User avatar
Mosty Mostacho
Posts: 1
Joined: 09 October 2016, 04:18

Re: Move all card from different location back to deck

Post by Mosty Mostacho »

You can use

Code: Select all

getCardsInLocation($location, $location_arg = null, $order_by = null)
documented here: http://en.doc.boardgamearena.com/index. ... formations

Of course, use the array of locations you need to get them from.

Having said that, why not just?

Code: Select all

self::DbQuery("UPDATE `deck` SET `card_location` = 'deck'");
That is more efficient. Considering the slowness of the Studio server, efficiency should not be negligible. If you care too much about readability, just create a new class (possible extending Deck) and create the corresponding method.
User avatar
Ilmion
Posts: 30
Joined: 28 March 2020, 03:26

Re: Move all card from different location back to deck

Post by Ilmion »

You get my idea about readability but also it is much cleaner (IMHO) if we always use the deck object to manipulate the deck. That is why I was hesitant to directly query the database, but I really like the idea of extending the deck object.
User avatar
Ilmion
Posts: 30
Joined: 28 March 2020, 03:26

Re: Move all card from different location back to deck

Post by Ilmion »

I've found it !!
In the wiki in the hearts "example" :

Code: Select all

// This is a new hand: let's gather all cards from everywhere in the deck:
$this->cards->moveAllCardsInLocation( null, "deck" );
I'll try and update the definition of moveAllCardsInLocation.
Post Reply

Return to “Developers”