mirror of
https://github.com/EmulatorJS/EmulatorJS.git
synced 2024-09-20 02:46:23 +00:00
Ability to load state on start
This commit is contained in:
parent
66076df1df
commit
96ad084485
2 changed files with 27 additions and 4 deletions
|
@ -498,11 +498,34 @@ class EmulatorJS {
|
||||||
parts.splice(parts.length-1, 1);
|
parts.splice(parts.length-1, 1);
|
||||||
return parts.join(".");
|
return parts.join(".");
|
||||||
}
|
}
|
||||||
downloadBios() {
|
downloadStartState() {
|
||||||
if (!this.config.biosUrl) {
|
if (typeof this.config.loadState !== "string") {
|
||||||
this.startGame();
|
this.startGame();
|
||||||
return;
|
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");
|
this.textElem.innerText = this.localization("Download Game BIOS");
|
||||||
const gotBios = (data) => {
|
const gotBios = (data) => {
|
||||||
this.checkCompression(new Uint8Array(data), this.localization("Decompress Game BIOS")).then((data) => {
|
this.checkCompression(new Uint8Array(data), this.localization("Decompress Game BIOS")).then((data) => {
|
||||||
|
@ -515,7 +538,7 @@ class EmulatorJS {
|
||||||
console.log(k.split('/').pop());
|
console.log(k.split('/').pop());
|
||||||
FS.writeFile(k.split('/').pop(), data[k]);
|
FS.writeFile(k.split('/').pop(), data[k]);
|
||||||
}
|
}
|
||||||
this.startGame();
|
this.downloadStartState();
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -541,7 +564,6 @@ class EmulatorJS {
|
||||||
}, true, {responseType: "arraybuffer", method: "GET"});
|
}, true, {responseType: "arraybuffer", method: "GET"});
|
||||||
})
|
})
|
||||||
}, null, true, {method: "HEAD"})
|
}, null, true, {method: "HEAD"})
|
||||||
|
|
||||||
}
|
}
|
||||||
downloadRom() {
|
downloadRom() {
|
||||||
this.gameManager = new window.EJS_GameManager(this.Module);
|
this.gameManager = new window.EJS_GameManager(this.Module);
|
||||||
|
|
|
@ -57,6 +57,7 @@
|
||||||
config.defaultControllers = window.EJS_defaultControls;
|
config.defaultControllers = window.EJS_defaultControls;
|
||||||
config.startOnLoad = window.EJS_startOnLoaded;
|
config.startOnLoad = window.EJS_startOnLoaded;
|
||||||
config.filePaths = window.EJS_paths;
|
config.filePaths = window.EJS_paths;
|
||||||
|
config.loadState = window.EJS_loadStateURL;
|
||||||
|
|
||||||
new EmulatorJS(EJS_player, config);
|
new EmulatorJS(EJS_player, config);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue