bindings: SaveGame without dungeon.dat and graphics.dat #453

Closed
opened 2026-10-31 09:31:34 +01:00 by jqueuniet · 1 comment
Owner

A save opened without its dungeon.dat and graphics.dat has no handle: it still goes through saveToJson, saveFromJson and saveFieldLimitsJson, the last one duplicating SaveGame.fieldLimits. Consumers keep two code paths for one file type.

Proposal

A SaveGame that can open without context (e.g. a SaveGame.limited(bytes) constructor, or optional context arguments): toJson, toBytes, gameplay, setGameplay and fieldLimits work; item methods refuse. Context can be supplied later, reloading the save as edited so far.

Acceptance

  • A save without context is read, edited and rebuilt through SaveGame alone.
A save opened without its `dungeon.dat` and `graphics.dat` has no handle: it still goes through `saveToJson`, `saveFromJson` and `saveFieldLimitsJson`, the last one duplicating `SaveGame.fieldLimits`. Consumers keep two code paths for one file type. ## Proposal A `SaveGame` that can open without context (e.g. a `SaveGame.limited(bytes)` constructor, or optional context arguments): `toJson`, `toBytes`, `gameplay`, `setGameplay` and `fieldLimits` work; item methods refuse. Context can be supplied later, reloading the save as edited so far. ## Acceptance - A save without context is read, edited and rebuilt through `SaveGame` alone.
Author
Owner

Deviations in #458:

  • wasm constructors: wasm uses SaveGame.limited(bytes) and SaveGame.limitedFromJson(json) instead of optional context arguments. wasm-bindgen 0.2.129 cannot take Option<&DungeonFile>.
  • Optional arguments elsewhere: Python does take them (SaveGame(data), SaveGame.from_json(dump)). C has dm2_save_game_open_limited and dm2_save_game_from_json_limited.
  • Supplying context later: attach(dungeon, graphics) does it. It refuses a save that already has its files (ContextAttached) and leaves the save unchanged on a mismatch. hasContext() tells the two states apart.
  • Free functions: save_to_json, save_from_json and save_field_limits_json are removed. save_info_json, the lossy gameplay-only view, stays free; it could become a SaveGame method later.

https://claude.ai/code/session_01SnENBXnZbhNNrojZT5jbJ7

Deviations in #458: - **wasm constructors:** wasm uses `SaveGame.limited(bytes)` and `SaveGame.limitedFromJson(json)` instead of optional context arguments. wasm-bindgen 0.2.129 cannot take `Option<&DungeonFile>`. - **Optional arguments elsewhere:** Python does take them (`SaveGame(data)`, `SaveGame.from_json(dump)`). C has `dm2_save_game_open_limited` and `dm2_save_game_from_json_limited`. - **Supplying context later:** `attach(dungeon, graphics)` does it. It refuses a save that already has its files (`ContextAttached`) and leaves the save unchanged on a mismatch. `hasContext()` tells the two states apart. - **Free functions:** `save_to_json`, `save_from_json` and `save_field_limits_json` are removed. `save_info_json`, the lossy gameplay-only view, stays free; it could become a `SaveGame` method later. https://claude.ai/code/session_01SnENBXnZbhNNrojZT5jbJ7
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
jqueuniet/dm2-tools#453
No description provided.