Ability to load state on start

This commit is contained in:
Ethan O'Brien 2023-07-03 11:01:26 -05:00
parent 66076df1df
commit 96ad084485
2 changed files with 27 additions and 4 deletions

View file

@ -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);

View file

@ -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);