From 255e160ebb00c123e373a5199b66e18b1e0ca629 Mon Sep 17 00:00:00 2001 From: DD Date: Thu, 16 Nov 2017 17:19:51 -0500 Subject: [PATCH] Change it so we dont have to do string manipulation on IDs to get data out of events --- src/blocks/scratch3_looks.js | 8 ++++---- src/blocks/scratch3_motion.js | 6 +++--- src/blocks/scratch3_sensing.js | 10 +++++----- src/blocks/scratch3_sound.js | 2 +- src/engine/blocks.js | 11 +++++------ src/virtual-machine.js | 9 --------- 6 files changed, 18 insertions(+), 28 deletions(-) diff --git a/src/blocks/scratch3_looks.js b/src/blocks/scratch3_looks.js index a64f095b0..6c8f4fe3b 100644 --- a/src/blocks/scratch3_looks.js +++ b/src/blocks/scratch3_looks.js @@ -244,10 +244,10 @@ class Scratch3LooksBlocks { getMonitored () { return { - size: {isSpriteSpecific: true}, - costumeorder: {isSpriteSpecific: true}, - backdroporder: {}, - backdropname: {} + looks_size: {isSpriteSpecific: true}, + looks_costumeorder: {isSpriteSpecific: true}, + looks_backdroporder: {}, + looks_backdropname: {} }; } diff --git a/src/blocks/scratch3_motion.js b/src/blocks/scratch3_motion.js index b30138d3e..0b206975b 100644 --- a/src/blocks/scratch3_motion.js +++ b/src/blocks/scratch3_motion.js @@ -40,9 +40,9 @@ class Scratch3MotionBlocks { getMonitored () { return { - xposition: {isSpriteSpecific: true}, - yposition: {isSpriteSpecific: true}, - direction: {isSpriteSpecific: true} + motion_xposition: {isSpriteSpecific: true}, + motion_yposition: {isSpriteSpecific: true}, + motion_direction: {isSpriteSpecific: true} }; } diff --git a/src/blocks/scratch3_sensing.js b/src/blocks/scratch3_sensing.js index d51dd5d3b..fa129f6c0 100644 --- a/src/blocks/scratch3_sensing.js +++ b/src/blocks/scratch3_sensing.js @@ -51,11 +51,11 @@ class Scratch3SensingBlocks { getMonitored () { return { - answer: {}, - loudness: {}, - timer: {}, - of: {}, - current: {} + sensing_answer: {}, + sensing_loudness: {}, + sensing_timer: {}, + sensing_of: {}, + sensing_current: {} }; } diff --git a/src/blocks/scratch3_sound.js b/src/blocks/scratch3_sound.js index d3f3f92ac..be78ec7e2 100644 --- a/src/blocks/scratch3_sound.js +++ b/src/blocks/scratch3_sound.js @@ -105,7 +105,7 @@ class Scratch3SoundBlocks { getMonitored () { return { - volume: {} + sound_volume: {} }; } diff --git a/src/engine/blocks.js b/src/engine/blocks.js index 155a2e5e8..a5b6ad45c 100644 --- a/src/engine/blocks.js +++ b/src/engine/blocks.js @@ -327,7 +327,11 @@ class Blocks { break; case 'checkbox': block.isMonitored = args.value; - block.targetId = args.isSpriteSpecific ? this._getTargetIdFromBlockId(block.id) : null; + if (optRuntime) { + const isSpriteSpecific = optRuntime.monitorBlockInfo.hasOwnProperty(block.opcode) && + optRuntime.monitorBlockInfo[block.opcode].isSpriteSpecific; + block.targetId = isSpriteSpecific ? optRuntime.getEditingTarget().id : null; + } if (optRuntime && wasMonitored && !block.isMonitored) { optRuntime.requestRemoveMonitor(block.id); } else if (optRuntime && !wasMonitored && block.isMonitored) { @@ -416,11 +420,6 @@ class Blocks { }); } - _getTargetIdFromBlockId (blockId) { - // First word of block ID. See makeToolboxXML in scratch-gui - return blockId.split('_')[0]; - } - /** * Block management: delete blocks and their associated scripts. * @param {!object} e Blockly delete event to be processed. diff --git a/src/virtual-machine.js b/src/virtual-machine.js index 5c5361bae..994de9860 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -578,15 +578,6 @@ class VirtualMachine extends EventEmitter { // Filter events by type, since monitor blocks only need to listen to these events. // Monitor blocks shouldn't be destroyed when flyout blocks are deleted. if (['create', 'change'].indexOf(e.type) !== -1) { - let blockType = e.blockId.split('_'); - blockType = blockType[blockType.length - 1]; - if (!this.runtime.monitorBlockInfo.hasOwnProperty(blockType)) { - return; - } - if (!this.runtime.monitorBlockInfo.hasOwnProperty(blockType) || - this.runtime.monitorBlockInfo[blockType].isSpriteSpecific) { - e.isSpriteSpecific = true; - } this.runtime.monitorBlocks.blocklyListen(e, this.runtime); } }