board icon indicating copy to clipboard operation
board copied to clipboard

Add `local` engine to read playback frames from NDJSON files.

Open Schoonology opened this issue 1 year ago • 1 comments

This reads the new playback-optimized replay files from rules, given the engine setting of "local". Files are, by default, read from process.cwd(), but can be read from another location via the REPLAYS_DIR environment variable.

In other words, asking for ?game=1234&engine=local will read from ${REPLAYS_DIR}/1234.ndjson.

Requested feedback (also left as TODO comments in context, in case we intend to address these in the future):

  • [ ] Do we have a file extension we would like to use in place of the not-quite-standard .ndjson?
  • [ ] Alongside that, do we want a delimiter between the first "game info" JSON line, and the frame lines? We could break with NDJSON and use --- like it's front matter, or use a JSON-compatible value like the empty object, {}.

Schoonology avatar Sep 18 '23 12:09 Schoonology

This code also isn't robust to a lot of edge cases, though in my experience it doesn't crash from things like missing files. (That might just be Vite catching and restarting, though.)

I'm happy to make this as resilient as y'all want before merging.

Schoonology avatar Sep 18 '23 12:09 Schoonology