git @ Cat's Eye Technologies Pixley / 8628347
Add pixley-launcher.js. Dependency injection, how I love/hate you. Chris Pressey 9 years ago
3 changed file(s) with 68 addition(s) and 42 deletion(s). Raw diff Collapse all Expand all
4545 <div id="panel">
4646 <button id="start">Start</button>
4747 <button id="stop">Stop</button>
48 <button id="wrap" onclick="c.wrapWith(document.getElementById('pixley-interpreter').innerHTML);">Wrap in Pixley Interpreter</button>
48 <button id="wrap">Wrap in Pixley Interpreter</button>
4949 <span id="status"></span>
5050 </div>
5151
230230 <script src="../src/yoob/preset-manager.js"></script>
231231 <script src="../src/pixley-controller.js"></script>
232232 <script src="../src/pixley-depictor.js"></script>
233 <script src="../src/pixley-launcher.js"></script>
233234 <script>
234 var c = new PixleyController();
235 c.init({
236 'status': document.getElementById('status'),
237 'display': document.getElementById('display'),
238 'output': document.getElementById('output'),
239 'wrapButton': document.getElementById('wrap')
240 });
241 document.getElementById('start').onclick = function() { c.start(); };
242 document.getElementById('stop').onclick = function() { c.stop(); };
243 c.depictor = new PixleyDepictor();
244 c.depictor.init(document.getElementById('canvas'));
245
246 var sourceManager = (new yoob.SourceManager()).init({
247 'panelContainer': document.getElementById('edit_panel'),
248 'editor': document.getElementById('program'),
249 'hideDuringEdit': [
250 document.getElementById('display'),
251 document.getElementById('status')
252 ],
253 'disableDuringEdit': [document.getElementById('panel')],
254 'storageKey': 'demo/pixley.html',
255 'onDone': function() {
256 /* Apparently this gets called as soon as the sourceManager
257 has been initialized... but we don't have any editor text
258 yet at that point. But it will get called again, when
259 we make the sourceManager. So, ... we check first. */
260 if (this.getEditorText()) {
261 c.load(this.getEditorText());
262 }
263 }
264 });
265
266 var presetManager = (new yoob.PresetManager()).init({
235 launch({
236 workerURL: "../src/pixley-worker.js",
237 status: document.getElementById('status'),
238 display: document.getElementById('display'),
239 output: document.getElementById('output'),
240 startButton: document.getElementById('start'),
241 stopButton: document.getElementById('stop'),
242 wrapButton: document.getElementById('wrap'),
243 pixleyInterpreter: document.getElementById('pixley-interpreter').innerHTML,
244 depictionCanvas: document.getElementById('canvas'),
245 editor: document.getElementById('program'),
246 editPanel: document.getElementById('edit_panel'),
247 controlPanel: document.getElementById('panel'),
248 storageKey: 'demo/pixley.html',
267249 selectElem: document.getElementById('select_source'),
268 setPreset: function(id) {
269 sourceManager.loadSourceFromHTML(document.getElementById(id).innerHTML);
270 }
271 }).populateFromClass('example_program').select('cons-test');
250 exampleProgramClass: 'example_program',
251 initialProgramName: 'cons-test'
252 });
272253 </script>
1010 this.status = cfg.status;
1111 this.display = cfg.display;
1212 this.output = cfg.output;
13 this.wrapButton = cfg.wrapButton;
14 this.workerURL = cfg.workerURL || "../src/pixley-worker.js";
13 this.workerURL = cfg.workerURL;
1514 this.loadWorker();
1615 this.running = false;
1716 this.setStatus('Ready.');
3029 };
3130
3231 this.draw = function() {
33 var display = document.getElementById('display');
34 display.innerHTML = depict(this.ast);
32 if (this.display) {
33 this.display.innerHTML = depict(this.ast);
34 }
3535 if (this.depictor) {
3636 this.depictor.depict(this.ast);
3737 }
0 function launch(cfg) {
1 var c = new PixleyController();
2 c.init({
3 status: cfg.status,
4 display: cfg.display,
5 output: cfg.output,
6 workerURL: cfg.workerURL
7 });
8
9 cfg.startButton.onclick = function() { c.start(); };
10 cfg.stopButton.onclick = function() { c.stop(); };
11 cfg.wrapButton.onclick = function() {
12 c.wrapWith(cfg.pixleyInterpreter);
13 };
14
15 c.depictor = new PixleyDepictor();
16 c.depictor.init(cfg.depictionCanvas);
17
18 var sourceManager = (new yoob.SourceManager()).init({
19 'panelContainer': cfg.editPanel,
20 'editor': cfg.editor,
21 'hideDuringEdit': [
22 cfg.display,
23 cfg.status
24 ],
25 'disableDuringEdit': [cfg.controlPanel],
26 'storageKey': cfg.storageKey,
27 'onDone': function() {
28 /* Apparently this gets called as soon as the sourceManager
29 has been initialized... but we don't have any editor text
30 yet at that point. But it will get called again, when
31 we make the sourceManager. So, ... we check first. */
32 if (this.getEditorText()) {
33 c.load(this.getEditorText());
34 }
35 }
36 });
37
38 var presetManager = (new yoob.PresetManager()).init({
39 selectElem: cfg.selectElem,
40 setPreset: function(id) {
41 sourceManager.loadSourceFromHTML(document.getElementById(id).innerHTML);
42 }
43 }).populateFromClass(cfg.exampleProgramClass).select(cfg.initialProgramName);
44 }