This repository was archived by the owner on Aug 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 238
Expand file tree
/
Copy pathJSIL.js
More file actions
309 lines (236 loc) · 9.95 KB
/
JSIL.js
File metadata and controls
309 lines (236 loc) · 9.95 KB
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
"use strict";
//
// JSIL loader. Synchronously loads all core JSIL scripts, adds essential libraries to the content manifest,
// and loads your manifest scripts.
// Load this at the top of your document (optionally after declaring a jsilConfig dict in a previous script tag).
// Asset loading (after page load) is provided by JSIL.Browser.js.
//
(function (globalNamespace) {
if (typeof (globalNamespace.JSIL) !== "undefined")
throw new Error("JSIL.js loaded twice");
var JSIL = {
__FullName__: "JSIL"
};
Object.defineProperty(
globalNamespace, "JSIL",
{
value: JSIL,
configurable: false,
enumerable: true,
writable: false
}
);
JSIL.GlobalNamespace = globalNamespace;
if (typeof (globalNamespace.jsilConfig) !== "object")
globalNamespace.jsilConfig = {};
if (typeof (globalNamespace.contentManifest) !== "object")
globalNamespace.contentManifest = {};
})(this);
contentManifest["JSIL"] = [];
var $jsilloaderstate = {
environment: null,
loadFailures: []
};
(function loadJSIL (config) {
function Environment_Browser (config) {
var self = this;
this.config = config;
this.scriptIndex = 0;
this.scriptURIs = {};
window.$scriptLoadFailed = function (i) {
var uri = self.scriptURIs[i];
if (window.JSIL && window.JSIL.Host && window.JSIL.Host.logWriteLine)
JSIL.Host.logWriteLine("JSIL.js failed to load script '" + uri + "'");
else if (window.console && window.console.log)
console.error("JSIL.js failed to load script '" + uri + "'");
$jsilloaderstate.loadFailures.push([uri]);
if (config.onLoadFailure) {
try {
config.onLoadFailure(uri);
} catch (exc) {
}
}
}
contentManifest["JSIL"].push(["Library", "JSIL.Storage.js"]);
contentManifest["JSIL"].push(["Library", "JSIL.IO.js"]);
contentManifest["JSIL"].push(["Library", "JSIL.JSON.js"]);
contentManifest["JSIL"].push(["Library", "JSIL.XML.js"]);
};
Environment_Browser.prototype.getUserSetting = function (key) {
key = key.toLowerCase();
var query = window.location.search.substring(1);
var vars = query.split('&');
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');
if (decodeURIComponent(pair[0]).toLowerCase() === key) {
if (pair.length > 1)
return decodeURIComponent(pair[1]);
else
return true;
}
}
return false;
};
Environment_Browser.prototype.loadScript = function (uri) {
if (window.console && window.console.log)
window.console.log("Loading '" + uri + "'...");
this.scriptIndex += 1;
this.scriptURIs[this.scriptIndex] = uri;
document.write(
"<script type=\"text/javascript\" src=\"" + uri + "\" onerror=\"$scriptLoadFailed(" +
this.scriptIndex +
")\"></script>"
);
};
Environment_Browser.prototype.loadEnvironmentScripts = function () {
var libraryRoot = this.config.libraryRoot;
this.loadScript(libraryRoot + "JSIL.Browser.js");
this.loadScript(libraryRoot + "JSIL.Browser.Audio.js");
this.loadScript(libraryRoot + "JSIL.Browser.Loaders.js");
this.loadScript(libraryRoot + "JSIL.Browser.Touch.js");
};
function Environment_SpidermonkeyShell (config) {
var self = this;
this.config = config;
contentManifest["JSIL"].push(["Library", "JSIL.Storage.js"]);
contentManifest["JSIL"].push(["Library", "JSIL.IO.js"]);
contentManifest["JSIL"].push(["Library", "JSIL.XML.js"]);
};
Environment_SpidermonkeyShell.prototype.getUserSetting = function (key) {
// FIXME
return false;
};
Environment_SpidermonkeyShell.prototype.loadScript = function (uri) {
load(uri);
};
Environment_SpidermonkeyShell.prototype.loadEnvironmentScripts = function () {
this.loadScript(libraryRoot + "JSIL.Shell.js");
this.loadScript(libraryRoot + "JSIL.Shell.Loaders.js");
};
function Environment_WebWorker (config) {
var self = this;
this.config = config;
contentManifest["JSIL"].push(["Library", "JSIL.Storage.js"]);
contentManifest["JSIL"].push(["Library", "JSIL.IO.js"]);
contentManifest["JSIL"].push(["Library", "JSIL.XML.js"]);
};
Environment_WebWorker.prototype.getUserSetting = function (key) {
// FIXME
return false;
};
Environment_WebWorker.prototype.loadScript = function (uri) {
importScripts(uri);
};
Environment_WebWorker.prototype.loadEnvironmentScripts = function () {
this.loadScript(libraryRoot + "JSIL.WebWorker.js");
this.loadScript(libraryRoot + "JSIL.WebWorker.Loaders.js");
};
var environments = {
"browser": Environment_Browser,
"spidermonkey_shell": Environment_SpidermonkeyShell,
"webworker": Environment_WebWorker
}
if (!config.environment) {
if (typeof (window) !== "undefined")
config.environment = "browser";
else
throw new Error("jsilConfig.environment not set and no default available");
}
var environment;
if (typeof (config.environment) === "function") {
environment = $jsilloaderstate.environment = new (config.environment)(config);
} else if (typeof (config.environment) === "string") {
var environmentType = environments[config.environment];
if (!environmentType)
throw new Error("No environment named '" + config.environment + "' available.");
environment = $jsilloaderstate.environment = new (environmentType)(config);
}
if (typeof (config.libraryRoot) === "undefined")
config.libraryRoot = "../Libraries/";
var libraryRoot = config.libraryRoot;
var manifestRoot = (config.manifestRoot = config.manifestRoot || "");
config.scriptRoot = config.scriptRoot || "";
config.fileRoot = config.fileRoot || "";
config.assetRoot = config.assetRoot || "";
if (typeof (config.contentRoot) === "undefined")
config.contentRoot = "Content/";
if (typeof (config.fileVirtualRoot) === "undefined")
config.fileVirtualRoot = config.fileRoot || "";
if (config.printStackTrace)
environment.loadScript(libraryRoot + "printStackTrace.js");
if (config.webgl2d)
environment.loadScript(libraryRoot + "webgl-2d.js");
if (config.gamepad)
environment.loadScript(libraryRoot + "gamepad.js");
environment.loadScript(libraryRoot + "Polyfills.js");
environment.loadScript(libraryRoot + "mersenne.js");
if (config.typedObjects || false) {
environment.loadScript(libraryRoot + "typedobjects.js");
environment.loadScript(libraryRoot + "JSIL.TypedObjects.js");
}
environment.loadScript(libraryRoot + "JSIL.Core.js");
environment.loadScript(libraryRoot + "JSIL.Host.js");
environment.loadEnvironmentScripts();
environment.loadScript(libraryRoot + "JSIL.Core.Types.js");
environment.loadScript(libraryRoot + "JSIL.Core.Reflection.js");
environment.loadScript(libraryRoot + "JSIL.References.js");
environment.loadScript(libraryRoot + "JSIL.Unsafe.js");
environment.loadScript(libraryRoot + "JSIL.Bootstrap.js");
environment.loadScript(libraryRoot + "JSIL.Bootstrap.Int64.js");
environment.loadScript(libraryRoot + "JSIL.Bootstrap.DateTime.js");
environment.loadScript(libraryRoot + "JSIL.Bootstrap.Text.js");
environment.loadScript(libraryRoot + "JSIL.Bootstrap.Resources.js");
environment.loadScript(libraryRoot + "JSIL.Bootstrap.Linq.js");
environment.loadScript(libraryRoot + "JSIL.Bootstrap.Async.js");
if (config.interpreter || environment.getUserSetting("interpreter"))
environment.loadScript(libraryRoot + "JSIL.ExpressionInterpreter.js");
if (config.testFixture || environment.getUserSetting("testFixture"))
environment.loadScript(libraryRoot + "JSIL.TestFixture.js");
config.record |= Boolean(environment.getUserSetting("record"));
config.replayURI = environment.getUserSetting("replayURI") || config.replayURI;
config.replayName = environment.getUserSetting("replayName") || config.replayName;
config.fastReplay = config.fastReplay || environment.getUserSetting("fastReplay") || false;
config.autoPlay = config.autoPlay || environment.getUserSetting("autoPlay") || config.replayURI || config.replayName || false;
if (
config.record ||
config.replayURI ||
config.replayName
) {
environment.loadScript(libraryRoot + "JSIL.Replay.js");
}
config.disableSound = config.disableSound || environment.getUserSetting("disableSound") || false;
config.viewportScale = parseFloat((config.viewportScale || environment.getUserSetting("viewportScale") || 1.0).toString());
config.disableFiltering = config.disableFiltering || environment.getUserSetting("disableFiltering") || false;
config.enableFreezeAndSeal = config.enableFreezeAndSeal || environment.getUserSetting("enableFreezeAndSeal") || false;
var manifests = config.manifests || [];
for (var i = 0, l = manifests.length; i < l; i++)
environment.loadScript(manifestRoot + manifests[i] + ".manifest.js");
if (config.winForms || config.monogame) {
contentManifest["JSIL"].push(["Library", "System.Drawing.js"]);
contentManifest["JSIL"].push(["Library", "System.Windows.js"]);
}
if (config.xna) {
contentManifest["JSIL"].push(["Library", "XNA/XNA4.js"]);
switch (Number(config.xna)) {
case 4:
break;
default:
throw new Error("Unsupported XNA version");
}
contentManifest["JSIL"].push(["Library", "XNA/Content.js"]);
contentManifest["JSIL"].push(["Library", "XNA/Graphics.js"]);
contentManifest["JSIL"].push(["Library", "XNA/Input.js"]);
contentManifest["JSIL"].push(["Library", "XNA/Audio.js"]);
contentManifest["JSIL"].push(["Library", "XNA/Storage.js"]);
}
if (config.monogame) {
contentManifest["JSIL"].push(["Library", "MonoGame/OpenTK.js"]);
contentManifest["JSIL"].push(["Library", "MonoGame/OpenTK.GL.js"]);
contentManifest["JSIL"].push(["Library", "MonoGame/OpenTK.AL.js"]);
contentManifest["JSIL"].push(["Library", "MonoGame/SDL.js"]);
}
if (config.readOnlyStorage)
contentManifest["JSIL"].push(["Library", "JSIL.ReadOnlyStorage.js"]);
if (config.localStorage)
contentManifest["JSIL"].push(["Library", "JSIL.LocalStorage.js"]);
})(jsilConfig);