mirror of
https://github.com/EmulatorJS/EmulatorJS.git
synced 2024-09-20 02:46:23 +00:00
Save file support
This commit is contained in:
parent
0f96beabf4
commit
36d2d61740
2 changed files with 27 additions and 10 deletions
|
@ -21,7 +21,8 @@ class EJS_GameManager {
|
|||
setCurrentDisk: this.Module.cwrap('set_current_disk', 'null', ['number']),
|
||||
getSaveFilePath: this.Module.cwrap('save_file_path', 'string', []),
|
||||
saveSaveFiles: this.Module.cwrap('cmd_savefiles', '', []),
|
||||
supportsStates: this.Module.cwrap('supports_states', 'number', [])
|
||||
supportsStates: this.Module.cwrap('supports_states', 'number', []),
|
||||
loadSaveFiles: this.Module.cwrap('refresh_save_files', 'null', [])
|
||||
}
|
||||
this.mkdir("/home");
|
||||
this.mkdir("/home/web_user");
|
||||
|
@ -33,7 +34,15 @@ class EJS_GameManager {
|
|||
|
||||
this.FS.writeFile("/home/web_user/retroarch/userdata/retroarch.cfg", this.getRetroArchCfg());
|
||||
|
||||
this.FS.mount(IDBFS, {}, '/data/saves');
|
||||
this.FS.syncfs(true, () => {});
|
||||
|
||||
this.initShaders();
|
||||
|
||||
this.EJS.addEventListener(window, "beforeunload", () => {
|
||||
this.saveSaveFiles();
|
||||
this.FS.syncfs(() => {});
|
||||
})
|
||||
}
|
||||
mkdir(path) {
|
||||
try {
|
||||
|
@ -41,7 +50,15 @@ class EJS_GameManager {
|
|||
} catch(e) {}
|
||||
}
|
||||
getRetroArchCfg() {
|
||||
return "autosave_interval = 10\nsavefile_directory = \"/data/saves\"\n";
|
||||
return "autosave_interval = 60\n" +
|
||||
"screenshot_directory = /\n" +
|
||||
"block_sram_overwrite = false\n" +
|
||||
"video_font_enable = false\n" +
|
||||
"video_scale = 1.0\n" +
|
||||
"video_gpu_screenshot = false\n" +
|
||||
"audio_latency = 96\n" +
|
||||
"video_vsync = true\n" +
|
||||
"savefile_directory = \"/data/saves\"\n";
|
||||
}
|
||||
initShaders() {
|
||||
if (!window.EJS_SHADERS) return;
|
||||
|
@ -217,18 +234,18 @@ class EJS_GameManager {
|
|||
}
|
||||
saveSaveFiles() {
|
||||
this.functions.saveSaveFiles();
|
||||
this.FS.syncfs(false, () => {});
|
||||
}
|
||||
supportsStates() {
|
||||
return !!this.functions.supportsStates();
|
||||
}
|
||||
getSaveFile() {
|
||||
return new Promise((resolve) => {
|
||||
this.saveSaveFiles();
|
||||
setTimeout(() => {
|
||||
const exists = FS.analyzePath(this.getSaveFilePath()).exists;
|
||||
resolve(exists ? FS.readFile(this.getSaveFilePath()) : null);
|
||||
}, 250);
|
||||
})
|
||||
return (exists ? FS.readFile(this.getSaveFilePath()) : null);
|
||||
}
|
||||
loadSaveFiles() {
|
||||
this.functions.loadSaveFiles();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1107,7 +1107,6 @@ class EmulatorJS {
|
|||
const state = new Uint8Array(await file.arrayBuffer());
|
||||
this.gameManager.loadState(state);
|
||||
}
|
||||
this.gameManager.saveSaveFiles();
|
||||
});
|
||||
const controlMenu = addButton("Control Settings", '<svg viewBox="0 0 640 512"><path fill="currentColor" d="M480 96H160C71.6 96 0 167.6 0 256s71.6 160 160 160c44.8 0 85.2-18.4 114.2-48h91.5c29 29.6 69.5 48 114.2 48 88.4 0 160-71.6 160-160S568.4 96 480 96zM256 276c0 6.6-5.4 12-12 12h-52v52c0 6.6-5.4 12-12 12h-40c-6.6 0-12-5.4-12-12v-52H76c-6.6 0-12-5.4-12-12v-40c0-6.6 5.4-12 12-12h52v-52c0-6.6 5.4-12 12-12h40c6.6 0 12 5.4 12 12v52h52c6.6 0 12 5.4 12 12v40zm184 68c-26.5 0-48-21.5-48-48s21.5-48 48-48 48 21.5 48 48-21.5 48-48 48zm80-80c-26.5 0-48-21.5-48-48s21.5-48 48-48 48 21.5 48 48-21.5 48-48 48z"/></svg>', () => {
|
||||
this.controlMenu.style.display = "";
|
||||
|
@ -1144,6 +1143,7 @@ class EmulatorJS {
|
|||
}
|
||||
if (FS.analyzePath(path).exists) FS.unlink(path);
|
||||
FS.writeFile(path, sav);
|
||||
this.gameManager.loadSaveFiles();
|
||||
});
|
||||
|
||||
const spacer = this.createElement("span");
|
||||
|
|
Loading…
Reference in a new issue