Part 9: Finishing the Deck Builder prototype

Once Iโ€™d cracked the repeater system for the card grid for my Marvel Snap game on the deck builder page, it unlocked the final parts of that page for me. ย 

Having been able to define the grid for selecting cards to ADD to the deck, I could use a smaller-scale version of the same mechanism to build the Current Deck section of the deck builder page. ย  In the last update I created a flow that would automatically create placeholders for the 12 cards in my deck. ย Now that I know a deck will always contain 12 card slots and they may or may not have a card defined, then I can create my repeater to show the 12 cards.

Marvel Snap shows the โ€œin deckโ€ cards as smaller than the card selection cards so I followed that style decision:

Screenshot 2023 11 11 at 22 43 09

I have a data resource for the Deck record already, so I added some elements to the header that will retrieve the name of the Deck and Iโ€™m also adding an element that shows me the current number of cards (based on the deck record) so that I can debug my refresh feature:

Screenshot 2023 11 11 at 22 13 26 2x

Note that for some of the UI Builder stuff I mildly broke my โ€œno codeโ€ rule for some of the design stuff – Iโ€™m using some CSS code for text design and colouring backgrounds etc. ย Iโ€™m going to consider CSS to be โ€œnot codeโ€ for the purposes of this project. ย So far, apart from the CSS work, this has been 100% no code baby!

Below the header I built a repater following the pattern from part 7. ย  Because these cards are derived from my Deck files, I had to do some dotwalking to find the references to the card definition fields like image and ability, but all very doable. ย It involved a different data resource for the Player Card instances, but otherwise very similar to the previous pattern. ย Hereโ€™s the repeater:

Screenshot 2023 11 11 at 22 18 19

And hereโ€™s the Image component:

Screenshot 2023 11 11 at 22 18 06

Like the Card Selection section, I also added an event to udpate the Deck Modification Event table – this time Iโ€™m adding a โ€œremoveโ€ event to the queue on my card container (I used card containers because they support click events). ย I set the โ€œRemoveโ€ operation, set the status of the event to โ€œPendingโ€, then I set the card instance that Iโ€™m removing to the item unique value:

Screenshot 2023 11 11 at 22 20 02

The Deck Modification Event data resource has proven quite flexible – I can pass add and remove actions to it, and have different flows perform different activities based on the operation. ย I can also use the flows to update the status so I have an audit trail for troubleshooting. ย Very useful!

The subflows I built to act on the Deck Mod events are pretty simple – they will either remove the relationship from the instance or they will find the next empty slot (player card instance with no card definition) and add the card to that slot. ย In both cases the flows will update the total card count on the parent deck record. ย This becomes important later when I want to refresh the istance:

Screenshot 2023 11 11 at 22 26 13

I had to change my approach slightly – I no longer want to try to track a number that is incremented by 100 – Iโ€™m happy to just drop the card into the next available slot, ย itโ€™s going to be a bit janky in the UI, but weโ€™re not here to be completely polished, just to prove that we can do this.

Ok, so at this point I can click a card an trigger either an Add or Remove event. ย The flow engine will then pick these actions up from the queue based on the โ€œrecord is createdโ€ trigger and perform the relevant record updates. ย  This is great, but weโ€™re not seeing it appear in the instanceโ€ฆ this is where we need a record watcher data resource.

So basically the last action that the subflows for Add or Remove will do is scan all the current cards assigned to the deck and then tell the Deck record how many cards there are. ย This means that the last meaningful database update for each flow is an update to the Player Deck recordโ€™s โ€œnumber of cardsโ€ field. ย I want my UI to update every time this field is updatedโ€ฆ so I can use a Record watcher, and then use the Record Watcher to trigger a refresh of the Player Deck data resource:

Screenshot 2023 11 11 at 22 31 30

The refresh event will immediately tell the repeater that thereโ€™s new data, and it will redraw:

Screenshot 2023 11 11 at 22 31 45

Thereโ€™s still a few debug messages active, and it could use some polish, but the Deck Builder page is functionally complete at this stage – it can add and remove cards through a click on the card components in each area, and the whole thing was achieved with no code (excluding CSS). ย It looks ok too!:

Screenshot 2023 11 11 at 22 40 27 2x


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *