Contribution to Stock component proposal, regarding card order

Game development with Board Game Arena Studio
Post Reply
User avatar
JustinFernal
Posts: 9
Joined: 27 March 2020, 03:03

Contribution to Stock component proposal, regarding card order

Post by JustinFernal »

Hello,

In the game I'm currently developing, I have lines of cards in the table, and for each line, cards need to be displayed in a given oder (based on when and where they were added basically).

Based on the stock component (http://en.doc.boardgamearena.com/Stock), there is a weight parameter that is used to sort items of the stock during the display, but only for ItemType, not for individual cards. Is there something similar at the Item level :?:

What I would expect : The weight can (must?) be defined at the type level and is the default weight for each component of this type, unless the weight is overwritten by the Item. Display order is then done by sorting all the items based on their weight. If no weight is defined at the item level, it would not change the current behavior, and it would allow to choose the order of individual cards.

I can have a workaround by creating a new "type" in the stock for each "true type of card" X "position", but that sounds like a dirty hack. (That's more or less what is done in hanabi, creating a type per card_id because the position is sorted by card_id for each hand, so I'm not the first game to have this concern. ;) )

Does it already exists or Is it a modification that can be made? (I might help by doing a Pull Request if I know where to find the Stock source code or updating the wiki if it is already possible.)
Last edited by JustinFernal on 03 April 2020, 17:31, edited 1 time in total.
User avatar
JustinFernal
Posts: 9
Joined: 27 March 2020, 03:03

Re: [Feature request?] Stock component, card order

Post by JustinFernal »

For the others that might be searching for a solution, ebg/stock has many functions that are not documented in the wiki. One of them is : changeItemsWeight( {type: weight} ).

While I still consider the points above as valid (we shall be able to override the weight at the object level), it makes a pretty good solution for me so far as cards of the same type are grouped together.


For the maintainers of ebg/stock, there is an hardening modification that shall be made to this function :
On the usual addItemType, the weight is converted to an int, even if we provide a string for instance.

Code: Select all

weight: toint(weight), 
On changeItemsWeight however, that's not done, and so we might introduce a string by mistake. (Guess what, somebody did recently :roll: ;) )

Code: Select all

if (this.item_type[type]) {
 this.item_type[type].weight = _115a;
Should become :

Code: Select all

if (this.item_type[type]) {
 this.item_type[type].weight = toint(_115a);
Who might adress this, and is there a way to make pull requests for such modifications on the shared libraries?
User avatar
Lymon Flowers
Posts: 195
Joined: 01 April 2020, 21:14

Re: Contribution to Stock component proposal, regarding card order

Post by Lymon Flowers »

You can still override the sortItems function of the ebg.stock object:

Code: Select all

            // Player hand
            this.playerHand = new ebg.stock();
	    this.playerHand.sortItems = function ( ) {
		return this.items.sort(function(a,b) { return parseInt(a . id) < parseInt(b . id); } );
	    };
This is what I did for my game, not sure if this is recommended on the long run thought.
User avatar
Benoit314
Posts: 82
Joined: 02 April 2020, 22:12

Re: Contribution to Stock component proposal, regarding card order

Post by Benoit314 »

The doc isn't complete, but if you check the game Jaipur, you can use:

Code: Select all

this.yourstock.order_items = false;
Then your cards will be in the order they've been added to the stock.
Post Reply

Return to “Developers”