From cac52020a4c5fdd8af0a54758130764760e38edf Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Tue, 29 Nov 2016 17:18:20 -0500 Subject: [PATCH 01/26] Add Export To Rendered Target --- src/sprites/rendered-target.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/sprites/rendered-target.js b/src/sprites/rendered-target.js index 50ad7e8f5..57eab25b0 100644 --- a/src/sprites/rendered-target.js +++ b/src/sprites/rendered-target.js @@ -64,6 +64,21 @@ RenderedTarget.prototype.initDrawable = function () { } }; +RenderedTarget.prototype.export = function () { + var result = new Object(); + var notSaved = ["renderer","effects","sprite","drawableID","runtime"]; + for (x in this) { + if (typeof(this[x]) === "function") { + continue; + } + if (notSaved.indexOf(x) == -1) { + result[x] = this[x]; + } + } + result.sprite = this.sprite.export(); + return result; +}; + /** * Whether this represents an "original" non-clone rendered-target for a sprite, * i.e., created by the editor and not clone blocks. From 0f4e80cbfcbaaec25016246a216d0d1615b7ae7f Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Tue, 29 Nov 2016 17:23:28 -0500 Subject: [PATCH 02/26] Add Export To Sprite --- src/sprites/sprite.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/sprites/sprite.js b/src/sprites/sprite.js index 0f189206a..479647c3f 100644 --- a/src/sprites/sprite.js +++ b/src/sprites/sprite.js @@ -54,4 +54,18 @@ Sprite.prototype.createClone = function () { return newClone; }; +Sprite.prototype.export = function () { + var result = new Object(); + var notSaved = ["clones","runtime"]; + for (x in this) { + if (typeof(this[x]) === "function") { + continue; + } + if (notSaved.indexOf(x) == -1) { + result[x] = this[x]; + } + } + return result; +}; + module.exports = Sprite; From 16449ae73dcb62ea0041dfd3ba1564f1476d4d1a Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Tue, 29 Nov 2016 17:50:31 -0500 Subject: [PATCH 03/26] Add Loading And Exporting --- src/index.js | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 4ed724f39..f7473a723 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,8 @@ var EventEmitter = require('events'); var util = require('util'); - +var Blocks = require('../engine/blocks'); +var RenderedTarget = require('../sprites/rendered-target'); +var Sprite = require('../sprites/sprite'); var Runtime = require('./engine/runtime'); var sb2import = require('./import/sb2import'); @@ -154,6 +156,41 @@ VirtualMachine.prototype.loadProject = function (json) { this.runtime.setEditingTarget(this.editingTarget); }; +VirtualMachine.prototype.exportToJson = function () { + this.clear(); + var obj = new Object(); + var i = 0; + obj.sprites = []; + for (; i < this.runtime.targets; i++) { + obj.sprites.push(this.runtime.targets[i].export()); + } + obj.meta.name = "WIP"; + obj.meta.useragent = navigator.userAgent; + return JSON.stringify(obj); +} + +VirtualMachine.prototype.importFromJson = function (json) { + var obj = JSON.parse(json); + var i = 0; + for (; i < obj.sprites.length; i++) { + var blocks = new Blocks(); + var sprite = new Sprite(blocks, this.runtime); + for (y in obj.sprites[i].sprite) { + sprite[y] = obj.sprites[i].sprite[y]; + } + var target = sprite.createClone(); + this.runtime.targets.push(target); + for (x in obj.sprites[i]) { + target[x] = obj.sprites[y]; + } + } + this.editingTarget = this.runtime.targets[1]; + // Update the VM user's knowledge of targets and blocks on the workspace. + this.emitTargetsUpdate(); + this.emitWorkspaceUpdate(); + this.runtime.setEditingTarget(this.editingTarget); +} + /** * Add a single sprite from the "Sprite2" (i.e., SB2 sprite) format. * @param {?string} json JSON string representing the sprite. From 51d829786c62b4ab9cfce8fe178ae213b511e551 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Tue, 29 Nov 2016 18:07:50 -0500 Subject: [PATCH 04/26] Update index.js --- src/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/index.js b/src/index.js index f7473a723..29e752289 100644 --- a/src/index.js +++ b/src/index.js @@ -181,6 +181,9 @@ VirtualMachine.prototype.importFromJson = function (json) { var target = sprite.createClone(); this.runtime.targets.push(target); for (x in obj.sprites[i]) { + if (x == "sprite") { + continue; + } target[x] = obj.sprites[y]; } } From 1777ab6a210c273c575949be951a87397ba5404d Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Tue, 29 Nov 2016 18:09:28 -0500 Subject: [PATCH 05/26] Update index.js --- src/index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 29e752289..0dcdeadfc 100644 --- a/src/index.js +++ b/src/index.js @@ -1,8 +1,7 @@ var EventEmitter = require('events'); var util = require('util'); -var Blocks = require('../engine/blocks'); -var RenderedTarget = require('../sprites/rendered-target'); -var Sprite = require('../sprites/sprite'); +var Blocks = require('./engine/blocks'); +var Sprite = require('./sprites/sprite'); var Runtime = require('./engine/runtime'); var sb2import = require('./import/sb2import'); From f4959305abfc007d2a97b6515d1cad5277f05e92 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Tue, 29 Nov 2016 18:14:12 -0500 Subject: [PATCH 06/26] Update index.js --- src/index.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index 0dcdeadfc..8d7a9f74c 100644 --- a/src/index.js +++ b/src/index.js @@ -163,10 +163,10 @@ VirtualMachine.prototype.exportToJson = function () { for (; i < this.runtime.targets; i++) { obj.sprites.push(this.runtime.targets[i].export()); } - obj.meta.name = "WIP"; + obj.meta.name = 'WIP'; obj.meta.useragent = navigator.userAgent; return JSON.stringify(obj); -} +}; VirtualMachine.prototype.importFromJson = function (json) { var obj = JSON.parse(json); @@ -174,16 +174,18 @@ VirtualMachine.prototype.importFromJson = function (json) { for (; i < obj.sprites.length; i++) { var blocks = new Blocks(); var sprite = new Sprite(blocks, this.runtime); + var y = null; for (y in obj.sprites[i].sprite) { sprite[y] = obj.sprites[i].sprite[y]; } var target = sprite.createClone(); this.runtime.targets.push(target); + var x = null; for (x in obj.sprites[i]) { - if (x == "sprite") { + if (x === 'sprite') { continue; } - target[x] = obj.sprites[y]; + target[x] = obj.sprites[x]; } } this.editingTarget = this.runtime.targets[1]; @@ -191,7 +193,7 @@ VirtualMachine.prototype.importFromJson = function (json) { this.emitTargetsUpdate(); this.emitWorkspaceUpdate(); this.runtime.setEditingTarget(this.editingTarget); -} +}; /** * Add a single sprite from the "Sprite2" (i.e., SB2 sprite) format. From 1980fbc98d22f8a85ca19015ab8daa751531c549 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Tue, 29 Nov 2016 18:53:38 -0500 Subject: [PATCH 07/26] Update rendered-target.js --- src/sprites/rendered-target.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/sprites/rendered-target.js b/src/sprites/rendered-target.js index 57eab25b0..cd2fe42d7 100644 --- a/src/sprites/rendered-target.js +++ b/src/sprites/rendered-target.js @@ -66,12 +66,13 @@ RenderedTarget.prototype.initDrawable = function () { RenderedTarget.prototype.export = function () { var result = new Object(); - var notSaved = ["renderer","effects","sprite","drawableID","runtime"]; + var notSaved = ['renderer', 'effects', 'sprite', 'drawableID', 'runtime']; + var x = null; for (x in this) { - if (typeof(this[x]) === "function") { + if (typeof this[x] === 'function') { continue; } - if (notSaved.indexOf(x) == -1) { + if (notSaved.indexOf(x) === -1) { result[x] = this[x]; } } From 74b8378a7c5c0ea130e2b7b80605438caaf7ca89 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Tue, 29 Nov 2016 18:55:38 -0500 Subject: [PATCH 08/26] Update sprite.js --- src/sprites/sprite.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/sprites/sprite.js b/src/sprites/sprite.js index 479647c3f..bdfbd20a2 100644 --- a/src/sprites/sprite.js +++ b/src/sprites/sprite.js @@ -56,12 +56,13 @@ Sprite.prototype.createClone = function () { Sprite.prototype.export = function () { var result = new Object(); - var notSaved = ["clones","runtime"]; + var notSaved = ['clones', 'runtime']; + var x = null; for (x in this) { - if (typeof(this[x]) === "function") { + if (typeof this[x] === 'function') { continue; } - if (notSaved.indexOf(x) == -1) { + if (notSaved.indexOf(x) === -1) { result[x] = this[x]; } } From 72b44b3ec713a1be62525b91dd65c29719e6e53a Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Tue, 29 Nov 2016 18:57:35 -0500 Subject: [PATCH 09/26] Update rendered-target.js --- src/sprites/rendered-target.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sprites/rendered-target.js b/src/sprites/rendered-target.js index cd2fe42d7..c237f8451 100644 --- a/src/sprites/rendered-target.js +++ b/src/sprites/rendered-target.js @@ -66,7 +66,7 @@ RenderedTarget.prototype.initDrawable = function () { RenderedTarget.prototype.export = function () { var result = new Object(); - var notSaved = ['renderer', 'effects', 'sprite', 'drawableID', 'runtime']; + var notSaved = ['renderer', 'effects', 'sprite', 'drawableID', 'runtime', 'id']; var x = null; for (x in this) { if (typeof this[x] === 'function') { From dd8675991502b50c0e0f7392555fcc87c3d70da2 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Fri, 2 Dec 2016 15:34:01 -0500 Subject: [PATCH 10/26] Update rendered-target.js --- src/sprites/rendered-target.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sprites/rendered-target.js b/src/sprites/rendered-target.js index c237f8451..b78e09bee 100644 --- a/src/sprites/rendered-target.js +++ b/src/sprites/rendered-target.js @@ -64,9 +64,9 @@ RenderedTarget.prototype.initDrawable = function () { } }; -RenderedTarget.prototype.export = function () { +RenderedTarget.prototype.toJSON = function () { var result = new Object(); - var notSaved = ['renderer', 'effects', 'sprite', 'drawableID', 'runtime', 'id']; + var notSaved = ['renderer', 'effects', 'sprite', 'drawableID', 'runtime', 'id', 'blocks']; var x = null; for (x in this) { if (typeof this[x] === 'function') { From 0707c4bcc8668553d06df9fa05894cd09b58a7b9 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Fri, 2 Dec 2016 15:35:35 -0500 Subject: [PATCH 11/26] Update index.js --- src/index.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index 8d7a9f74c..0fb9efbf3 100644 --- a/src/index.js +++ b/src/index.js @@ -156,19 +156,16 @@ VirtualMachine.prototype.loadProject = function (json) { }; VirtualMachine.prototype.exportToJson = function () { - this.clear(); var obj = new Object(); var i = 0; - obj.sprites = []; - for (; i < this.runtime.targets; i++) { - obj.sprites.push(this.runtime.targets[i].export()); - } + obj.sprites = this.runtime.targets; obj.meta.name = 'WIP'; obj.meta.useragent = navigator.userAgent; return JSON.stringify(obj); }; VirtualMachine.prototype.importFromJson = function (json) { + this.clear(); var obj = JSON.parse(json); var i = 0; for (; i < obj.sprites.length; i++) { From a520990a80c5d1fc9acd3e7c591041344b44c0a1 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Fri, 2 Dec 2016 15:37:35 -0500 Subject: [PATCH 12/26] Update index.js --- src/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/index.js b/src/index.js index 0fb9efbf3..a9e1fe329 100644 --- a/src/index.js +++ b/src/index.js @@ -157,7 +157,6 @@ VirtualMachine.prototype.loadProject = function (json) { VirtualMachine.prototype.exportToJson = function () { var obj = new Object(); - var i = 0; obj.sprites = this.runtime.targets; obj.meta.name = 'WIP'; obj.meta.useragent = navigator.userAgent; From 424b41ac315b0fc62fc32b42a67e34712aa80015 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Fri, 2 Dec 2016 15:41:55 -0500 Subject: [PATCH 13/26] Pretty Print --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index a9e1fe329..204970429 100644 --- a/src/index.js +++ b/src/index.js @@ -160,7 +160,7 @@ VirtualMachine.prototype.exportToJson = function () { obj.sprites = this.runtime.targets; obj.meta.name = 'WIP'; obj.meta.useragent = navigator.userAgent; - return JSON.stringify(obj); + return JSON.stringify(obj, null, 2); }; VirtualMachine.prototype.importFromJson = function (json) { From 34d2676db36bf682e73c96186e30641a2625d9af Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Fri, 2 Dec 2016 15:57:56 -0500 Subject: [PATCH 14/26] Update index.js --- src/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.js b/src/index.js index 204970429..149f06798 100644 --- a/src/index.js +++ b/src/index.js @@ -158,6 +158,7 @@ VirtualMachine.prototype.loadProject = function (json) { VirtualMachine.prototype.exportToJson = function () { var obj = new Object(); obj.sprites = this.runtime.targets; + obj.meta = new Object(); obj.meta.name = 'WIP'; obj.meta.useragent = navigator.userAgent; return JSON.stringify(obj, null, 2); From f2a08b466d56cb4da4ad3467a8417d86d9ce9032 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Fri, 2 Dec 2016 16:03:52 -0500 Subject: [PATCH 15/26] Update Names --- src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 149f06798..4e6878e07 100644 --- a/src/index.js +++ b/src/index.js @@ -155,7 +155,7 @@ VirtualMachine.prototype.loadProject = function (json) { this.runtime.setEditingTarget(this.editingTarget); }; -VirtualMachine.prototype.exportToJson = function () { +VirtualMachine.prototype.toJSON = function () { var obj = new Object(); obj.sprites = this.runtime.targets; obj.meta = new Object(); @@ -164,7 +164,7 @@ VirtualMachine.prototype.exportToJson = function () { return JSON.stringify(obj, null, 2); }; -VirtualMachine.prototype.importFromJson = function (json) { +VirtualMachine.prototype.fromJSON = function (json) { this.clear(); var obj = JSON.parse(json); var i = 0; From 05a827c0eaf37a1f7be60c2bff3dbf86b129006d Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Fri, 2 Dec 2016 16:30:34 -0500 Subject: [PATCH 16/26] Update index.js --- src/index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/index.js b/src/index.js index 4e6878e07..d6fb1107c 100644 --- a/src/index.js +++ b/src/index.js @@ -170,9 +170,16 @@ VirtualMachine.prototype.fromJSON = function (json) { var i = 0; for (; i < obj.sprites.length; i++) { var blocks = new Blocks(); + var z = null; + for (z in obj.sprites[i].sprite.blocks) { + blocks[z] = obj.sprites[i].sprite.blocks[z]; + } var sprite = new Sprite(blocks, this.runtime); var y = null; for (y in obj.sprites[i].sprite) { + if (y === 'blocks') { + continue; + } sprite[y] = obj.sprites[i].sprite[y]; } var target = sprite.createClone(); From 39e71aa4f41a60e4245fe14cb545334cc8c6046a Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Sat, 3 Dec 2016 13:25:15 -0500 Subject: [PATCH 17/26] Add To Playground --- playground/index.html | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/playground/index.html b/playground/index.html index 4c0a454bc..b981ef2f4 100644 --- a/playground/index.html +++ b/playground/index.html @@ -52,9 +52,9 @@

- +   - +

@@ -70,18 +70,17 @@ From 7fe597c9f98058579b8a16f8769e2a4dafc88927 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Sat, 3 Dec 2016 16:29:56 -0500 Subject: [PATCH 18/26] Now Actually loads Rendered Target Properties --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index d6fb1107c..d25ce3c78 100644 --- a/src/index.js +++ b/src/index.js @@ -189,7 +189,7 @@ VirtualMachine.prototype.fromJSON = function (json) { if (x === 'sprite') { continue; } - target[x] = obj.sprites[x]; + target[x] = obj.sprites[i][x]; } } this.editingTarget = this.runtime.targets[1]; From c4750d64b6e15a32fccc004cc54995837f2f3be2 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Sat, 3 Dec 2016 16:50:06 -0500 Subject: [PATCH 19/26] Fix Drawable Properties Not Getting Updated --- src/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.js b/src/index.js index d25ce3c78..1d64030d1 100644 --- a/src/index.js +++ b/src/index.js @@ -191,6 +191,7 @@ VirtualMachine.prototype.fromJSON = function (json) { } target[x] = obj.sprites[i][x]; } + target.updateAllDrawablePropertie(); } this.editingTarget = this.runtime.targets[1]; // Update the VM user's knowledge of targets and blocks on the workspace. From a58bcb93e64cf0b941574b95aeea67d06e81ae6d Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Sun, 4 Dec 2016 08:39:22 -0500 Subject: [PATCH 20/26] Update index.js --- src/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 1d64030d1..73f2e7886 100644 --- a/src/index.js +++ b/src/index.js @@ -155,13 +155,17 @@ VirtualMachine.prototype.loadProject = function (json) { this.runtime.setEditingTarget(this.editingTarget); }; +VirtualMachine.prototype.toPrettyJSON = function () { + return JSON.stringify(this.toJSON(), null, 4); +} + VirtualMachine.prototype.toJSON = function () { var obj = new Object(); obj.sprites = this.runtime.targets; obj.meta = new Object(); obj.meta.name = 'WIP'; obj.meta.useragent = navigator.userAgent; - return JSON.stringify(obj, null, 2); + return obj; }; VirtualMachine.prototype.fromJSON = function (json) { From 532df2079b72ca4ed01157169ae2404fb1796c94 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Sun, 4 Dec 2016 08:39:46 -0500 Subject: [PATCH 21/26] Update index.html --- playground/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playground/index.html b/playground/index.html index b981ef2f4..13c345b25 100644 --- a/playground/index.html +++ b/playground/index.html @@ -72,7 +72,7 @@