EmulatorJS/data/loader.js

64 lines
2.5 KiB
JavaScript
Raw Normal View History

(async function() {
const folderPath = (path) => path.substring(0, path.length - path.split('/').pop().length);
2023-07-03 15:49:28 +00:00
const scriptPath = (typeof window.EJS_pathtodata === "string") ? window.EJS_pathtodata : folderPath((new URL(document.currentScript.src)).pathname);
if (!scriptPath.endsWith('/')) scriptPath+='/';
//console.log(scriptPath);
function loadScript(file) {
return new Promise(function (resolve, reject) {
let script = document.createElement('script');
script.src = function() {
2023-07-03 15:49:28 +00:00
if ('undefined' != typeof EJS_paths && typeof EJS_paths[file] === 'string') {
return EJS_paths[file];
} else {
return scriptPath+file;
}
}();
script.onload = resolve;
document.head.appendChild(script);
})
}
function loadStyle(file) {
return new Promise(function(resolve, reject) {
let css = document.createElement('link');
css.rel = 'stylesheet';
css.href = function() {
2023-07-03 15:49:28 +00:00
if ('undefined' != typeof EJS_paths && typeof EJS_paths[file] === 'string') {
return EJS_paths[file];
} else {
return scriptPath+file;
}
}();
css.onload = resolve;
document.head.appendChild(css);
})
}
if (('undefined' != typeof EJS_DEBUG_XX && true === EJS_DEBUG_XX) || true) {
await loadScript('emulator.js');
await loadScript('nipplejs.js');
2023-06-29 16:49:48 +00:00
await loadScript('shaders.js');
2023-06-30 15:19:52 +00:00
await loadScript('storage.js');
2023-06-25 03:18:12 +00:00
await loadScript('gamepad.js');
await loadScript('GameManager.js');
await loadStyle('css/main.css');
}
const config = {};
2023-06-26 16:39:31 +00:00
config.gameUrl = window.EJS_gameUrl;
config.dataPath = scriptPath;
2023-06-26 16:39:31 +00:00
config.system = window.EJS_core;
config.biosUrl = window.EJS_biosUrl;
2023-07-01 18:15:26 +00:00
config.gameName = window.EJS_gameName;
config.color = window.EJS_color;
2023-07-01 18:59:39 +00:00
config.adUrl = window.EJS_AdUrl;
2023-07-01 19:06:16 +00:00
config.adTimer = window.EJS_AdTimer
config.VirtualGamepadSettings = window.EJS_VirtualGamepadSettings;
2023-07-01 19:15:00 +00:00
config.buttonOpts = window.EJS_Buttons;
2023-07-03 14:34:48 +00:00
config.volume = window.EJS_volume;
2023-07-03 15:49:28 +00:00
config.defaultControllers = window.EJS_defaultControls;
config.startOnLoad = window.EJS_startOnLoaded;
config.filePaths = window.EJS_paths;
2023-07-03 16:01:26 +00:00
config.loadState = window.EJS_loadStateURL;
new EmulatorJS(EJS_player, config);
})();