Page 1 of 1

Suggestion for an improvement of stock component

Posted: 27 October 2014, 22:12
by stst
Many games on BGA use stock component and most of these games use methods: addToStock/addToStockWithId and removeFromStock/removeFromStockById with optional parameter "from/to" for sliding of stock item from/to an Html element. Very often stock item (card, token, ...) is sliding under various game elements on game board, but it would have to slide above those game elements. This situation looks not very beautifully.

I offer to add two optional parameters to those methods: addToStock( type, from, zindex, duration ) and removeFromStock( type, to, zindex, duration ) and (too addToStockWithId/removeFromStockById)
Additional parameters:

zindex: OPTIONNAL: z-index of stock item sliding to/from an Html element. (Then we could manage z-index of stock item and it could slide above required game elements)
Available value: "PREV" - value by default for compatibility with previous version, "AUTO" - z-index of stock item equal z-index of Html element, any value for z-index of stock item.

duration: OPTIONNAL: duration of sliding of stock item to/from an Html element (msec). Value by default equal 1000 for compatibility with previous version.

Re: Suggestion for an improvement of stock component

Posted: 28 October 2014, 14:25
by pikiou
These two additional parameters would be very useful to me as well!
There is another way around that would require slightly more code but would allow for more flexibility.

As a replacement of the zIndex parameter, I'd suggest using a Stock method that gives the id of the element of an item, then change the zIndex of the item before the animation:

Code: Select all

dojo.style(myHand.itemElementId(45), 'zIndex', 900);
myHand.removeFromStock(45, 'discard');
I know how to create the element id of an item when I know the item id, but when I only know its type, it's more difficult. We could also make use of an itemElementIdById that would take an item id as parameter (since the control_name property of stocks is not documented, I guess we're not supposed to use it).

For the duration, all we'd need is for these addToStock[WithId]/removeFromStock[ById] methods to return the animation. We could then change the animation duration on the fly:

Code: Select all

var anim = myHand.removeFromStock(45, 'discard');
anim.duration = 1000;
Having the animation handler would also be useful to trigger something at the end of the animation, like a counter rising up.