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

@ -1,5 +1,6 @@
#include "GameEngine.h"
#include "ActionCode.h"
#include <sys/stat.h>
#include "McRFPy_API.h"
#include "PyScene.h"
#include "UITestScene.h"
@ -77,6 +78,15 @@ GameEngine::GameEngine(const McRogueFaceConfig& cfg)
Resources::font.loadFromFile("./assets/JetbrainsMono.ttf");
Resources::game = this;
window_title = "McRogueFace Engine";
// Ensure save/ directory exists for persistent game data
#ifndef __EMSCRIPTEN__
// Desktop: create save/ in working directory (WASM uses IDBFS mount from JS)
struct stat st;
if (stat("save", &st) != 0) {
mkdir("save", 0755);
}
#endif
// Initialize rendering based on headless mode
if (headless) {