From d033271a1ffed6e46deeb95f99616cd419c41d26 Mon Sep 17 00:00:00 2001 From: Morten Dybdal Date: Thu, 26 Apr 2018 10:59:53 +0200 Subject: [PATCH 1/2] Included a function to add sprite 3 to vm --- src/virtual-machine.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/virtual-machine.js b/src/virtual-machine.js index 1e7a0b9e1..01a934bbd 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -394,6 +394,32 @@ class VirtualMachine extends EventEmitter { this.installTargets(targets, extensions, false)); } + /** + * Add a single sb3 sprite. + * @param {string} json JSON string representing the sprite/target. + * @returns {Promise} Promise that resolves after the sprite is added + */ + addSprite3(target) { + // Validate & parse + if (typeof target !== 'string') { + log.error('Failed to parse sprite. Non-string supplied to addSprite3.'); + return; + } + target = JSON.parse(target); + if (typeof target !== 'object') { + log.error('Failed to parse sprite. JSON supplied to addSprite3 is not an object.'); + return; + } + + const jsonFormatted = { + targets: [target], + }; + + return sb3 + .deserialize(jsonFormatted, this.runtime, null) + .then(({ targets, extensions }) => this.installTargets(targets, extensions, false)); + } + /** * Add a costume to the current editing target. * @param {string} md5ext - the MD5 and extension of the costume to be loaded. From 41be65ba4d928dd5c547ad567e9346ae71364b32 Mon Sep 17 00:00:00 2001 From: Morten Dybdal Date: Tue, 1 May 2018 13:23:21 +0200 Subject: [PATCH 2/2] Fixing js linting issues --- src/virtual-machine.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/virtual-machine.js b/src/virtual-machine.js index 01a934bbd..f86ac0659 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -396,10 +396,10 @@ class VirtualMachine extends EventEmitter { /** * Add a single sb3 sprite. - * @param {string} json JSON string representing the sprite/target. + * @param {string} target JSON string representing the sprite/target. * @returns {Promise} Promise that resolves after the sprite is added */ - addSprite3(target) { + addSprite3 (target) { // Validate & parse if (typeof target !== 'string') { log.error('Failed to parse sprite. Non-string supplied to addSprite3.'); @@ -412,12 +412,12 @@ class VirtualMachine extends EventEmitter { } const jsonFormatted = { - targets: [target], + targets: [target] }; return sb3 .deserialize(jsonFormatted, this.runtime, null) - .then(({ targets, extensions }) => this.installTargets(targets, extensions, false)); + .then(({targets, extensions}) => this.installTargets(targets, extensions, false)); } /**