Fix new project creation ()

* Fix new project creation

* Fix new project creation

* const -> var
This commit is contained in:
dekrain 2016-10-12 19:56:31 +02:00 committed by Tim Mickel
parent a7522c7734
commit 49d6bd3b67
2 changed files with 10 additions and 4 deletions

View file

@ -1,6 +1,12 @@
var NEW_PROJECT_HASH = 'createEmptyProject';
var loadProject = function () { var loadProject = function () {
var id = location.hash.substring(1); var id = location.hash.substring(1);
if (id.length < 1) { if (id === NEW_PROJECT_HASH) {
window.vm.createEmptyProject();
return;
}
if (id.length < 1 || !isFinite(id)) {
id = '119615668'; id = '119615668';
} }
var url = 'https://projects.scratch.mit.edu/internalapi/project/' + var url = 'https://projects.scratch.mit.edu/internalapi/project/' +
@ -32,7 +38,7 @@ window.onload = function() {
}; };
document.getElementById('createEmptyProject').addEventListener('click', document.getElementById('createEmptyProject').addEventListener('click',
function() { function() {
document.location = '#' + 'createEmptyProject'; document.location = '#' + NEW_PROJECT_HASH;
location.reload(); location.reload();
}); });
loadProject(); loadProject();

View file

@ -132,7 +132,7 @@ VirtualMachine.prototype.loadProject = function (json) {
VirtualMachine.prototype.createEmptyProject = function () { VirtualMachine.prototype.createEmptyProject = function () {
// Stage. // Stage.
var blocks2 = new Blocks(); var blocks2 = new Blocks();
var stage = new Sprite(blocks2); var stage = new Sprite(blocks2, this.runtime);
stage.name = 'Stage'; stage.name = 'Stage';
stage.costumes.push({ stage.costumes.push({
skin: '/assets/stage.png', skin: '/assets/stage.png',
@ -151,7 +151,7 @@ VirtualMachine.prototype.createEmptyProject = function () {
target2.isStage = true; target2.isStage = true;
// Sprite1 (cat). // Sprite1 (cat).
var blocks1 = new Blocks(); var blocks1 = new Blocks();
var sprite = new Sprite(blocks1); var sprite = new Sprite(blocks1, this.runtime);
sprite.name = 'Sprite1'; sprite.name = 'Sprite1';
sprite.costumes.push({ sprite.costumes.push({
skin: '/assets/scratch_cat.svg', skin: '/assets/scratch_cat.svg',