Change it so we dont have to do string manipulation on IDs to get data out of events

This commit is contained in:
DD 2017-11-16 17:19:51 -05:00
parent 0958db2618
commit 255e160ebb
6 changed files with 18 additions and 28 deletions

View file

@ -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: {}
};
}

View file

@ -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}
};
}

View file

@ -51,11 +51,11 @@ class Scratch3SensingBlocks {
getMonitored () {
return {
answer: {},
loudness: {},
timer: {},
of: {},
current: {}
sensing_answer: {},
sensing_loudness: {},
sensing_timer: {},
sensing_of: {},
sensing_current: {}
};
}

View file

@ -105,7 +105,7 @@ class Scratch3SoundBlocks {
getMonitored () {
return {
volume: {}
sound_volume: {}
};
}

View file

@ -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.

View file

@ -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);
}
}