Cross-platform persistent save directory (IDBFS on WASM, filesystem on desktop)

Game code uses standard Python file I/O to mcrfpy.save_dir with no platform
branching. On WASM, builtins.open() is monkeypatched so writes to /save/
auto-sync IDBFS on close, making persistence transparent.

API: mcrfpy.save_dir (str), mcrfpy._sync_storage() (auto-called on WASM)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
John McCardle 2026-02-25 20:42:44 -05:00
commit e2d3e56968
7 changed files with 212 additions and 1 deletions

View file

@ -82,6 +82,18 @@
});
var Module = {
preRun: [function() {
// Mount IDBFS at /save/ for persistent game data
FS.mkdir('/save');
FS.mount(IDBFS, {}, '/save');
// Restore saved data from IndexedDB (synchronous before main())
Module.addRunDependency('idbfs-restore');
FS.syncfs(true, function(err) {
if (err) console.error('McRogueFace: Failed to restore /save/:', err);
else console.log('McRogueFace: /save/ restored from IndexedDB');
Module.removeRunDependency('idbfs-restore');
});
}],
print: function(text) {
if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
console.log(text);