UNPKG

2 kBJavaScriptView Raw
1window.addEventListener("load", function() {
2 var resource = new client.ResourceFactory();
3 resource.createScriptAsset = function(id, assetPath) {
4 return new SandboxScriptAsset(id, assetPath);
5 }
6
7 function onLoadGameConfiguration(asset) {
8 if (!window.maxAge || window.maxAge != parseInt(window.maxAge) || window.maxAge <= 0) {
9 window.alert("invalid maxAge:" + window.maxAge);
10 return;
11 }
12
13 var conf = JSON.parse(asset.data);
14 var browser = new client.BrowserGame("scene", conf.width, conf.height, document.getElementById("container"));
15
16 // 扱えるパラメータ
17 console.log("window.maxAge=" + window.maxAge);
18 console.log("window.renderPerFrame=" + window.renderPerFrame);
19 console.log("window.loopCount=" + window.loopCount);
20
21 var game;
22 var beginTime = +(new Date());
23 if (window.renderPerFrame!==undefined && window.maxAge!==undefined) { // 他のパラメータはoptional
24 game = new Game(conf, resource, "/test/");
25 browser.start(game, "/test/");
26 game.loopCount = window.loopCount!==undefined ? window.loopCount : game.loopCount;
27 game.startCheck(window.maxAge, window.renderPerFrame, function() {
28 var elapse = +(new Date()) - beginTime;
29 document.location.href = "/next/?elapse=" + elapse;
30 });
31 } else {
32 console.log("use derived Game class");
33 game = new client.Game(conf, resource, "/test/");
34 game.beforeTickTrigger.handle(function(age) {
35 if (age == window.maxAge) {
36 var elapse = +(new Date()) - beginTime;
37 document.location.href = "/next/?elapse=" + elapse;
38 }
39 });
40 browser.start(game, "/test/");
41 }
42 }
43
44 resource.createTextAsset("", "./game.json")._load({
45 _onAssetLoad: onLoadGameConfiguration,
46 _onAssetError: function () {
47 throw new Error("Could not read game.json");
48 }
49 });
50});
51client.AudioPluginRegistry.addPlugin(client.WebAudioPlugin, client.HTMLAudioPlugin);
52window.KeyboardOperationPlugin = client.KeyboardOperationPlugin;
53window.TestMouseFlickOperationPlugin = client.TestMouseFlickOperationPlugin;