Add EJS_softLoad option

This commit is contained in:
Ethan O'Brien 2023-10-02 19:41:16 -05:00
parent 569db3dac7
commit eac73e2fc8
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]); this.FS.writeFile('/shader/'+shader, window.EJS_SHADERS[shader]);
} }
} }
clearEJSResetTimer() {
if (this.EJS.resetTimeout) {
clearTimeout(this.EJS.resetTimeout);
delete this.EJS.resetTimeout;
}
}
restart() { restart() {
this.clearEJSResetTimer();
this.functions.restart(); this.functions.restart();
} }
getState() { getState() {
@ -115,6 +122,7 @@ class EJS_GameManager {
this.FS.unlink('game.state'); this.FS.unlink('game.state');
} catch(e){} } catch(e){}
this.FS.writeFile('/game.state', state); this.FS.writeFile('/game.state', state);
this.clearEJSResetTimer();
this.functions.loadState("game.state", 0); this.functions.loadState("game.state", 0);
setTimeout(() => { setTimeout(() => {
try { try {
@ -141,6 +149,7 @@ class EJS_GameManager {
if (!slot) slot = 1; if (!slot) slot = 1;
(async () => { (async () => {
let name = slot + '-quick.state'; let name = slot + '-quick.state';
this.clearEJSResetTimer();
this.functions.loadState(name, 0); this.functions.loadState(name, 0);
})(); })();
} }
@ -310,6 +319,7 @@ class EJS_GameManager {
return (exists ? FS.readFile(this.getSaveFilePath()) : null); return (exists ? FS.readFile(this.getSaveFilePath()) : null);
} }
loadSaveFiles() { loadSaveFiles() {
this.clearEJSResetTimer();
this.functions.loadSaveFiles(); this.functions.loadSaveFiles();
} }
setFastForwardRatio(ratio) { setFastForwardRatio(ratio) {

View file

@ -1067,6 +1067,11 @@ class EmulatorJS {
args.push('/'+this.fileName); args.push('/'+this.fileName);
if (this.debug) console.log(args); if (this.debug) console.log(args);
this.Module.callMain(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.Module.resumeMainLoop();
this.checkSupportedOpts(); this.checkSupportedOpts();
this.setupSettingsMenu(); this.setupSettingsMenu();

View file

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