This repository has been archived by the owner on Mar 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Solar.js
62 lines (51 loc) · 1.49 KB
/
Solar.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
function main() {
window.onload = function(){
window.Solar = {};
var keys = Object.keys(modules),
r = document.getElementsByTagName('script'),
values = {},
paths = [];
for(var i=0, len = keys.length; i < len; ++i) {
var val = modules[keys[i]];
Object.assign(values, val);
}
for(var key in values) {
Solar[values[key].split('.', 1)] = eval('('+key+')');
paths.push(values[key]);
}
for(var i = r.length; --i;) {
if(paths.indexOf(r[i].getAttribute('src')) !== -1) document.body.removeChild(r[i]);
}
}
}
var modules = {
core : {
Display : 'display.js',
InputController : 'input.js',
Math : 'math.js',
Matrix : 'matrix.js',
Rect : 'rect.js',
SoundLib : 'soundlib.js',
Surface : 'surface.js',
Timer : 'timer.js',
'Vector.vector2' : 'vector.js'
},
custom : {
}
};
function load() {
var keys = Object.keys(modules),
values = [];
for(var i=0, len = keys.length; i < len; ++i) {
var val = Object.keys(modules[keys[i]]).map(key => modules[keys[i]][key]);
Array.prototype.push.apply(values, val);
}
for(var i=0, len = values.length; i < len; ++i) {
var s = document.createElement('script');
s.src = values[i];
document.body.appendChild(s);
}
// Callback
main();
}
load();