feat(wasm): dm2-wasm browser bindings for the parser crates #314
No reviewers
Labels
No labels
area/ci-release
area/cli
area/docs
area/dungeon
area/ftl
area/graphics
area/gui
area/music
area/saves
area/tooling
port/amiga
port/dos
port/fm-towns
port/mac
port/pc98
port/sega-cd
priority/high
priority/low
priority/medium
type/bug
type/chore
type/docs
type/feature
type/research
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
jqueuniet/dm2-tools!314
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/wasm-bindings"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #301 — a new
dm2-wasmcrate that exposes the DM2 parser crates to the browser through wasm-bindgen.The premise held (and then some)
#301 guessed a WASM target should be "mostly free" because the parsers are pure-Rust and
&[u8]-driven. Verified: all eight parser crates compile towasm32-unknown-unknownunchanged, and no library code path touchesstd::fs/ time / threads / rng (every such call is confined to#[cfg(test)]orsrc/bin/). So this PR is a thin marshalling layer, not a port.Structure — three layers
core— purefn(&[u8]) -> Result<_, WasmError>functions. No#[wasm_bindgen], no JS types, so they are exercised directly by nativecargo testover real fixtures.error— oneWasmErrorunifying every wrapped crate's error via#[from]; itsDisplayis the JS-facing message. Kept wasm-free so native builds don't pull inJsError.wasm—#[wasm_bindgen]passthroughs (camelCasejs_names) that mapWasmError -> JsError, plus aconsole_error_panic_hookstart shim so Rust panics surface readably in the browser console.API surface (this slice: round-trip + all reads)
saveToJson/saveFromJson(byte-exact self-contained round-trip),saveInfoJson(lossy gameplay view)dungeonToJson/dungeonFromJson(byte-exact self-contained round-trip),dungeonSkprojectJson(lossy interop)graphicsHeaderJson,graphicsDecodePng(read-only)musicDetect,musicHmpToSmf,musicRenderModWav,musicSndToWav(read-only)ftlInfoJson,ftlRoundtripOk(read-only)The save/dungeon round-trip reuses the self-contained lossless JSON from #308/#309 — no external files, which is exactly the web-friendly form #307 identified. Byte order for dungeon/saves is auto-detected inside the crate by mirroring the CLI's try-both-endians pattern against public predicates.
Proof
MThd; MOD→WAV header valid; 19 FTL files round-tripped byte-exact (sega-cd-us + amiga-eu).cargo build -p dm2-wasm --target wasm32-unknown-unknownsucceeds; nativecargo build/teststill pass (wasm-bindgen compiles inertly off-target); fmt clean; no new clippy warning naming a crate file.wasm-pack build crates/dm2-wasm --target webis the documented package build (crate README carries the JS API table + a round-trip usage example).Scope / follow-ups
SaveDump::full, which needsdungeon.dat+graphics.datas inputs) is not exposed yet — the self-contained round-trip covers the browser edit flow without extra uploads. Easy to add later if a consumer wants field-level record-stream edits.Note for reviewers: the
.idea/dm2-tools.imlsource-folder entry the IDE auto-generates for the new crate was intentionally left out of the commit.https://claude.ai/code/session_01D3ec7SFejDHAwmCwbapMVV