mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-03-14 17:30:26 -04:00
Merge pull request #451 from cwillisf/cleaner-playground
Use Webpack to generate the whole playground
This commit is contained in:
commit
6038722a79
5 changed files with 24 additions and 29 deletions
8
.gitignore
vendored
8
.gitignore
vendored
|
@ -14,10 +14,4 @@ npm-*
|
||||||
|
|
||||||
# Build
|
# Build
|
||||||
/dist
|
/dist
|
||||||
/playground/assets
|
/playground
|
||||||
/playground/media
|
|
||||||
/playground/scratch-vm.js
|
|
||||||
/playground/scratch-vm.js.map
|
|
||||||
/playground/vendor.js
|
|
||||||
/playground/vendor.js.map
|
|
||||||
/playground/zenburn.css
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
var loadProject = function () {
|
var loadProject = function () {
|
||||||
var id = location.hash.substring(1);
|
var id = location.hash.substring(1);
|
||||||
if (id.length < 1 || !isFinite(id)) {
|
if (id.length < 1 || !isFinite(id)) {
|
||||||
|
@ -7,7 +6,7 @@ var loadProject = function () {
|
||||||
var url = 'https://projects.scratch.mit.edu/internalapi/project/' +
|
var url = 'https://projects.scratch.mit.edu/internalapi/project/' +
|
||||||
id + '/get/';
|
id + '/get/';
|
||||||
var r = new XMLHttpRequest();
|
var r = new XMLHttpRequest();
|
||||||
r.onreadystatechange = function() {
|
r.onreadystatechange = function () {
|
||||||
if (this.readyState === 4) {
|
if (this.readyState === 4) {
|
||||||
if (r.status === 200) {
|
if (r.status === 200) {
|
||||||
window.vm.loadProject(this.responseText);
|
window.vm.loadProject(this.responseText);
|
||||||
|
@ -18,7 +17,7 @@ var loadProject = function () {
|
||||||
r.send();
|
r.send();
|
||||||
};
|
};
|
||||||
|
|
||||||
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.
|
// Instantiate the VM.
|
||||||
var vm = new window.VirtualMachine();
|
var vm = new window.VirtualMachine();
|
||||||
|
@ -74,7 +73,7 @@ window.onload = function() {
|
||||||
// Playground data tabs.
|
// Playground data tabs.
|
||||||
// Block representation tab.
|
// Block representation tab.
|
||||||
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);
|
||||||
};
|
};
|
||||||
|
@ -83,7 +82,7 @@ window.onload = function() {
|
||||||
var threadexplorer = document.getElementById('threadexplorer');
|
var threadexplorer = document.getElementById('threadexplorer');
|
||||||
var cachedThreadJSON = '';
|
var cachedThreadJSON = '';
|
||||||
var updateThreadExplorer = function (newJSON) {
|
var updateThreadExplorer = function (newJSON) {
|
||||||
if (newJSON != cachedThreadJSON) {
|
if (newJSON !== cachedThreadJSON) {
|
||||||
cachedThreadJSON = newJSON;
|
cachedThreadJSON = newJSON;
|
||||||
threadexplorer.innerHTML = cachedThreadJSON;
|
threadexplorer.innerHTML = cachedThreadJSON;
|
||||||
window.hljs.highlightBlock(threadexplorer);
|
window.hljs.highlightBlock(threadexplorer);
|
||||||
|
@ -101,7 +100,7 @@ window.onload = function() {
|
||||||
|
|
||||||
// VM handlers.
|
// VM handlers.
|
||||||
// Receipt of new playground data (thread, block representations).
|
// 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);
|
||||||
});
|
});
|
||||||
|
@ -125,7 +124,7 @@ window.onload = function() {
|
||||||
var targetOption = document.createElement('option');
|
var targetOption = document.createElement('option');
|
||||||
targetOption.setAttribute('value', data.targetList[i].id);
|
targetOption.setAttribute('value', data.targetList[i].id);
|
||||||
// If target id matches editingTarget id, select it.
|
// If target id matches editingTarget id, select it.
|
||||||
if (data.targetList[i].id == data.editingTarget) {
|
if (data.targetList[i].id === data.editingTarget) {
|
||||||
targetOption.setAttribute('selected', 'selected');
|
targetOption.setAttribute('selected', 'selected');
|
||||||
}
|
}
|
||||||
targetOption.appendChild(
|
targetOption.appendChild(
|
||||||
|
@ -139,23 +138,23 @@ window.onload = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Feedback for stacks and blocks running.
|
// Feedback for stacks and blocks running.
|
||||||
vm.on('SCRIPT_GLOW_ON', function(data) {
|
vm.on('SCRIPT_GLOW_ON', function (data) {
|
||||||
workspace.glowStack(data.id, true);
|
workspace.glowStack(data.id, true);
|
||||||
});
|
});
|
||||||
vm.on('SCRIPT_GLOW_OFF', function(data) {
|
vm.on('SCRIPT_GLOW_OFF', function (data) {
|
||||||
workspace.glowStack(data.id, false);
|
workspace.glowStack(data.id, false);
|
||||||
});
|
});
|
||||||
vm.on('BLOCK_GLOW_ON', function(data) {
|
vm.on('BLOCK_GLOW_ON', function (data) {
|
||||||
workspace.glowBlock(data.id, true);
|
workspace.glowBlock(data.id, true);
|
||||||
});
|
});
|
||||||
vm.on('BLOCK_GLOW_OFF', function(data) {
|
vm.on('BLOCK_GLOW_OFF', function (data) {
|
||||||
workspace.glowBlock(data.id, false);
|
workspace.glowBlock(data.id, false);
|
||||||
});
|
});
|
||||||
vm.on('VISUAL_REPORT', function(data) {
|
vm.on('VISUAL_REPORT', function (data) {
|
||||||
workspace.reportValue(data.id, data.value);
|
workspace.reportValue(data.id, data.value);
|
||||||
});
|
});
|
||||||
|
|
||||||
vm.on('SPRITE_INFO_REPORT', function(data) {
|
vm.on('SPRITE_INFO_REPORT', function (data) {
|
||||||
if (data.id !== selectedTarget.value) return; // Not the editingTarget
|
if (data.id !== selectedTarget.value) return; // Not the editingTarget
|
||||||
document.getElementById('sinfo-x').value = data.x;
|
document.getElementById('sinfo-x').value = data.x;
|
||||||
document.getElementById('sinfo-y').value = data.y;
|
document.getElementById('sinfo-y').value = data.y;
|
||||||
|
@ -213,7 +212,7 @@ window.onload = function() {
|
||||||
// Feed keyboard events as VM I/O events.
|
// Feed keyboard events as VM I/O events.
|
||||||
document.addEventListener('keydown', function (e) {
|
document.addEventListener('keydown', function (e) {
|
||||||
// Don't capture keys intended for Blockly inputs.
|
// Don't capture keys intended for Blockly inputs.
|
||||||
if (e.target != document && e.target != document.body) {
|
if (e.target !== document && e.target !== document.body) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
window.vm.postIOData('keyboard', {
|
window.vm.postIOData('keyboard', {
|
||||||
|
@ -222,7 +221,7 @@ window.onload = function() {
|
||||||
});
|
});
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
document.addEventListener('keyup', function(e) {
|
document.addEventListener('keyup', function (e) {
|
||||||
// Always capture up events,
|
// Always capture up events,
|
||||||
// even those that have switched to other targets.
|
// even those that have switched to other targets.
|
||||||
window.vm.postIOData('keyboard', {
|
window.vm.postIOData('keyboard', {
|
||||||
|
@ -230,7 +229,7 @@ window.onload = function() {
|
||||||
isDown: false
|
isDown: false
|
||||||
});
|
});
|
||||||
// E.g., prevent scroll.
|
// E.g., prevent scroll.
|
||||||
if (e.target != document && e.target != document.body) {
|
if (e.target !== document && e.target !== document.body) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -239,25 +238,25 @@ window.onload = function() {
|
||||||
vm.start();
|
vm.start();
|
||||||
|
|
||||||
// Inform VM of animation frames.
|
// Inform VM of animation frames.
|
||||||
var animate = function() {
|
var animate = function () {
|
||||||
stats.update();
|
stats.update();
|
||||||
requestAnimationFrame(animate);
|
requestAnimationFrame(animate);
|
||||||
};
|
};
|
||||||
requestAnimationFrame(animate);
|
requestAnimationFrame(animate);
|
||||||
|
|
||||||
// Handlers for green flag and stop all.
|
// Handlers for green flag and stop all.
|
||||||
document.getElementById('greenflag').addEventListener('click', function() {
|
document.getElementById('greenflag').addEventListener('click', function () {
|
||||||
vm.greenFlag();
|
vm.greenFlag();
|
||||||
});
|
});
|
||||||
document.getElementById('stopall').addEventListener('click', function() {
|
document.getElementById('stopall').addEventListener('click', function () {
|
||||||
vm.stopAll();
|
vm.stopAll();
|
||||||
});
|
});
|
||||||
document.getElementById('turbomode').addEventListener('change', function() {
|
document.getElementById('turbomode').addEventListener('change', function () {
|
||||||
var turboOn = document.getElementById('turbomode').checked;
|
var turboOn = document.getElementById('turbomode').checked;
|
||||||
vm.setTurboMode(turboOn);
|
vm.setTurboMode(turboOn);
|
||||||
});
|
});
|
||||||
document.getElementById('compatmode').addEventListener('change',
|
document.getElementById('compatmode').addEventListener('change',
|
||||||
function() {
|
function () {
|
||||||
var compatibilityMode = document.getElementById('compatmode').checked;
|
var compatibilityMode = document.getElementById('compatmode').checked;
|
||||||
vm.setCompatibilityMode(compatibilityMode);
|
vm.setCompatibilityMode(compatibilityMode);
|
||||||
});
|
});
|
|
@ -5,7 +5,7 @@ var webpack = require('webpack');
|
||||||
|
|
||||||
var base = {
|
var base = {
|
||||||
devServer: {
|
devServer: {
|
||||||
contentBase: path.resolve(__dirname, 'playground'),
|
contentBase: false,
|
||||||
host: '0.0.0.0',
|
host: '0.0.0.0',
|
||||||
port: process.env.PORT || 8073
|
port: process.env.PORT || 8073
|
||||||
},
|
},
|
||||||
|
@ -108,6 +108,8 @@ module.exports = [
|
||||||
to: 'media'
|
to: 'media'
|
||||||
}, {
|
}, {
|
||||||
from: 'node_modules/highlightjs/styles/zenburn.css'
|
from: 'node_modules/highlightjs/styles/zenburn.css'
|
||||||
|
}, {
|
||||||
|
from: 'src/playground'
|
||||||
}])
|
}])
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue