diff --git a/playground/index.html b/playground/index.html
index 12a545d9929..7add6a5078a 100644
--- a/playground/index.html
+++ b/playground/index.html
@@ -14,6 +14,7 @@
Scratch VM Playground
+
diff --git a/playground/playground.js b/playground/playground.js
index 9c3f0069082..cedb83950b7 100644
--- a/playground/playground.js
+++ b/playground/playground.js
@@ -26,14 +26,35 @@ window.onload = function() {
window.vm = vm;
// Loading projects from the server.
- document.getElementById('projectLoadButton').onclick = function () {
+ document.getElementById('projectLoadButton').addEventListener('click', function () {
document.location = '#' + document.getElementById('projectId').value;
location.reload();
- };
+ });
document.getElementById('createEmptyProject').addEventListener('click', function() {
document.location = '#' + 'createEmptyProject';
location.reload();
});
+ document.getElementById('newSprite').addEventListener('click', function() {
+ var blocks = new window.Blocks();
+ var sprite = new window.Sprite(blocks);
+ var i = 1;
+ while (vm.runtime.getCloneByName('Sprite' + i)) {
+ ++i;
+ }
+ sprite.name = 'Sprite' + i;
+ sprite.costumes.push({
+ skin: '/assets/scratch_cat.svg',
+ name: 'costume1',
+ bitmapResolution: 1,
+ rotationCenterX: 47,
+ rotationCenterY: 55
+ });
+ var target = sprite.createClone();
+ vm.runtime.targets.push(target);
+ vm.editingTarget = target;
+ vm.emitTargetsUpdate();
+ vm.emitWorkspaceUpdate();
+ });
loadProject();
// Instantiate the renderer and connect it to the VM.
diff --git a/src/engine/blocks.js b/src/engine/blocks.js
index b3d87e49f7d..ebd0ff2eeaf 100644
--- a/src/engine/blocks.js
+++ b/src/engine/blocks.js
@@ -411,3 +411,4 @@ Blocks.prototype._deleteScript = function (topBlockId) {
};
module.exports = Blocks;
+if (typeof window !== 'undefined') window.Blocks = module.exports;
diff --git a/src/engine/runtime.js b/src/engine/runtime.js
index 6c5f36eb15c..f0db15cb0e6 100644
--- a/src/engine/runtime.js
+++ b/src/engine/runtime.js
@@ -474,6 +474,20 @@ Runtime.prototype.getTargetById = function (targetId) {
}
};
+/**
+ * Get a Clone by its name.
+ * @param {string} targetName Name of clone's sprite to find.
+ * @return {?Clone} The clone target, if found.
+ */
+Runtime.prototype.getCloneByName = function (targetName) {
+ for (var i = 0; i