-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloader.js
154 lines (150 loc) · 7.2 KB
/
loader.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
(async function() {
const folderPath = (path) => path.substring(0, path.length - path.split('/').pop().length);
let 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() {
if ('undefined' != typeof EJS_paths && typeof EJS_paths[file] === 'string') {
return EJS_paths[file];
} else {
return scriptPath+file;
}
}();
script.onload = resolve;
script.onerror = () => {
filesmissing(file).then(e => 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() {
if ('undefined' != typeof EJS_paths && typeof EJS_paths[file] === 'string') {
return EJS_paths[file];
} else {
return scriptPath+file;
}
}();
css.onload = resolve;
css.onerror = () => {
filesmissing(file).then(e => resolve());
}
document.head.appendChild(css);
})
}
async function filesmissing(file) {
console.error("Failed to load " + file);
let minifiedFailed = file.includes(".min.") && !file.includes("socket");
console[minifiedFailed?"warn":"error"]("Failed to load " + file + " beacuse it's likly that the minified files are missing.\nTo fix this you have 3 options:\n1. You can download the zip from the latest release here: https://github.com/EmulatorJS/EmulatorJS/releases/latest - Stable\n2. You can download the zip from here: https://cdn.emulatorjs.org/latest/data/emulator.min.zip and extract it to the data/ folder. (easiest option) - Beta\n3. You can build the files by running `npm i && npm run build` in the data/minify folder. (hardest option) - Beta\nNote: you will probably need to do the same for the cores, extract them to the data/cores/ folder.");
if (minifiedFailed) {
console.log("Attempting to load non-minified files");
if (file === "emulator.min.js") {
await loadScript('emulator.js');
await loadScript('nipplejs.js');
await loadScript('shaders.js');
await loadScript('storage.js');
await loadScript('gamepad.js');
await loadScript('GameManager.js');
await loadScript('socket.io.min.js');
await loadScript('controls.js');
} else {
await loadStyle('emulator.css');
}
}
}
if (('undefined' != typeof EJS_DEBUG_XX && true === EJS_DEBUG_XX)) {
await loadScript('emulator.js');
await loadScript('nipplejs.js');
await loadScript('shaders.js');
await loadScript('storage.js');
await loadScript('gamepad.js');
await loadScript('GameManager.js');
await loadScript('socket.io.min.js');
await loadStyle('emulator.css');
} else {
await loadScript('emulator.min.js');
await loadStyle('emulator.min.css');
}
const config = {};
config.gameUrl = window.EJS_gameUrl;
config.dataPath = scriptPath;
config.system = window.EJS_core;
config.biosUrl = window.EJS_biosUrl;
config.gameName = window.EJS_gameName;
config.color = window.EJS_color;
config.adUrl = window.EJS_AdUrl;
config.adMode = window.EJS_AdMode;
config.adTimer = window.EJS_AdTimer;
config.adSize = window.EJS_AdSize;
config.alignStartButton = window.EJS_alignStartButton;
config.VirtualGamepadSettings = window.EJS_VirtualGamepadSettings;
config.buttonOpts = window.EJS_Buttons;
config.volume = window.EJS_volume;
config.defaultControllers = window.EJS_defaultControls;
config.startOnLoad = window.EJS_startOnLoaded;
config.fullscreenOnLoad = window.EJS_fullscreenOnLoaded;
config.filePaths = window.EJS_paths;
config.loadState = window.EJS_loadStateURL;
config.cacheLimit = window.EJS_CacheLimit;
config.cheats = window.EJS_cheats;
config.defaultOptions = window.EJS_defaultOptions;
config.gamePatchUrl = window.EJS_gamePatchUrl;
config.gameParentUrl = window.EJS_gameParentUrl;
config.netplayUrl = window.EJS_netplayServer;
config.gameId = window.EJS_gameID;
config.backgroundImg = window.EJS_backgroundImage;
config.backgroundBlur = window.EJS_backgroundBlur;
config.backgroundColor = window.EJS_backgroundColor;
config.controlScheme = window.EJS_controlScheme;
config.threads = window.EJS_threads;
config.disableCue = window.EJS_disableCue;
config.startBtnName = window.EJS_startButtonName;
config.softLoad = window.EJS_softLoad;
config.screenRecording = window.EJS_screenRecording;
config.externalFiles = window.EJS_externalFiles;
config.disableDatabases = window.EJS_disableDatabases;
config.disableLocalStorage = window.EJS_disableLocalStorage;
config.forceLegacyCores = window.EJS_forceLegacyCores;
config.noAutoFocus = window.EJS_noAutoFocus;
config.shaders = Object.assign({}, window.EJS_SHADERS, window.EJS_shaders ? window.EJS_shaders : {});
if (typeof window.EJS_language === "string" && window.EJS_language !== "en-US") {
try {
let path;
if ('undefined' != typeof EJS_paths && typeof EJS_paths[window.EJS_language] === 'string') {
path = EJS_paths[window.EJS_language];
} else {
path = scriptPath+"localization/"+window.EJS_language+".json";
}
config.language = window.EJS_language;
config.langJson = JSON.parse(await (await fetch(path)).text());
} catch(e) {
config.langJson = {};
}
}
window.EJS_emulator = new EmulatorJS(EJS_player, config);
window.EJS_adBlocked = (url, del) => window.EJS_emulator.adBlocked(url, del);
if (typeof window.EJS_ready === "function") {
window.EJS_emulator.on("ready", window.EJS_ready);
}
if (typeof window.EJS_onGameStart === "function") {
window.EJS_emulator.on("start", window.EJS_onGameStart);
}
if (typeof window.EJS_onLoadState === "function") {
window.EJS_emulator.on("loadState", window.EJS_onLoadState);
}
if (typeof window.EJS_onSaveState === "function") {
window.EJS_emulator.on("saveState", window.EJS_onSaveState);
}
if (typeof window.EJS_onLoadSave === "function") {
window.EJS_emulator.on("loadSave", window.EJS_onLoadSave);
}
if (typeof window.EJS_onSaveSave === "function") {
window.EJS_emulator.on("saveSave", window.EJS_onSaveSave);
}
})();