Page 1 of 1
Stock control, how to modify individual item
Posted: 14 August 2017, 20:39
by quietmint
My game has a small deck of cards. I am using the Stock control to manage each player's hand of 2 cards. During the game, cards in hand are spent/used up, but they still remain in that player's hand. I want to change the appearance of the spent cards. I want to keep them in the same Stock as the unused cards so I can continue to overlap them.
How can I add a CSS class to an individual card in Stock? I see how onItemCreate lets me do this at card creation time, but what about later during the course of the game? Given a card's specific ID, how do I get the corresponding HTML element to manipulate it?
Re: Stock control, how to modify individual item
Posted: 15 August 2017, 04:26
by Victoria_La
Are you using addToStockWithId? You can see what it generates to see if you hook it to it by that id, there is hook onItemCreate
from which you can get the node id
Re: Stock control, how to modify individual item
Posted: 16 August 2017, 01:13
by quietmint
I know onItemCreate was hoping for a more elegant solution. I want to modify the card at runtime, not at creation.
But actually, I take back what I said earlier. Even onItemCreate doesn't give me the card ID, it only gives the ID of the DOM element. Am I just to assume that DOM element "tableau_2305331_item_4" is for card ID = 4?
Re: Stock control, how to modify individual item
Posted: 16 August 2017, 02:54
by Morgalad
you NEED to remember which element goes with each id!!!
The game logic is based in the fact that a player can press F5 at any moment!
Re: Stock control, how to modify individual item
Posted: 16 August 2017, 17:37
by Een
Stock method getItemDivId( id ) might be what you are looking for.
Re: Stock control, how to modify individual item
Posted: 19 August 2017, 15:19
by quietmint
Een wrote:Stock method getItemDivId( id ) might be what you are looking for.
Thanks, that's exactly it!