Taking advantage of Nim APIs, you'll be soon able to decode/encode JSON in this type safe way!
type
Equip = ref object
name: string
damage: Option[int] // optional value
Entity = ref object
name: string
enemy: bool
health: int
equip: seq[Equip] // list of equips
try:
let jsonString = playdate.file.open("/json/data.json", kFileRead).readString()
let entityObj = parseJson(jsonString).to(Entity) // Yay, type safe decoding
let encodedEntity = %* entityObj // %* is the operator to encode an object
except:
// ops, something went wrong, bad json file!
...
Love this! I’ve been thinking about using Nim for play date development for a few weeks now, so I’m glad to see someone else has already done the leg work. I’m pumped to give this a try
Developed a command line tool (spriterot, will be a Nim package too) to generate RotSprite rotations of images.
The idea is to have this tool do the repetitive task of generating rotated bitmap tables automatically at build time and ideally only when the source image has changed.
# By default, rotations are generated from 0 to 360 degrees
# Uses count in -rotations-<count> if no override is provided
spriterot ./helix_catcher_arm-rotations-16.png
Coupled with that, I'm working on adding a new utility object to the Nim bindings: LCDRotatableBitmap (name could change)
This object will load the automatically generated bitmap table and transparently draw its pre-rendered rotations with the same API of standard LCDBitmaps!
# Auto-resolves the filename
rotatableCatcherArm = try: newRotatableBitmap("/images/helix_catcher_arm", 16) except: nil
...
# Will draw using the rotated pre-rendered frames! Better performance!
rotatableCatcherArm.drawRotated(x, y, angle, 0.5, 0.5, 1, 1)
Here it is in action! (more than 16 frames of course!)
Also, the VSCode configuration to build and launch the simulator works on every platform now!
One more thing: while the average user will not have to deal with it, I'm starting to move the build system to a very simple CMake config that will let advanced users easily add libraries and other C code!