(include raylib.h) (include stdlib.h) (include string.h) #+emscripten (include emscripten.h) ;; Native storage lives under the XDG config directory. Web storage is the ;; IDBFS mount created by shell.html and backed by IndexedDB. #-emscripten (pub fn storage-save-dir () (* const char) (var base (* char) (getenv "XDG_CONFIG_HOME")) (if (! (|| (== base NULL) (== (strlen base) 0))) (return (TextFormat "%s/catch-phase" base))) (= base (getenv "HOME")) (if (|| (== base NULL) (== (strlen base) 0)) (return (TextFormat "%s/catch-phase" "."))) (return (TextFormat "%s/.config/catch-phase" base))) #+emscripten (pub fn storage-save-dir () (* const char) (return "/persist")) (pub fn storage-settings-path () (* const char) (return (TextFormat "%s/settings.conf" (storage-save-dir)))) #-emscripten (pub fn storage-init () void (var dir (* const char) (storage-save-dir)) (if (!= (MakeDirectory dir) 0) (TraceLog LOG-WARNING "failed to create settings directory \"%s\"" dir))) #+emscripten (pub fn storage-init () void ;; shell.html mounts /persist and waits for the initial sync before main(). (return)) #-emscripten (pub fn storage-sync () void (return)) #+emscripten (pub fn storage-sync () void (emscripten-run-script "Module.FS.syncfs(false, function (e) { if (e) console.error('Catch-Phase: failed to persist storage', e); });"))