|
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 |
}
|