]> icculus.org git repositories - taylor/freespace2.git/blob - dist/demo-play.js.in
fix up command line options:
[taylor/freespace2.git] / dist / demo-play.js.in
1 var progress_bar = document.getElementById('progress_bar');
2 var progress_text = document.getElementById('progress_text');
3
4 var Module = {
5   preRun: [],
6   postRun: [],
7   print: (function() {
8     return function(text) {
9       if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
10       // These replacements are necessary if you render to raw HTML
11       //text = text.replace(/&/g, "&");
12       //text = text.replace(/</g, "&lt;");
13       //text = text.replace(/>/g, "&gt;");
14       //text = text.replace('\n', '<br>', 'g');
15       console.log(text);
16     };
17   })(),
18   printErr: function(text) {
19     if (arguments.length > 1) text = Array.prototype.slice.call(arguments).join(' ');
20     if (0) { // XXX disabled for safety typeof dump == 'function') {
21       dump(text + '\n'); // fast, straight to the real console
22     } else {
23       console.error(text);
24     }
25   },
26   canvas: (function() {
27     var canvas = document.getElementById('canvas');
28
29     // As a default initial behavior, pop up an alert when webgl context is lost. To make your
30     // application robust, you may want to override this behavior before shipping!
31     // See http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15.2
32     canvas.addEventListener("webglcontextlost", function(e) { alert('WebGL context lost. You will need to reload the page.'); e.preventDefault(); }, false);
33
34     return canvas;
35   })(),
36   setStatus: function(text) {
37     var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/);
38     if (m) {
39       text = m[1];
40       var perc = parseInt(m[2]) / parseInt(m[4]) * 100;
41       if (perc > 0) {
42         progress_bar.style.width = perc + '%';
43         progress_bar.innerHTML = perc.toFixed(1) + '%';
44       }
45     } else {
46       progress_bar.innerHTML = '';
47     }
48     progress_text.innerHTML = text;
49   },
50   totalDependencies: 0,
51   monitorRunDependencies: function(left) {
52     this.totalDependencies = Math.max(this.totalDependencies, left);
53     Module.setStatus('Preparing... (' + (this.totalDependencies-left) + '/' + this.totalDependencies + ')');
54   }
55 };
56 Module.setStatus('Downloading...');
57 window.onerror = function() {
58   Module.setStatus('Exception thrown, see JavaScript console');
59   Module.setStatus = function(text) {
60     if (text) Module.printErr('[post-exception status] ' + text);
61   };
62 };