git @ Cat's Eye Technologies noit-o-mnain-worb / 2dda834
Package launching logic into src/worb-launcher.js. Chris Pressey 4 years ago
2 changed file(s) with 81 addition(s) and 54 deletion(s). Raw diff Collapse all Expand all
3232 <textarea id="editor" rows="25" cols="40"></textarea>
3333
3434 </body>
35 <script src="../src/yoob/controller.js"></script>
36 <script src="../src/yoob/playfield.js"></script>
37 <script src="../src/yoob/playfield-canvas-view.js"></script>
38 <script src="../src/yoob/preset-manager.js"></script>
39 <script src="../src/yoob/source-manager.js"></script>
40 <script src="../src/worb.js"></script>
4135 <script src="../../../eg/index.js"></script>
36 <script src="../src/worb-launcher.js"></script>
4237 <script>
43 var loadIndicator = document.getElementById('load_indicator');
44 var controlPanel = document.getElementById('control_panel');
45 var display = document.getElementById('canvas_viewport');
46
47 var v = new yoob.PlayfieldCanvasView().init({
48 canvas: document.getElementById('canvas')
49 });
50 v.setCellDimensions(16, 16);
51
52 var controller = (new WorbController()).init({
53 panelContainer: controlPanel,
54 view: v
55 });
56
57 var loadLevel = 0;
58 controller.onstep = function(underLoad) {
59 if (underLoad) loadLevel += 60;
60 loadLevel -= 10;
61 if (loadLevel < 0) loadLevel = 0;
62 if (loadLevel > 255) loadLevel = 255;
63 var l = 255 - loadLevel;
64 loadIndicator.style.background = "rgba(255, " + l + "," + l + ",1.0)";
65 };
66
67 var sourceManager = (new yoob.SourceManager()).init({
68 panelContainer: controlPanel,
69 editor: document.getElementById('editor'),
70 hideDuringEdit: [display],
71 disableDuringEdit: [controller.panel],
72 storageKey: 'worb.js',
73 onDone: function() {
74 controller.setResetState(this.getEditorText());
75 controller.clickReset();
76 }
77 });
78
79 var presetManager = (new yoob.PresetManager()).init({
80 selectElem: document.getElementById('select_source'),
81 });
82 function makeCallback(sourceText) {
83 return function(id) {
84 sourceManager.loadSource(sourceText);
85 }
86 }
87 for (var i = 0; i < examplePrograms.length; i++) {
88 presetManager.add(examplePrograms[i][0], makeCallback(examplePrograms[i][1]));
89 }
90 presetManager.select(examplePrograms[0][0]);
38 launch('../src/', 'container', {});
9139 </script>
0 function launch(prefix, container, config) {
1 if (typeof container === 'string') {
2 container = document.getElementById(container);
3 }
4 config = config || {};
5 var deps = [
6 "yoob/controller.js",
7 "yoob/playfield.js",
8 "yoob/playfield-canvas-view.js",
9 "yoob/preset-manager.js",
10 "yoob/source-manager.js",
11 "worb.js"
12 ];
13 var loaded = 0;
14 var onload = function() {
15 if (++loaded < deps.length) return;
16 //document.getElementById('installation').innerHTML =
17 // '<div id="control_panel"></div>' +
18 // '<span id="load_indicator">load indicator</span>' +
19 // '<div>example source: <select id="select_source"></select></div>' +
20 // '<div id="animation_container"><canvas id="canvas" width="400" height="400"></canvas></div>' +
21 // '<textarea id="editor" rows="25" cols="40"></textarea>';
22
23 var loadIndicator = document.getElementById('load_indicator');
24 var controlPanel = document.getElementById('control_panel');
25 var display = document.getElementById('canvas_viewport');
26
27 var v = new yoob.PlayfieldCanvasView().init({
28 canvas: document.getElementById('canvas')
29 });
30 v.setCellDimensions(16, 16);
31
32 var controller = (new WorbController()).init({
33 panelContainer: controlPanel,
34 view: v
35 });
36
37 var loadLevel = 0;
38 controller.onstep = function(underLoad) {
39 if (underLoad) loadLevel += 60;
40 loadLevel -= 10;
41 if (loadLevel < 0) loadLevel = 0;
42 if (loadLevel > 255) loadLevel = 255;
43 var l = 255 - loadLevel;
44 loadIndicator.style.background = "rgba(255, " + l + "," + l + ",1.0)";
45 };
46
47 var sourceManager = (new yoob.SourceManager()).init({
48 panelContainer: controlPanel,
49 editor: document.getElementById('editor'),
50 hideDuringEdit: [display],
51 disableDuringEdit: [controller.panel],
52 storageKey: 'worb.js',
53 onDone: function() {
54 controller.setResetState(this.getEditorText());
55 controller.clickReset();
56 }
57 });
58
59 var presetManager = (new yoob.PresetManager()).init({
60 selectElem: document.getElementById('select_source'),
61 });
62 function makeCallback(sourceText) {
63 return function(id) {
64 sourceManager.loadSource(sourceText);
65 }
66 }
67 for (var i = 0; i < examplePrograms.length; i++) {
68 presetManager.add(examplePrograms[i][0], makeCallback(examplePrograms[i][1]));
69 }
70 presetManager.select(examplePrograms[0][0]);
71 };
72 for (var i = 0; i < deps.length; i++) {
73 var elem = document.createElement('script');
74 elem.src = prefix + deps[i];
75 elem.onload = onload;
76 document.body.appendChild(elem);
77 }
78 }