2023-06-20 19:17:02 +00:00
( async function ( ) {
const folderPath = ( path ) => path . substring ( 0 , path . length - path . split ( '/' ) . pop ( ) . length ) ;
2023-08-26 15:49:05 +00:00
let scriptPath = ( typeof window . EJS _pathtodata === "string" ) ? window . EJS _pathtodata : folderPath ( ( new URL ( document . currentScript . src ) ) . pathname ) ;
2023-06-20 19:17:02 +00:00
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' ) {
2023-06-20 19:17:02 +00:00
return EJS _paths [ file ] ;
} else {
return scriptPath + file ;
}
} ( ) ;
script . onload = resolve ;
2024-01-16 18:39:16 +00:00
script . onerror = ( ) => {
filesmissing ( file ) . then ( e => resolve ( ) ) ;
}
2023-06-20 19:17:02 +00:00
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' ) {
2023-06-20 19:17:02 +00:00
return EJS _paths [ file ] ;
} else {
return scriptPath + file ;
}
} ( ) ;
css . onload = resolve ;
2024-01-16 18:39:16 +00:00
css . onerror = ( ) => {
filesmissing ( file ) . then ( e => resolve ( ) ) ;
}
2023-06-20 19:17:02 +00:00
document . head . appendChild ( css ) ;
} )
}
2024-01-16 18:39:16 +00:00
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' ) ;
} else {
await loadStyle ( 'emulator.css' ) ;
}
}
}
2023-06-20 19:17:02 +00:00
2023-07-18 16:10:21 +00:00
if ( ( 'undefined' != typeof EJS _DEBUG _XX && true === EJS _DEBUG _XX ) ) {
2023-06-20 19:17:02 +00:00
await loadScript ( 'emulator.js' ) ;
2023-06-24 17:42:10 +00:00
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' ) ;
2023-06-22 16:00:13 +00:00
await loadScript ( 'GameManager.js' ) ;
2023-07-17 14:00:32 +00:00
await loadScript ( 'socket.io.min.js' ) ;
2023-07-18 15:56:27 +00:00
await loadStyle ( 'emulator.css' ) ;
2023-07-18 16:10:21 +00:00
} else {
await loadScript ( 'emulator.min.js' ) ;
await loadStyle ( 'emulator.min.css' ) ;
2023-06-20 19:17:02 +00:00
}
const config = { } ;
2023-06-26 16:39:31 +00:00
config . gameUrl = window . EJS _gameUrl ;
2023-06-20 19:17:02 +00:00
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-08-13 15:10:33 +00:00
config . adMode = window . EJS _AdMode ;
2023-07-18 15:56:27 +00:00
config . adTimer = window . EJS _AdTimer ;
2023-08-13 15:10:33 +00:00
config . adSize = window . EJS _AdSize ;
2023-08-14 23:19:17 +00:00
config . alignStartButton = window . EJS _alignStartButton ;
2023-07-01 19:06:16 +00:00
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 ;
2023-08-12 16:10:30 +00:00
config . fullscreenOnLoad = window . EJS _fullscreenOnLoaded ;
2023-07-03 15:49:28 +00:00
config . filePaths = window . EJS _paths ;
2023-07-03 16:01:26 +00:00
config . loadState = window . EJS _loadStateURL ;
2023-07-03 16:16:44 +00:00
config . cacheLimit = window . EJS _CacheLimit ;
2023-07-03 16:25:22 +00:00
config . cheats = window . EJS _cheats ;
2023-07-03 16:43:59 +00:00
config . defaultOptions = window . EJS _defaultOptions ;
2023-07-11 16:30:27 +00:00
config . gamePatchUrl = window . EJS _gamePatchUrl ;
config . gameParentUrl = window . EJS _gameParentUrl ;
2023-07-15 20:10:56 +00:00
config . netplayUrl = window . EJS _netplayServer ;
2023-07-17 13:07:52 +00:00
config . gameId = window . EJS _gameID ;
2023-07-18 14:59:31 +00:00
config . backgroundImg = window . EJS _backgroundImage ;
2023-08-13 15:10:33 +00:00
config . backgroundBlur = window . EJS _backgroundBlur ;
config . backgroundColor = window . EJS _backgroundColor ;
2023-08-05 11:59:04 +00:00
config . controlScheme = window . EJS _controlScheme ;
2023-08-24 16:57:46 +00:00
config . threads = window . EJS _threads ;
2023-08-30 18:42:50 +00:00
config . disableCue = window . EJS _disableCue ;
2023-10-02 16:58:16 +00:00
config . startBtnName = window . EJS _startButtonName ;
2023-10-03 00:41:16 +00:00
config . softLoad = window . EJS _softLoad ;
2023-11-06 15:08:14 +00:00
config . screenRecording = window . EJS _screenRecording ;
2024-01-29 22:41:23 +00:00
config . externalFiles = window . EJS _externalFiles ;
2023-06-20 19:17:02 +00:00
2023-07-03 16:37:43 +00:00
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 = { } ;
}
}
2023-07-18 15:56:27 +00:00
window . EJS _emulator = new EmulatorJS ( EJS _player , config ) ;
2023-08-13 15:10:33 +00:00
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 ) ;
}
2023-07-18 15:56:27 +00:00
if ( typeof window . EJS _onGameStart === "function" ) {
window . EJS _emulator . on ( "start" , window . EJS _onGameStart ) ;
}
if ( typeof window . EJS _onLoadState === "function" ) {
window . EJS _emulator . on ( "load" , window . EJS _onLoadState ) ;
}
if ( typeof window . EJS _onSaveState === "function" ) {
window . EJS _emulator . on ( "save" , window . EJS _onSaveState ) ;
}
2023-08-24 16:57:46 +00:00
} ) ( ) ;