SaveGame handle for the save editor bindings #446
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#446
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
Follow-up to #440 and #443. The save editor bindings pass the whole dump in and out:
sksave0.dat, 3.0 MB of it tile chains;graphics.datre-parse it, and in wasm copy its 8.6 MB first;language), so adding one breaks signatures.Measured natively on
sksave0.dat:save_to_json_fullsave_inventory_clear_json("cursor")save_inventory_jsonProposal
A
SaveGamehandle (wasm class, opaque FFIDm2SaveGame *, Python class) holding the decoded full save, edited in place.Construction:
new SaveGame(bytes, dungeon, graphics)replaces the decode ofsave_to_json_full, with the same checks: a mismatched dungeon is refused, and the rebuild must be byte-exact.SaveGame.fromJson(json, dungeon, graphics)loads a full dump.dungeonis aDungeonFileandgraphicsaGraphicsArchive. Only the map info the save needs is kept from the dungeon. Methods needinggraphics.dattake theGraphicsArchiveper call, asDungeonFiledoes: a wasm object cannot borrow another across calls.Methods, each with a trailing options object:
toJson()save_to_json_fulloutputtoBytes(graphics)save_from_json_fullgameplay()/setGameplay(json)gameplaysection (15 KB), so champion fields no longer move the record streaminventory(graphics)language(en)save_inventory_jsoncontainer(loc, graphics)language(en)save_container_jsonmoveItem(src, dst),swapItems(a, b),copyItem(src, dst),clearItem(loc)save_inventory_*putInContainer(src, container, graphics),takeFromContainer(container, index, dst, graphics)save_container_put/save_container_takecreateItem(dst, item, graphics)save_item_createpreviewItem(dst, item, graphics)language(en)save_item_previewfieldLimits()save_field_limits_json, the variant taken from the saveEdits return nothing, and a refused edit leaves the save unchanged.
GraphicsArchivegains the two calls that only readgraphics.dat:itemCatalog({language}), replacingitem_catalog_json;skillTitle(skill, level, {language}), replacingskill_title_json.These stay free:
save_to_json,save_from_jsonandsave_info_json(self-contained, bytes only, nothing to cache), andskill_levelandskill_experience_for_level(pure arithmetic).Naming:
SaveGameavoids clashing withdm2_saves::SaveFileand thedm2_save_*C exports.PRs:
GraphicsArchivemethods.SaveGame, additive.Acceptance
inventory()is measurably faster than the dump round trip in wasm (numbers in the PR).Out of scope
Editing tile chains, i.e. items on the dungeon floor.
https://claude.ai/code/session_01SnENBXnZbhNNrojZT5jbJ7