8000 Upload a premade game data JSON file as custom data by noahm · Pull Request #678 · noahm/DDRCardDraw · GitHub
[go: up one dir, main page]

Skip to content

Upload a premade game data JSON file as custom data - #678

Merged
noahm merged 2 commits into
partykitfrom
json-data-upload
Oct 23, 2026
Merged

noahm merged 2 commits into
partykitfrom
json-data-upload

Conversation

@noahm
@noahm noahm commented Oct 23, 2026 •
Copy link
Copy Markdown
Owner

Adds a third option to the Create Custom Data dialog, next to SMX edits and ITG packs: Upload a premade data file. You can pick a .json file there or drop one anywhere on the page.

  • Dropping: if the single dropped item is a .json file (by MIME type or extension), the dialog opens straight into the new form. Anything else is still treated as an ITG pack. The pendingPackDrop atom is now pendingDrop, which holds either a pack or a JSON file. The file is read out during the drop event, because the dropped item stops working once the event ends.
  • Checking: the file is checked against the game data schema in the browser before publishing. A bad file shows up to five readable errors and Publish stays disabled. The check now lives in a shared validateGameData() helper in game-data.atoms.ts, used by both this form and loadCustomGamedataByUrl.
  • Which schema: a file whose $schema points at https://data.ddr.tools/schema/*.json is checked against that schema, fetched live. That way files written for a schema newer than this build, like v2's required song.id, are still accepted. Files with no $schema, a relative path (as stock data uses) or any other host are checked against the bundled v1 copy. loadCustomGamedataByUrl follows the same rule, so a published v2 bundle loads back. The Worker still validates on upload.
  • Consistency checks: after the schema passes, the file gets the same checks yarn validate runs on bundled data: every declared style, difficulty and flag has a translation (and difficulties an $abbr), defaults exist, charts use known styles and diffClass values, folders and draw groups are present, and chart ids are unique. The checks now live in src/utils/game-data-consistency.ts, shared with scripts/validate.mjs, which imports it through Node's type stripping (validate:types:data silences Node's typeless-package warning). The jacket-exists check stays script-only. The loader doesn't run these checks, so bundles that are already published can't become unloadable.
  • Publishing: the file is published as-is through publishBundle with source: { kind: "json", fileName }. Then a config is created and opened, same as the other imports. The only change made to the file is the display name (i18n.en.name), which is pre-filled from the file's own name and falls back to the filename. The Worker needs no changes: it treats source as opaque and validates the file again itself.
  • Text: new strings in English and Japanese, and the drop hint now mentions .json files.

Caveats

  • A premade file's jacket paths are used exactly as written. Full URLs and smx/… paths will keep working. Other relative paths point at the app's bundled /jackets/, so they'll break once those move to the CDN in M3.
  • The Worker's 2 MB limit is only enforced on the server. A file over it gets the Worker's error message in the form.

Testing

  • Ran it end to end in Chromium against a local rgt-data Worker: dropped shine-2026.json, renamed it and published. The upload went through, the new config opened with that data selected, and the toast appeared.
  • A file missing required fields showed the schema errors and kept Publish disabled.
  • Picking a file from the chooser works too.
  • A copy missing a difficulty translation, with an untranslated flag and an unknown chart style, lists all four problems and keeps Publish disabled. yarn validate:types:data still passes on all stock data.
  • A v2 copy of shine-2026.json (with ids, without saHash/saIndex) that declares $schema: https://data.ddr.tools/schema/v2.json was validated against the live v2 schema, published (201) and loaded back. The same file without a $schema is still rejected against v1.
  • Types, lint and formatting all pass.

🤖 Generated with Claude Code

Adds a third source to the custom-data dialog alongside SMX edits and ITG
packs: pick (or drop anywhere on the page) a single .json file that
conforms to the Game Data schema, and it's published as-is to
data.ddr.tools like the other custom sets, so synced peers resolve the
same bytes. The file is validated client-side first so a bad file shows
readable schema errors; only the display name can be changed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel
vercel Bot commented Oct 23, 2026 •
Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
ddr-tools Ready Ready Preview Oct 23, 2026 5:47pm UTC

A file whose `$schema` points at data.ddr.tools/schema/*.json is now
checked against that schema, fetched live, instead of the v1 copy this
build bundles. That lets premade files written for v2 (required
song.id) through the upload form, and lets their published bundles
load back. Anything else keeps the bundled schema; the publish Worker
still validates on upload.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@noahm
noahm merged commit 08ae8cb into partykit Oct 23, 2026
7 checks passed
@noahm
noahm deleted the json-data-upload branch October 23, 2026 17:57
noahm added a commit that referenced this pull request Oct 26, 2026
Resolves conflicts with #678 and #679:
- validate.mjs now delegates to the shared findConsistencyErrors, so the
  duplicate song id check moves into src/utils/game-data-consistency.ts.
- loadCustomGamedataByUrl validates against the schema a bundle declares.
  Hosted v1 forbids `song.id`, so a bundle declaring a hosted schema is
  validated as published and upgraded afterwards; one held to the bundled
  v2 schema is upgraded first, as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch was successfully deployed

1 active deployment
Preview — 23352b93 Deployed Oct 23, 2026 by vercel[bot]
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.

1 participant

0