mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-06-08 03:24:56 -04:00
Add tab to VM playground to show threads
This commit is contained in:
parent
cb4dd7b511
commit
f2734950d7
3 changed files with 48 additions and 5 deletions
playground
|
@ -12,8 +12,16 @@
|
||||||
<h2>Scratch VM Playground</h2>
|
<h2>Scratch VM Playground</h2>
|
||||||
<button id="greenflag">Green flag</button>
|
<button id="greenflag">Green flag</button>
|
||||||
<button id="stopall">Stop</button>
|
<button id="stopall">Stop</button>
|
||||||
|
<p>
|
||||||
|
<a id="threadexplorer-link" href="#">VM Threads</a><br />
|
||||||
|
<a id="blockexplorer-link" href="#">VM Block Representation</a>
|
||||||
|
</p>
|
||||||
|
<div id="tab-threadexplorer">
|
||||||
|
Thread explorer
|
||||||
|
<pre id="threadexplorer"></pre>
|
||||||
|
</div>
|
||||||
<div id="tab-blockexplorer">
|
<div id="tab-blockexplorer">
|
||||||
<h3>VM Block Representation</h3>
|
Block explorer
|
||||||
<pre id="blockexplorer"></pre>
|
<pre id="blockexplorer"></pre>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
body {
|
body {
|
||||||
background: rgb(36,36,36);
|
background: rgb(36,36,36);
|
||||||
}
|
}
|
||||||
|
a {
|
||||||
|
color: rgb(217,217,217);
|
||||||
|
}
|
||||||
#blocks {
|
#blocks {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 40%;
|
left: 40%;
|
||||||
|
@ -17,7 +20,7 @@ body {
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
width: 35%;
|
width: 35%;
|
||||||
}
|
}
|
||||||
#blockexplorer {
|
#blockexplorer, #threadexplorer {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 75%;
|
height: 75%;
|
||||||
|
@ -28,3 +31,7 @@ body {
|
||||||
font-family: monospace;
|
font-family: monospace;
|
||||||
font-size: 10pt;
|
font-size: 10pt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#tab-blockexplorer {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
|
@ -29,13 +29,26 @@ window.onload = function() {
|
||||||
// Block events.
|
// Block events.
|
||||||
workspace.addChangeListener(vm.blockListener);
|
workspace.addChangeListener(vm.blockListener);
|
||||||
|
|
||||||
var explorer = document.getElementById('blockexplorer');
|
var blockexplorer = document.getElementById('blockexplorer');
|
||||||
workspace.addChangeListener(function() {
|
workspace.addChangeListener(function() {
|
||||||
// On a change, update the block explorer.
|
// On a change, update the block explorer.
|
||||||
explorer.innerHTML = JSON.stringify(vm.runtime.blocks, null, 2);
|
blockexplorer.innerHTML = JSON.stringify(vm.runtime.blocks, null, 2);
|
||||||
window.hljs.highlightBlock(explorer);
|
window.hljs.highlightBlock(blockexplorer);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var threadexplorer = document.getElementById('threadexplorer');
|
||||||
|
var cachedThreadJSON = '';
|
||||||
|
var updateThreadExplorer = function () {
|
||||||
|
var newJSON = JSON.stringify(vm.runtime.threads, null, 2);
|
||||||
|
if (newJSON != cachedThreadJSON) {
|
||||||
|
cachedThreadJSON = newJSON;
|
||||||
|
threadexplorer.innerHTML = cachedThreadJSON;
|
||||||
|
window.hljs.highlightBlock(threadexplorer);
|
||||||
|
}
|
||||||
|
window.requestAnimationFrame(updateThreadExplorer);
|
||||||
|
};
|
||||||
|
updateThreadExplorer();
|
||||||
|
|
||||||
// Feedback for stacks running.
|
// Feedback for stacks running.
|
||||||
vm.runtime.on('STACK_GLOW_ON', function(blockId) {
|
vm.runtime.on('STACK_GLOW_ON', function(blockId) {
|
||||||
workspace.glowStack(blockId, true);
|
workspace.glowStack(blockId, true);
|
||||||
|
@ -54,4 +67,19 @@ window.onload = function() {
|
||||||
document.getElementById('stopall').addEventListener('click', function() {
|
document.getElementById('stopall').addEventListener('click', function() {
|
||||||
vm.runtime.stopAll();
|
vm.runtime.stopAll();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var tabBlockExplorer = document.getElementById('tab-blockexplorer');
|
||||||
|
var tabThreadExplorer = document.getElementById('tab-threadexplorer');
|
||||||
|
|
||||||
|
// Handlers to show different explorers.
|
||||||
|
document.getElementById('threadexplorer-link').addEventListener('click',
|
||||||
|
function () {
|
||||||
|
tabBlockExplorer.style.display = 'none';
|
||||||
|
tabThreadExplorer.style.display = 'block';
|
||||||
|
});
|
||||||
|
document.getElementById('blockexplorer-link').addEventListener('click',
|
||||||
|
function () {
|
||||||
|
tabBlockExplorer.style.display = 'block';
|
||||||
|
tabThreadExplorer.style.display = 'none';
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue