diff --git a/src/emulator.js b/src/emulator.js index 6859508..e127f6b 100644 --- a/src/emulator.js +++ b/src/emulator.js @@ -498,11 +498,34 @@ class EmulatorJS { parts.splice(parts.length-1, 1); return parts.join("."); } - downloadBios() { - if (!this.config.biosUrl) { + downloadStartState() { + if (typeof this.config.loadState !== "string") { this.startGame(); return; } + this.textElem.innerText = this.localization("Download Game State"); + + this.downloadFile(this.config.loadState, (res) => { + if (res === -1) { + this.textElem.innerText = "Error"; + this.textElem.style.color = "red"; + return; + } + this.on("start", () => { + setTimeout(() => { + this.gameManager.loadState(new Uint8Array(res.data)); + }, 10); + }) + this.startGame(); + }, (progress) => { + this.textElem.innerText = this.localization("Download Game State") + progress; + }, true, {responseType: "arraybuffer", method: "GET"}); + } + downloadBios() { + if (typeof this.config.biosUrl !== "string") { + this.downloadStartState(); + return; + } this.textElem.innerText = this.localization("Download Game BIOS"); const gotBios = (data) => { this.checkCompression(new Uint8Array(data), this.localization("Decompress Game BIOS")).then((data) => { @@ -515,7 +538,7 @@ class EmulatorJS { console.log(k.split('/').pop()); FS.writeFile(k.split('/').pop(), data[k]); } - this.startGame(); + this.downloadStartState(); }) } @@ -541,7 +564,6 @@ class EmulatorJS { }, true, {responseType: "arraybuffer", method: "GET"}); }) }, null, true, {method: "HEAD"}) - } downloadRom() { this.gameManager = new window.EJS_GameManager(this.Module); diff --git a/src/loader.js b/src/loader.js index d3c2b68..79d7cde 100644 --- a/src/loader.js +++ b/src/loader.js @@ -57,6 +57,7 @@ config.defaultControllers = window.EJS_defaultControls; config.startOnLoad = window.EJS_startOnLoaded; config.filePaths = window.EJS_paths; + config.loadState = window.EJS_loadStateURL; new EmulatorJS(EJS_player, config);