2022-02-22 15:56:48 +00:00
( async function ( ) {
2022-05-16 16:50:41 +00:00
var VERSION = 1.7 ;
2022-05-06 20:42:58 +00:00
if ( ( window . location && [ 'localhost' , '127.0.0.1' ] . includes ( location . hostname ) ) ||
'undefined' != typeof EJS _DEBUG _XX && true === EJS _DEBUG _XX ) {
2022-02-22 15:56:48 +00:00
fetch ( 'https://raw.githack.com/ethanaobrien/emulatorjs/main/data/version.json' ) . then ( response => {
if ( response . ok ) {
response . text ( ) . then ( body => {
var version = JSON . parse ( body ) ;
if ( VERSION < version . current _version ) {
2022-03-26 20:29:20 +00:00
console . log ( 'Using emulatorjs version ' + VERSION + ' but the newest version is ' + version . current _version + '\nopen https://github.com/ethanaobrien/emulatorjs to update' ) ;
2022-02-22 15:56:48 +00:00
}
} )
}
} )
}
2022-05-06 16:21:08 +00:00
var scriptTag = document . getElementsByTagName ( 'script' ) [ 0 ] ;
2022-05-16 16:45:45 +00:00
function loadStyle ( file ) {
return new Promise ( function ( resolve , reject ) {
var 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 if ( 'undefined' != typeof EJS _pathtodata ) {
if ( ! EJS _pathtodata . endsWith ( '/' ) ) EJS _pathtodata += '/' ;
return EJS _pathtodata + file + '?v=' + VERSION ;
} else {
return file + '?v=' + VERSION ;
}
} ( ) ;
css . onload = resolve ;
document . head . appendChild ( css ) ;
} )
}
2022-02-22 15:56:48 +00:00
function loadScript ( file ) {
return new Promise ( function ( resolve , reject ) {
var script = document . createElement ( 'script' ) ;
script . src = function ( ) {
if ( 'undefined' != typeof EJS _paths && typeof EJS _paths [ file ] == 'string' ) {
return EJS _paths [ file ] ;
} else if ( 'undefined' != typeof EJS _pathtodata ) {
2022-05-16 16:45:45 +00:00
if ( ! EJS _pathtodata . endsWith ( '/' ) ) EJS _pathtodata += '/' ;
2022-02-22 15:56:48 +00:00
return EJS _pathtodata + file + '?v=' + VERSION ;
} else {
return file + '?v=' + VERSION ;
}
} ( ) ;
scriptTag . parentNode . insertBefore ( script , scriptTag ) ;
2022-05-16 16:45:45 +00:00
script . onload = resolve ;
2022-02-22 15:56:48 +00:00
} )
}
if ( 'undefined' != typeof EJS _DEBUG _XX && true === EJS _DEBUG _XX ) {
2022-05-16 16:45:45 +00:00
await loadStyle ( 'emu-css.css' ) ;
2022-02-22 15:56:48 +00:00
await loadScript ( 'emu-main.js' ) ;
await loadScript ( 'emulator.js' ) ;
2022-01-05 00:17:43 +00:00
} else {
2022-05-16 16:45:45 +00:00
await loadStyle ( 'emu-css.min.css' ) ;
await loadScript ( 'emulator.min.js' ) ;
2022-01-05 00:17:43 +00:00
}
2022-02-22 15:56:48 +00:00
var config = { } ;
config . gameUrl = EJS _gameUrl ;
'undefined' != typeof EJS _mameCore && ( config . mameCore = EJS _mameCore ) ;
'undefined' != typeof EJS _biosUrl && ( config . biosUrl = EJS _biosUrl ) ;
'undefined' != typeof EJS _gameID && ( config . gameId = EJS _gameID ) ;
'undefined' != typeof EJS _gameParentUrl && ( config . gameParentUrl = EJS _gameParentUrl ) ;
'undefined' != typeof EJS _gamePatchUrl && ( config . gamePatchUrl = EJS _gamePatchUrl ) ;
'undefined' != typeof EJS _AdUrl && ( config . adUrl = EJS _AdUrl ) ;
'undefined' != typeof EJS _paths && ( config . paths = EJS _paths ) ;
'undefined' != typeof EJS _netplayUrl && ( config . netplayUrl = EJS _netplayUrl ) ;
'undefined' != typeof EJS _startOnLoaded && ( config . startOnLoad = EJS _startOnLoaded ) ;
'undefined' != typeof EJS _core && ( config . system = EJS _core ) ;
'undefined' != typeof EJS _loadStateURL && ( config . loadStateOnStart = EJS _loadStateURL ) ;
'undefined' != typeof EJS _language && ( config . lang = EJS _language ) ;
2022-05-16 16:45:45 +00:00
'undefined' != typeof EJS _noAutoCloseAd && ( config . noAutoAdClose = EJS _noAutoCloseAd ) ;
2022-02-22 15:56:48 +00:00
'undefined' != typeof EJS _oldEJSNetplayServer && ( config . oldNetplayServer = EJS _oldEJSNetplayServer ) ;
'undefined' != typeof EJS _BETA && ( config . useBeta = EJS _BETA ) ;
config . onsavestate = null ;
config . onloadstate = null ;
'undefined' != typeof EJS _onSaveState && ( config . onsavestate = EJS _onSaveState ) ;
'undefined' != typeof EJS _onLoadState && ( config . onloadstate = EJS _onLoadState ) ;
'undefined' != typeof EJS _lightgun && ( config . lightgun = EJS _lightgun ) ;
'undefined' != typeof EJS _gameName && ( config . gameName = EJS _gameName ) ;
'undefined' != typeof EJS _pathtodata && ( config . dataPath = EJS _pathtodata ) ;
'undefined' != typeof EJS _mouse && ( config . mouse = EJS _mouse ) ;
'undefined' != typeof EJS _multitap && ( config . multitap = EJS _multitap ) ;
'undefined' != typeof EJS _playerName && ( config . playerName = EJS _playerName ) ;
'undefined' != typeof EJS _cheats && ( config . cheats = EJS _cheats ) ;
'undefined' != typeof EJS _color && ( config . color = EJS _color ) ;
window . EJS _emulator = new EJS ( EJS _player , config ) ;
'undefined' != typeof EJS _onGameStart && EJS _emulator . on ( 'start-game' , EJS _onGameStart ) ;
} ) ( ) ;