mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 23:12:24 -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 () {
|
getMonitored () {
|
||||||
return {
|
return {
|
||||||
size: {isSpriteSpecific: true},
|
looks_size: {isSpriteSpecific: true},
|
||||||
costumeorder: {isSpriteSpecific: true},
|
looks_costumeorder: {isSpriteSpecific: true},
|
||||||
backdroporder: {},
|
looks_backdroporder: {},
|
||||||
backdropname: {}
|
looks_backdropname: {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,9 +40,9 @@ class Scratch3MotionBlocks {
|
||||||
|
|
||||||
getMonitored () {
|
getMonitored () {
|
||||||
return {
|
return {
|
||||||
xposition: {isSpriteSpecific: true},
|
motion_xposition: {isSpriteSpecific: true},
|
||||||
yposition: {isSpriteSpecific: true},
|
motion_yposition: {isSpriteSpecific: true},
|
||||||
direction: {isSpriteSpecific: true}
|
motion_direction: {isSpriteSpecific: true}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,11 +51,11 @@ class Scratch3SensingBlocks {
|
||||||
|
|
||||||
getMonitored () {
|
getMonitored () {
|
||||||
return {
|
return {
|
||||||
answer: {},
|
sensing_answer: {},
|
||||||
loudness: {},
|
sensing_loudness: {},
|
||||||
timer: {},
|
sensing_timer: {},
|
||||||
of: {},
|
sensing_of: {},
|
||||||
current: {}
|
sensing_current: {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,7 @@ class Scratch3SoundBlocks {
|
||||||
|
|
||||||
getMonitored () {
|
getMonitored () {
|
||||||
return {
|
return {
|
||||||
volume: {}
|
sound_volume: {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -327,7 +327,11 @@ class Blocks {
|
||||||
break;
|
break;
|
||||||
case 'checkbox':
|
case 'checkbox':
|
||||||
block.isMonitored = args.value;
|
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) {
|
if (optRuntime && wasMonitored && !block.isMonitored) {
|
||||||
optRuntime.requestRemoveMonitor(block.id);
|
optRuntime.requestRemoveMonitor(block.id);
|
||||||
} else if (optRuntime && !wasMonitored && block.isMonitored) {
|
} 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.
|
* Block management: delete blocks and their associated scripts.
|
||||||
* @param {!object} e Blockly delete event to be processed.
|
* @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.
|
// 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.
|
// Monitor blocks shouldn't be destroyed when flyout blocks are deleted.
|
||||||
if (['create', 'change'].indexOf(e.type) !== -1) {
|
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);
|
this.runtime.monitorBlocks.blocklyListen(e, this.runtime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue