git @ Cat's Eye Technologies noit-o-mnain-worb / 7691bc8
Have the launcher only load the classes after the dependencies. Chris Pressey 4 years ago
1 changed file(s) with 71 addition(s) and 66 deletion(s). Raw diff Collapse all Expand all
22 container = document.getElementById(container);
33 }
44 config = config || {};
5 var deps = [
5
6 function loadThese(deps, callback) {
7 var loaded = 0;
8 for (var i = 0; i < deps.length; i++) {
9 var elem = document.createElement('script');
10 elem.src = prefix + deps[i];
11 elem.onload = function() {
12 if (++loaded < deps.length) return;
13 callback();
14 }
15 document.body.appendChild(elem);
16 }
17 }
18
19 loadThese([
620 "yoob/element-factory.js",
721 "yoob/controller.js",
822 "yoob/playfield.js",
923 "yoob/playfield-canvas-view.js",
1024 "yoob/preset-manager.js",
1125 "yoob/source-manager.js",
12 "worb.js"
13 ];
14 var loaded = 0;
15 var onload = function() {
16 if (++loaded < deps.length) return;
26 ], function() {
27 loadThese(["worb.js"], function() {
28 var controlPanel = yoob.makeDiv(container);
29 controlPanel.id = 'control_panel';
30 var subPanel = yoob.makeDiv(container);
31 var selectSource = yoob.makeSelect(subPanel, 'configuration:', []);
32 var loadIndicator = yoob.makeSpan(subPanel, "load indicator");
33 loadIndicator.id = 'load_indicator';
34 var canvasViewport = yoob.makeDiv(container);
35 canvasViewport.id = 'canvas_viewport';
36 var canvas = yoob.makeCanvas(canvasViewport, 400, 400);
37 var editor = yoob.makeTextArea(container, 40, 25);
1738
18 var controlPanel = yoob.makeDiv(container);
19 controlPanel.id = 'control_panel';
20 var subPanel = yoob.makeDiv(container);
21 var selectSource = yoob.makeSelect(subPanel, 'configuration:', []);
22 var loadIndicator = yoob.makeSpan(subPanel, "load indicator");
23 loadIndicator.id = 'load_indicator';
24 var canvasViewport = yoob.makeDiv(container);
25 canvasViewport.id = 'canvas_viewport';
26 var canvas = yoob.makeCanvas(canvasViewport, 400, 400);
27 var editor = yoob.makeTextArea(container, 40, 25);
39 var v = new yoob.PlayfieldCanvasView().init({
40 canvas: canvas
41 });
42 v.setCellDimensions(16, 16);
2843
29 var v = new yoob.PlayfieldCanvasView().init({
30 canvas: canvas
44 var controller = (new WorbController()).init({
45 panelContainer: controlPanel,
46 view: v
47 });
48
49 var loadLevel = 0;
50 controller.onstep = function(underLoad) {
51 if (underLoad) loadLevel += 60;
52 loadLevel -= 10;
53 if (loadLevel < 0) loadLevel = 0;
54 if (loadLevel > 255) loadLevel = 255;
55 var l = 255 - loadLevel;
56 loadIndicator.style.background = "rgba(255, " + l + "," + l + ",1.0)";
57 };
58
59 var sourceManager = (new yoob.SourceManager()).init({
60 panelContainer: controlPanel,
61 editor: editor,
62 hideDuringEdit: [canvasViewport],
63 disableDuringEdit: [controller.panel],
64 storageKey: 'worb.js',
65 onDone: function() {
66 controller.setResetState(this.getEditorText());
67 controller.clickReset();
68 }
69 });
70
71 var presetManager = (new yoob.PresetManager()).init({
72 selectElem: selectSource,
73 });
74 function makeCallback(sourceText) {
75 return function(id) {
76 sourceManager.loadSource(sourceText);
77 }
78 }
79 for (var i = 0; i < examplePrograms.length; i++) {
80 presetManager.add(examplePrograms[i][0], makeCallback(examplePrograms[i][1]));
81 }
82 presetManager.select(examplePrograms[0][0]);
3183 });
32 v.setCellDimensions(16, 16);
33
34 var controller = (new WorbController()).init({
35 panelContainer: controlPanel,
36 view: v
37 });
38
39 var loadLevel = 0;
40 controller.onstep = function(underLoad) {
41 if (underLoad) loadLevel += 60;
42 loadLevel -= 10;
43 if (loadLevel < 0) loadLevel = 0;
44 if (loadLevel > 255) loadLevel = 255;
45 var l = 255 - loadLevel;
46 loadIndicator.style.background = "rgba(255, " + l + "," + l + ",1.0)";
47 };
48
49 var sourceManager = (new yoob.SourceManager()).init({
50 panelContainer: controlPanel,
51 editor: editor,
52 hideDuringEdit: [canvasViewport],
53 disableDuringEdit: [controller.panel],
54 storageKey: 'worb.js',
55 onDone: function() {
56 controller.setResetState(this.getEditorText());
57 controller.clickReset();
58 }
59 });
60
61 var presetManager = (new yoob.PresetManager()).init({
62 selectElem: selectSource,
63 });
64 function makeCallback(sourceText) {
65 return function(id) {
66 sourceManager.loadSource(sourceText);
67 }
68 }
69 for (var i = 0; i < examplePrograms.length; i++) {
70 presetManager.add(examplePrograms[i][0], makeCallback(examplePrograms[i][1]));
71 }
72 presetManager.select(examplePrograms[0][0]);
73 };
74 for (var i = 0; i < deps.length; i++) {
75 var elem = document.createElement('script');
76 elem.src = prefix + deps[i];
77 elem.onload = onload;
78 document.body.appendChild(elem);
79 }
84 });
8085 }