From 14bee14d8c268185e14afbb5ff9fa29a958a6934 Mon Sep 17 00:00:00 2001 From: Karishma Chadha Date: Fri, 9 Nov 2018 23:34:06 -0500 Subject: [PATCH] Update extensions to load when deserializing monitors. This is necessary when the monitor is the only part of the project that uses the extension. Update extension monitor color category. --- src/engine/runtime.js | 4 ++-- src/serialization/sb3.js | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/engine/runtime.js b/src/engine/runtime.js index 66d6dee3f..b635bbd1f 100644 --- a/src/engine/runtime.js +++ b/src/engine/runtime.js @@ -2102,9 +2102,9 @@ class Runtime extends EventEmitter { const block = categoryInfo.blocks.find(b => b.info.opcode === opcode); if (!block) return; - // TODO: should this use some other category? Also, we may want to format the label in a locale-specific way. + // TODO: we may want to format the label in a locale-specific way. return { - category: 'data', + category: 'extension', // This assumes that all extensions have the same monitor color. label: `${categoryInfo.name}: ${block.info.text}` }; } diff --git a/src/serialization/sb3.js b/src/serialization/sb3.js index 63ef3235f..66d7e033a 100644 --- a/src/serialization/sb3.js +++ b/src/serialization/sb3.js @@ -1038,7 +1038,7 @@ const parseScratchObject = function (object, runtime, extensions, zip) { return Promise.all(costumePromises.concat(soundPromises)).then(() => target); }; -const deserializeMonitor = function (monitorData, runtime, targets) { +const deserializeMonitor = function (monitorData, runtime, targets, extensions) { // If the serialized monitor has spriteName defined, look up the sprite // by name in the given list of targets and update the monitor's targetId // to match the sprite's id. @@ -1115,6 +1115,12 @@ const deserializeMonitor = function (monitorData, runtime, targets) { } runtime.monitorBlocks.createBlock(monitorBlock); + + // If the block is from an extension, record it. + const extensionID = getExtensionIdForOpcode(monitorBlock.opcode); + if (extensionID) { + extensions.extensionIDs.add(extensionID); + } } // Otherwise, the monitor block will get created when the toolbox updates // after the target has been installed. @@ -1160,7 +1166,7 @@ const deserialize = function (json, runtime, zip, isSingleSprite) { return t; })) .then(targets => { - monitorObjects.map(monitorDesc => deserializeMonitor(monitorDesc, runtime, targets)); + monitorObjects.map(monitorDesc => deserializeMonitor(monitorDesc, runtime, targets, extensions)); return targets; }) .then(targets => ({