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:

Screenshot 2023 11 03 at 09 58 47 2x

ย 

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.

Screenshot 2023 11 03 at 10 02 17 2x

ย 

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.

Screenshot 2023 11 03 at 10 05 01 2x

Adding this Subflow to my existing card definition Subflow gives me a nice little โ€œGet the card Definition, then add the imageโ€ automation:

Screenshot 2023 11 03 at 10 08 52 2x

Hereโ€™s what the cards are starting to look like in my definition database:

Screenshot 2023 11 03 at 10 09 41 2x

ย 

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).


Comments

Leave a Reply

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