Your cart is currently empty!
Part 3: Importing Images using Flow Designer
Part of building out my Marvel Snap clone involved finding a source for the Card data. ย As mentioned earlier, I found a great database of cards that had an API that I could use to get the card records. ย The next thing I needed to do was import the images themselves. ย I created an Image field on the Card Definition record, but I needed to bring the images in via an automated method.
Looking at the card database website, I found that the images were stored in a folder:
https://images.marvelsnap.io/images/cards
Each image was stored as a .webp file. ย This doesnโt help me, because the image field type doesnโt support webp filesโฆ Luckily the database I was grabbing my cards from also had a JPG version in the same folder – very handy! ย The filenames were in the format <id>.jpg, so all I needed to do was substitute the card ID in the REST URL path to find the right file.ย
Using a Flow Designer action with a REST Step I could perform a GET on the URL of the JPG file:
ย
Flow Designer lets you save the payload as an attachment, and asks for a record and file name to write to the attachment table. ย In order to make an attachment in the attachment table map to a specific field (like an attachment or image field) we need to set the file name to match the field name.
ย
Technically if you attached file by hand to the image field, in the sys_attachment table for image files ServiceNow will prepend ZZ_YY to the table name (Which effectively stops the file from appearing in the โAttachmentโ section of the record, but this isnโt a dealbreaker for this implementation. ย If I was more worried about being clean with my implementation, Iโd go in to the attachment record after the fact and rename the table_name field.
Adding this Subflow to my existing card definition Subflow gives me a nice little โGet the card Definition, then add the imageโ automation:
Hereโs what the cards are starting to look like in my definition database:
ย
Next few things I think Iโll need to do:
– Start looking at what it will take to select my playerโs deck from my definition files (for example a Marvel Snap deck has 12 cards in it – how do we keep track of the number of cards in a deck?)
– Work on a shuffling/randomiser system for creating the active card instances for the playerโs deck
– Work on another card import for the Location cards (I might refactor my character card import mechanism so that it does two passes – one for location and one for character – right now itโs hard-coded to character only)
– Work on my โGame initialisationโ flow – Iโll need to start a game session, shuffle the locations into the right positions and ย shuffle each playerโs deck into card instances
– Work on all the flows for different player events (with decisions and dynamic subflows to execute the card subflows)
– Start creating ALL the subflows for each card (and probably a big library of subflows for different reusable behaviours).
Leave a Reply