Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add local engine to read playback frames from NDJSON files. #75

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Schoonology
Copy link

@Schoonology Schoonology commented Sep 18, 2023

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, {}.

Uses a single environment variable and a GET /replays/{id} with two
fields: `info` metadata and `frames` replay.
@Schoonology
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant