2016-06-01 10:04:56 -04:00
|
|
|
window.onload = function() {
|
|
|
|
// Lots of global variables to make debugging easier
|
|
|
|
var vm = new window.VirtualMachine();
|
|
|
|
window.vm = vm;
|
|
|
|
|
|
|
|
var toolbox = document.getElementById('toolbox');
|
|
|
|
var workspace = window.Blockly.inject('blocks', {
|
|
|
|
toolbox: toolbox,
|
|
|
|
media: '../node_modules/scratch-blocks/media/'
|
|
|
|
});
|
|
|
|
window.workspace = workspace;
|
|
|
|
|
|
|
|
// @todo: Also bind to flyout events, block running feedback.
|
|
|
|
// Block events.
|
|
|
|
workspace.addChangeListener(vm.blockListener);
|
|
|
|
|
2016-06-01 10:18:08 -04:00
|
|
|
var explorer = document.getElementById('blockexplorer');
|
|
|
|
workspace.addChangeListener(function() {
|
|
|
|
// On a change, update the block explorer.
|
|
|
|
explorer.innerHTML = JSON.stringify(vm.runtime.blocks, null, 2);
|
2016-06-01 10:47:47 -04:00
|
|
|
window.hljs.highlightBlock(explorer);
|
2016-06-01 10:18:08 -04:00
|
|
|
});
|
|
|
|
|
2016-06-01 10:04:56 -04:00
|
|
|
// Run threads
|
|
|
|
vm.runtime.start();
|
|
|
|
};
|