From 2b22ec14c34f28615f75cec7fc421c9e4f22e940 Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi <3247106+gantoine@users.noreply.github.com> Date: Sun, 11 Feb 2024 01:44:13 -0500 Subject: [PATCH] Add hooks for savign and loading save files (#771) --- .gitignore | 1 + data/emulator.js | 11 +++++++++-- data/loader.js | 10 ++++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 435a7c3..96090a0 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ roms/ data/emulator.min.js data/emulator.min.css data/cores +.DS_Store diff --git a/data/emulator.js b/data/emulator.js index e3b79fa..3700ede 100644 --- a/data/emulator.js +++ b/data/emulator.js @@ -1719,7 +1719,7 @@ class EmulatorJS { let stateUrl; const saveState = addButton("Save State", '', async () => { const state = this.gameManager.getState(); - const called = this.callEvent("save", { + const called = this.callEvent("saveState", { screenshot: await this.gameManager.screenshot(), state: state }); @@ -1738,7 +1738,7 @@ class EmulatorJS { } }); const loadState = addButton("Load State", '', async () => { - const called = this.callEvent("load"); + const called = this.callEvent("loadState"); if (called > 0) return; if (this.settings['save-state-location'] === "browser" && this.saveInBrowserSupported()) { this.storage.states.get(this.getBaseFileName()+".state").then(e => { @@ -1767,6 +1767,11 @@ class EmulatorJS { const saveSavFiles = addButton("Export Save File", '', async () => { const file = await this.gameManager.getSaveFile(); + const called = this.callEvent("saveSave", { + screenshot: await this.gameManager.screenshot(), + save: file + }); + if (called > 0) return; const blob = new Blob([file]); savUrl = URL.createObjectURL(blob); const a = this.createElement("a"); @@ -1775,6 +1780,8 @@ class EmulatorJS { a.click(); }); const loadSavFiles = addButton("Import Save File", '', async () => { + const called = this.callEvent("loadSave"); + if (called > 0) return; const file = await this.selectFile(); const sav = new Uint8Array(await file.arrayBuffer()); const path = this.gameManager.getSaveFilePath(); diff --git a/data/loader.js b/data/loader.js index e5ec4ae..72aa02c 100644 --- a/data/loader.js +++ b/data/loader.js @@ -136,9 +136,15 @@ window.EJS_emulator.on("start", window.EJS_onGameStart); } if (typeof window.EJS_onLoadState === "function") { - window.EJS_emulator.on("load", window.EJS_onLoadState); + window.EJS_emulator.on("loadState", window.EJS_onLoadState); } if (typeof window.EJS_onSaveState === "function") { - window.EJS_emulator.on("save", window.EJS_onSaveState); + window.EJS_emulator.on("saveState", window.EJS_onSaveState); + } + if (typeof window.EJS_onLoadSave === "function") { + window.EJS_emulator.on("loadSave", window.EJS_onLoadSave); + } + if (typeof window.EJS_onSaveSave === "function") { + window.EJS_emulator.on("saveSave", window.EJS_onSaveSave); } })();