mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
Change it so we dont have to do string manipulation on IDs to get data out of events
This commit is contained in:
parent
0958db2618
commit
255e160ebb
6 changed files with 18 additions and 28 deletions
|
@ -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: {}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -51,11 +51,11 @@ class Scratch3SensingBlocks {
|
|||
|
||||
getMonitored () {
|
||||
return {
|
||||
answer: {},
|
||||
loudness: {},
|
||||
timer: {},
|
||||
of: {},
|
||||
current: {}
|
||||
sensing_answer: {},
|
||||
sensing_loudness: {},
|
||||
sensing_timer: {},
|
||||
sensing_of: {},
|
||||
sensing_current: {}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ class Scratch3SoundBlocks {
|
|||
|
||||
getMonitored () {
|
||||
return {
|
||||
volume: {}
|
||||
sound_volume: {}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue