start on loaded, ejs_paths

This commit is contained in:
Ethan O'Brien 2023-07-03 10:49:28 -05:00
parent c3719b100e
commit 66076df1df
2 changed files with 22 additions and 6 deletions

View file

@ -94,6 +94,11 @@ class EmulatorJS {
downloadFile(path, cb, progressCB, notWithPath, opts) { downloadFile(path, cb, progressCB, notWithPath, opts) {
const basePath = notWithPath ? '' : this.config.dataPath; const basePath = notWithPath ? '' : this.config.dataPath;
path = basePath + path; path = basePath + path;
if (!notWithPath && this.config.filePaths) {
if (typeof this.config.filePaths[path.split('/').pop()] === "string") {
path = this.config.filePaths[path.split('/').pop()];
}
}
let url; let url;
try {url=new URL(path)}catch(e){}; try {url=new URL(path)}catch(e){};
if ((url && ['http:', 'https:'].includes(url.protocol)) || !url) { if ((url && ['http:', 'https:'].includes(url.protocol)) || !url) {
@ -271,10 +276,17 @@ class EmulatorJS {
this.touch = true; this.touch = true;
}) })
this.addEventListener(button, "click", this.startButtonClicked.bind(this)); this.addEventListener(button, "click", this.startButtonClicked.bind(this));
if (this.config.startOnLoad === true) {
this.startButtonClicked(button);
}
} }
startButtonClicked(e) { startButtonClicked(e) {
if (e.preventDefault) {
e.preventDefault(); e.preventDefault();
e.target.remove(); e.target.remove();
} else {
e.remove();
}
this.createText(); this.createText();
this.downloadGameCore(); this.downloadGameCore();
} }
@ -941,6 +953,8 @@ class EmulatorJS {
a.click(); a.click();
}); });
const loadState = addButton("Load State", '<svg viewBox="0 0 576 512"><path fill="currentColor" d="M572.694 292.093L500.27 416.248A63.997 63.997 0 0 1 444.989 448H45.025c-18.523 0-30.064-20.093-20.731-36.093l72.424-124.155A64 64 0 0 1 152 256h399.964c18.523 0 30.064 20.093 20.73 36.093zM152 224h328v-48c0-26.51-21.49-48-48-48H272l-64-64H48C21.49 64 0 85.49 0 112v278.046l69.077-118.418C86.214 242.25 117.989 224 152 224z"/></svg>', async () => { const loadState = addButton("Load State", '<svg viewBox="0 0 576 512"><path fill="currentColor" d="M572.694 292.093L500.27 416.248A63.997 63.997 0 0 1 444.989 448H45.025c-18.523 0-30.064-20.093-20.731-36.093l72.424-124.155A64 64 0 0 1 152 256h399.964c18.523 0 30.064 20.093 20.73 36.093zM152 224h328v-48c0-26.51-21.49-48-48-48H272l-64-64H48C21.49 64 0 85.49 0 112v278.046l69.077-118.418C86.214 242.25 117.989 224 152 224z"/></svg>', async () => {
const called = this.callEvent("load");
if (called > 0) return;
const file = await this.selectFile(); const file = await this.selectFile();
const state = new Uint8Array(await file.arrayBuffer()); const state = new Uint8Array(await file.arrayBuffer());
this.gameManager.loadState(state); this.gameManager.loadState(state);

View file

@ -1,13 +1,13 @@
(async function() { (async function() {
const folderPath = (path) => path.substring(0, path.length - path.split('/').pop().length); const folderPath = (path) => path.substring(0, path.length - path.split('/').pop().length);
const scriptPath = folderPath((new URL(document.currentScript.src)).pathname); const scriptPath = (typeof window.EJS_pathtodata === "string") ? window.EJS_pathtodata : folderPath((new URL(document.currentScript.src)).pathname);
if (!scriptPath.endsWith('/')) scriptPath+='/'; if (!scriptPath.endsWith('/')) scriptPath+='/';
//console.log(scriptPath); //console.log(scriptPath);
function loadScript(file) { function loadScript(file) {
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
let script = document.createElement('script'); let script = document.createElement('script');
script.src = function() { script.src = function() {
if ('undefined' != typeof EJS_paths && typeof EJS_paths[file] == 'string') { if ('undefined' != typeof EJS_paths && typeof EJS_paths[file] === 'string') {
return EJS_paths[file]; return EJS_paths[file];
} else { } else {
return scriptPath+file; return scriptPath+file;
@ -22,7 +22,7 @@
let css = document.createElement('link'); let css = document.createElement('link');
css.rel = 'stylesheet'; css.rel = 'stylesheet';
css.href = function() { css.href = function() {
if ('undefined' != typeof EJS_paths && typeof EJS_paths[file] == 'string') { if ('undefined' != typeof EJS_paths && typeof EJS_paths[file] === 'string') {
return EJS_paths[file]; return EJS_paths[file];
} else { } else {
return scriptPath+file; return scriptPath+file;
@ -54,7 +54,9 @@
config.VirtualGamepadSettings = window.EJS_VirtualGamepadSettings; config.VirtualGamepadSettings = window.EJS_VirtualGamepadSettings;
config.buttonOpts = window.EJS_Buttons; config.buttonOpts = window.EJS_Buttons;
config.volume = window.EJS_volume; config.volume = window.EJS_volume;
config.defaultControllers = window.EJS_defaultControls config.defaultControllers = window.EJS_defaultControls;
config.startOnLoad = window.EJS_startOnLoaded;
config.filePaths = window.EJS_paths;
new EmulatorJS(EJS_player, config); new EmulatorJS(EJS_player, config);