FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
EmulatorJS/data/loader.js at main · allancoding/EmulatorJS · GitHub
allancoding
/
EmulatorJS
Public
forked from
EmulatorJS/EmulatorJS
Notifications
You must be signed in to change notification settings
Fork
1
Star
4
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
EmulatorJS
/
data
/
loader.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
262 lines (229 loc) · 8.63 KB
Breadcrumbs
EmulatorJS
/
data
/
loader.js
Copy path
File metadata and controls
262 lines (229 loc) · 8.63 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
const
folderPath
=
(
path
)
=>
{
const
filename
=
path
.
split
(
"/"
)
.
pop
(
)
;
return
path
.
substring
(
0
,
path
.
length
-
filename
.
length
)
;
}
;
let
scriptPath
=
(
typeof
window
.
EJS_pathtodata
===
"string"
)
?
window
.
EJS_pathtodata
:
folderPath
(
(
new
URL
(
document
.
currentScript
.
src
)
)
.
pathname
)
;
if
(
!
scriptPath
.
endsWith
(
"/"
)
)
{
scriptPath
+=
"/"
;
}
const
debug
=
window
.
EJS_DEBUG_XX
===
true
;
if
(
debug
)
{
console
.
log
(
"Script Path:"
,
scriptPath
)
;
}
function
resolvePath
(
path
)
{
let
resolved
;
if
(
"undefined"
!=
typeof
EJS_paths
&&
typeof
EJS_paths
[
path
]
===
"string"
)
{
resolved
=
EJS_paths
[
path
]
;
}
else
if
(
path
.
endsWith
(
"emulator.min.js"
)
||
path
.
endsWith
(
"css"
)
)
{
resolved
=
scriptPath
+
path
;
}
else
{
resolved
=
scriptPath
+
"src/"
+
path
;
}
return
new
URL
(
resolved
,
document
.
baseURI
)
.
href
;
}
async
function
loadScript
(
file
)
{
try
{
const
script
=
resolvePath
(
file
)
;
const
module
=
await
import
(
script
)
;
return
module
.
default
;
}
catch
(
e
)
{
if
(
debug
)
console
.
error
(
e
)
;
const
module
=
await
filesMissing
(
file
)
;
return
module
;
}
}
function
loadStyle
(
file
)
{
return
new
Promise
(
function
(
resolve
)
{
let
css
=
document
.
createElement
(
"link"
)
;
css
.
rel
=
"stylesheet"
;
css
.
href
=
resolvePath
(
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"
)
;
const
errorMessage
=
`Failed to load
${
file
}
because it's likely that the minified files are missing.
To fix this you have 3 options:
1. You can download the zip from the latest release here: https://github.com/EmulatorJS/EmulatorJS/releases/latest - Recommended
2. You can download the zip from here: https://cdn.emulatorjs.org/stable/data/emulator.min.zip and extract it to the data/ folder
3. You can build the files by running "npm i && npm run build" in the data/minify folder.`
;
console
[
minifiedFailed
?
"warn"
:
"error"
]
(
errorMessage
)
;
if
(
minifiedFailed
)
{
console
.
log
(
"Attempting to load non-minified files"
)
;
if
(
file
===
"emulator.min.js"
)
{
return
await
loadScript
(
"emulator.js"
)
;
}
else
{
await
loadStyle
(
"emulator.css"
)
;
}
}
}
function
getLanguagePath
(
language
)
{
if
(
"undefined"
!=
typeof
EJS_paths
&&
typeof
EJS_paths
[
language
]
===
"string"
)
{
return
{
path
:
EJS_paths
[
language
]
,
fallback
:
null
}
;
}
const
base
=
scriptPath
+
"localization/"
+
language
+
".json"
;
let
fallback
=
null
;
if
(
language
.
includes
(
"-"
)
||
language
.
includes
(
"_"
)
)
{
fallback
=
scriptPath
+
"localization/"
+
language
.
split
(
/
[
-
_
]
/
)
[
0
]
+
".json"
;
}
return
{
path
:
base
,
fallback
}
;
}
async
function
fetchJson
(
path
)
{
try
{
const
response
=
await
fetch
(
path
)
;
if
(
!
response
.
ok
)
throw
new
Error
(
`HTTP
${
response
.
status
}
`
)
;
return
await
response
.
json
(
)
;
}
catch
(
e
)
{
console
.
warn
(
"Failed to fetch language file:"
,
path
,
e
.
message
)
;
return
null
;
}
}
function
mergeLanguages
(
baseJson
,
overrideJson
)
{
if
(
!
baseJson
||
!
overrideJson
)
return
baseJson
||
overrideJson
||
{
}
;
return
{
...
baseJson
,
...
overrideJson
}
;
}
async
function
loadLanguage
(
config
)
{
const
defaultLangs
=
[
"en"
,
"en-US"
]
;
if
(
!
config
.
language
||
defaultLangs
.
includes
(
config
.
language
)
)
return
config
;
console
.
log
(
"Language:"
,
config
.
language
)
;
let
langData
=
{
}
;
const
paths
=
getLanguagePath
(
config
.
language
)
;
try
{
const
specificJson
=
await
fetchJson
(
paths
.
path
)
;
if
(
paths
.
fallback
)
{
const
fallbackJson
=
await
fetchJson
(
paths
.
fallback
)
;
langData
=
mergeLanguages
(
fallbackJson
,
specificJson
||
{
}
)
;
}
else
{
langData
=
specificJson
||
{
}
;
}
config
.
langJson
=
langData
;
}
catch
(
e
)
{
if
(
paths
.
fallback
)
{
const
fallbackLang
=
config
.
language
.
split
(
/
[
-
_
]
/
)
[
0
]
;
console
.
warn
(
`Language '
${
config
.
language
}
' not found, trying '
${
fallbackLang
}
'`
)
;
const
fallbackJson
=
await
fetchJson
(
paths
.
fallback
)
;
if
(
fallbackJson
)
{
langData
=
fallbackJson
;
config
.
langJson
=
langData
;
config
.
language
=
fallbackLang
;
}
}
else
{
console
.
warn
(
`No language file found for '
${
config
.
language
}
'`
)
;
delete
config
.
language
;
delete
config
.
langJson
;
}
}
return
config
;
}
const
config
=
{
debug
:
debug
,
gameUrl
:
window
.
EJS_gameUrl
,
dataPath
:
scriptPath
,
system
:
window
.
EJS_core
,
biosUrl
:
window
.
EJS_biosUrl
,
gameName
:
window
.
EJS_gameName
,
color
:
window
.
EJS_color
,
adUrl
:
window
.
EJS_AdUrl
,
adMode
:
window
.
EJS_AdMode
,
adTimer
:
window
.
EJS_AdTimer
,
adSize
:
window
.
EJS_AdSize
,
alignStartButton
:
window
.
EJS_alignStartButton
,
VirtualGamepadSettings
:
window
.
EJS_VirtualGamepadSettings
,
buttonOpts
:
window
.
EJS_Buttons
,
volume
:
window
.
EJS_volume
,
defaultControllers
:
window
.
EJS_defaultControls
,
startOnLoad
:
window
.
EJS_startOnLoaded
,
fullscreenOnLoad
:
window
.
EJS_fullscreenOnLoaded
,
filePaths
:
window
.
EJS_paths
,
loadState
:
window
.
EJS_loadStateURL
,
cacheLimit
:
window
.
EJS_CacheLimit
,
cacheConfig
:
window
.
EJS_cacheConfig
,
cheats
:
window
.
EJS_cheats
,
cheatPath
:
window
.
EJS_cheatPath
,
defaultOptions
:
window
.
EJS_defaultOptions
,
gamePatchUrl
:
window
.
EJS_gamePatchUrl
,
gameParentUrl
:
window
.
EJS_gameParentUrl
,
netplayUrl
:
window
.
EJS_netplayServer
,
netplayICEServers
:
window
.
EJS_netplayICEServers
,
gameId
:
window
.
EJS_gameID
,
backgroundImg
:
window
.
EJS_backgroundImage
,
backgroundBlur
:
window
.
EJS_backgroundBlur
,
backgroundColor
:
window
.
EJS_backgroundColor
,
controlScheme
:
window
.
EJS_controlScheme
,
threads
:
window
.
EJS_threads
,
disableCue
:
window
.
EJS_disableCue
,
startBtnName
:
window
.
EJS_startButtonName
,
softLoad
:
window
.
EJS_softLoad
,
capture
:
window
.
EJS_screenCapture
,
externalFiles
:
window
.
EJS_externalFiles
,
dontExtractRom
:
window
.
EJS_dontExtractRom
,
dontExtractBIOS
:
window
.
EJS_dontExtractBIOS
,
disableLocalStorage
:
window
.
EJS_disableLocalStorage
,
forceLegacyCores
:
window
.
EJS_forceLegacyCores
,
noAutoFocus
:
window
.
EJS_noAutoFocus
,
videoRotation
:
window
.
EJS_videoRotation
,
hideSettings
:
window
.
EJS_hideSettings
,
browserMode
:
window
.
EJS_browserMode
,
additionalShaders
:
window
.
EJS_shaders
,
fixedSaveInterval
:
window
.
EJS_fixedSaveInterval
,
disableAutoUnload
:
window
.
EJS_disableAutoUnload
,
disableBatchBootup
:
window
.
EJS_disableBatchBootup
,
askBeforeExit
:
window
.
EJS_askBeforeExit
}
;
async
function
prepareLanguage
(
)
{
try
{
const
systemLang
=
Intl
.
DateTimeFormat
(
)
.
resolvedOptions
(
)
.
locale
;
config
.
language
=
window
.
EJS_language
||
systemLang
;
if
(
config
.
language
&&
window
.
EJS_disableAutoLang
!==
false
)
{
return
await
loadLanguage
(
config
)
;
}
}
catch
(
e
)
{
console
.
warn
(
"Language detection failed:"
,
e
.
message
)
;
delete
config
.
language
;
delete
config
.
langJson
;
}
}
(
async
function
(
)
{
let
EmulatorJS
;
if
(
debug
)
{
EmulatorJS
=
await
loadScript
(
"emulator.js"
)
;
await
loadStyle
(
"emulator.css"
)
;
}
else
{
EmulatorJS
=
await
loadScript
(
"emulator.min.js"
)
;
await
loadStyle
(
"emulator.min.css"
)
;
}
if
(
!
EmulatorJS
)
{
console
.
error
(
"EmulatorJS failed to load. Check for missing files."
)
;
return
;
}
await
prepareLanguage
(
)
;
if
(
debug
)
{
console
.
log
(
"Language:"
,
config
.
language
)
;
console
.
log
(
"Language JSON loaded:"
,
!
!
config
.
langJson
)
;
}
window
.
EJS_emulator
=
new
EmulatorJS
(
EJS_player
,
config
)
;
window
.
EJS_adBlocked
=
(
url
,
del
)
=>
window
.
EJS_emulator
.
adBlocked
(
url
,
del
)
;
const
handlers
=
[
[
"ready"
,
window
.
EJS_ready
]
,
[
"start"
,
window
.
EJS_onGameStart
]
,
[
"loadState"
,
window
.
EJS_onLoadState
]
,
[
"saveState"
,
window
.
EJS_onSaveState
]
,
[
"loadSave"
,
window
.
EJS_onLoadSave
]
,
[
"saveSave"
,
window
.
EJS_onSaveSave
]
,
[
"exit"
,
window
.
EJS_onExit
]
]
;
handlers
.
forEach
(
(
[
event
,
callback
]
)
=>
{
if
(
typeof
callback
===
"function"
)
{
window
.
EJS_emulator
.
on
(
event
,
callback
)
;
}
}
)
;
if
(
typeof
window
.
EJS_onSaveUpdate
===
"function"
)
{
window
.
EJS_emulator
.
on
(
"saveUpdate"
,
window
.
EJS_onSaveUpdate
)
;
window
.
EJS_emulator
.
enableSaveUpdateEvent
(
)
;
}
}
)
(
)
;
Back
|
FazBrowse Home
|
New Git URL