Add EJS_softLoad option

This commit is contained in:
Ethan O'Brien 2023-10-02 19:41:16 -05:00
parent 9477a7d25e
commit 1f8ffceb51
3 changed files with 16 additions and 0 deletions

View file

@ -81,7 +81,14 @@ class EJS_GameManager {
this.FS.writeFile('/shader/'+shader, window.EJS_SHADERS[shader]);
}
}
clearEJSResetTimer() {
if (this.EJS.resetTimeout) {
clearTimeout(this.EJS.resetTimeout);
delete this.EJS.resetTimeout;
}
}
restart() {
this.clearEJSResetTimer();
this.functions.restart();
}
getState() {
@ -115,6 +122,7 @@ class EJS_GameManager {
this.FS.unlink('game.state');
} catch(e){}
this.FS.writeFile('/game.state', state);
this.clearEJSResetTimer();
this.functions.loadState("game.state", 0);
setTimeout(() => {
try {
@ -141,6 +149,7 @@ class EJS_GameManager {
if (!slot) slot = 1;
(async () => {
let name = slot + '-quick.state';
this.clearEJSResetTimer();
this.functions.loadState(name, 0);
})();
}
@ -310,6 +319,7 @@ class EJS_GameManager {
return (exists ? FS.readFile(this.getSaveFilePath()) : null);
}
loadSaveFiles() {
this.clearEJSResetTimer();
this.functions.loadSaveFiles();
}
setFastForwardRatio(ratio) {

View file

@ -1067,6 +1067,11 @@ class EmulatorJS {
args.push('/'+this.fileName);
if (this.debug) console.log(args);
this.Module.callMain(args);
if (typeof this.config.softLoad === "number" && this.config.softLoad > 0) {
this.resetTimeout = setTimeout(() => {
this.gameManager.restart();
}, this.config.softLoad * 1000);
}
this.Module.resumeMainLoop();
this.checkSupportedOpts();
this.setupSettingsMenu();

View file

@ -81,6 +81,7 @@
config.threads = window.EJS_threads;
config.disableCue = window.EJS_disableCue;
config.startBtnName = window.EJS_startButtonName;
config.softLoad = window.EJS_softLoad;
if (typeof window.EJS_language === "string" && window.EJS_language !== "en-US") {
try {