mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 15:02:52 -05:00
Adding some comments to playground.js handlers
This commit is contained in:
parent
ae89cfbb6b
commit
fc4c5023e1
1 changed files with 15 additions and 6 deletions
|
@ -12,6 +12,7 @@ var loadProject = function () {
|
||||||
|
|
||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
// Lots of global variables to make debugging easier
|
// Lots of global variables to make debugging easier
|
||||||
|
// Instantiate the VM worker.
|
||||||
var vm = new window.VirtualMachine();
|
var vm = new window.VirtualMachine();
|
||||||
window.vm = vm;
|
window.vm = vm;
|
||||||
|
|
||||||
|
@ -22,10 +23,12 @@ window.onload = function() {
|
||||||
};
|
};
|
||||||
loadProject();
|
loadProject();
|
||||||
|
|
||||||
|
// Instantiate the renderer and connect it to the VM.
|
||||||
var canvas = document.getElementById('scratch-stage');
|
var canvas = document.getElementById('scratch-stage');
|
||||||
window.renderer = new window.RenderWebGLLocal(canvas);
|
window.renderer = new window.RenderWebGLLocal(canvas);
|
||||||
window.renderer.connectWorker(window.vm.vmWorker);
|
window.renderer.connectWorker(window.vm.vmWorker);
|
||||||
|
|
||||||
|
// Instantiate scratch-blocks and attach it to the DOM.
|
||||||
var toolbox = document.getElementById('toolbox');
|
var toolbox = document.getElementById('toolbox');
|
||||||
var workspace = window.Blockly.inject('blocks', {
|
var workspace = window.Blockly.inject('blocks', {
|
||||||
toolbox: toolbox,
|
toolbox: toolbox,
|
||||||
|
@ -48,23 +51,25 @@ window.onload = function() {
|
||||||
});
|
});
|
||||||
window.workspace = workspace;
|
window.workspace = workspace;
|
||||||
|
|
||||||
// FPS counter.
|
// Attach scratch-blocks events to VM.
|
||||||
|
// @todo: Re-enable flyout listening after fixing GH-69.
|
||||||
|
workspace.addChangeListener(vm.blockListener);
|
||||||
|
|
||||||
|
// Create FPS counter.
|
||||||
var stats = new window.Stats();
|
var stats = new window.Stats();
|
||||||
document.getElementById('tab-renderexplorer').appendChild(stats.dom);
|
document.getElementById('tab-renderexplorer').appendChild(stats.dom);
|
||||||
stats.dom.style.position = 'relative';
|
stats.dom.style.position = 'relative';
|
||||||
stats.begin();
|
stats.begin();
|
||||||
|
|
||||||
// Block events.
|
// Playground data tabs.
|
||||||
// @todo: Re-enable flyout listening after fixing GH-69.
|
// Block representation tab.
|
||||||
workspace.addChangeListener(vm.blockListener);
|
|
||||||
|
|
||||||
// Playground data
|
|
||||||
var blockexplorer = document.getElementById('blockexplorer');
|
var blockexplorer = document.getElementById('blockexplorer');
|
||||||
var updateBlockExplorer = function(blocks) {
|
var updateBlockExplorer = function(blocks) {
|
||||||
blockexplorer.innerHTML = JSON.stringify(blocks, null, 2);
|
blockexplorer.innerHTML = JSON.stringify(blocks, null, 2);
|
||||||
window.hljs.highlightBlock(blockexplorer);
|
window.hljs.highlightBlock(blockexplorer);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Thread representation tab.
|
||||||
var threadexplorer = document.getElementById('threadexplorer');
|
var threadexplorer = document.getElementById('threadexplorer');
|
||||||
var cachedThreadJSON = '';
|
var cachedThreadJSON = '';
|
||||||
var updateThreadExplorer = function (threads) {
|
var updateThreadExplorer = function (threads) {
|
||||||
|
@ -85,11 +90,14 @@ window.onload = function() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// VM handlers.
|
||||||
|
// Receipt of new playground data (thread, block representations).
|
||||||
vm.on('playgroundData', function(data) {
|
vm.on('playgroundData', function(data) {
|
||||||
updateThreadExplorer(data.threads);
|
updateThreadExplorer(data.threads);
|
||||||
updateBlockExplorer(data.blocks);
|
updateBlockExplorer(data.blocks);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Receipt of new block XML for the selected target.
|
||||||
vm.on('workspaceUpdate', function (data) {
|
vm.on('workspaceUpdate', function (data) {
|
||||||
window.Blockly.Events.disable();
|
window.Blockly.Events.disable();
|
||||||
workspace.clear();
|
workspace.clear();
|
||||||
|
@ -98,6 +106,7 @@ window.onload = function() {
|
||||||
window.Blockly.Events.enable();
|
window.Blockly.Events.enable();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Receipt of new list of targets, selected target update.
|
||||||
var selectedTarget = document.getElementById('selectedTarget');
|
var selectedTarget = document.getElementById('selectedTarget');
|
||||||
vm.on('targetsUpdate', function (data) {
|
vm.on('targetsUpdate', function (data) {
|
||||||
// Clear select box.
|
// Clear select box.
|
||||||
|
|
Loading…
Reference in a new issue