mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-11 10:39:56 -05:00
Fire remove monitors VM event
This commit is contained in:
parent
138b4631e1
commit
b1355c6b0b
3 changed files with 29 additions and 5 deletions
|
@ -215,7 +215,7 @@ class Blocks {
|
|||
element: e.element,
|
||||
name: e.name,
|
||||
value: e.newValue
|
||||
});
|
||||
}, optRuntime);
|
||||
break;
|
||||
case 'move':
|
||||
this.moveBlock({
|
||||
|
@ -270,11 +270,13 @@ class Blocks {
|
|||
/**
|
||||
* Block management: change block field values
|
||||
* @param {!object} args Blockly change event to be processed
|
||||
* @param {?Runtime} optRuntime Optional runtime to allow changeBlock to emit actions.
|
||||
*/
|
||||
changeBlock (args) {
|
||||
changeBlock (args, optRuntime) {
|
||||
// Validate
|
||||
if (['field', 'mutation', 'checkbox'].indexOf(args.element) === -1) return;
|
||||
const block = this._blocks[args.id];
|
||||
let wasMonitored = block.isMonitored;
|
||||
if (typeof block === 'undefined') return;
|
||||
|
||||
switch (args.element) {
|
||||
|
@ -288,6 +290,9 @@ class Blocks {
|
|||
break;
|
||||
case 'checkbox':
|
||||
block.isMonitored = args.value;
|
||||
if (optRuntime && wasMonitored && !block.isMonitored) {
|
||||
optRuntime.removeMonitors([{id: block.id}]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -241,6 +241,14 @@ class Runtime extends EventEmitter {
|
|||
return 'MONITORS_UPDATE';
|
||||
}
|
||||
|
||||
/**
|
||||
* Event name for monitors removed.
|
||||
* @const {string}
|
||||
*/
|
||||
static get MONITORS_REMOVED () {
|
||||
return 'MONITORS_REMOVED';
|
||||
}
|
||||
|
||||
/**
|
||||
* How rapidly we try to step threads by default, in ms.
|
||||
*/
|
||||
|
@ -859,12 +867,20 @@ class Runtime extends EventEmitter {
|
|||
|
||||
/**
|
||||
* Emit a monitor update which adds or updates if exists the given monitors.
|
||||
* @param {!Array} monitors Array of all monitors
|
||||
* @param {!Array} monitors Array of monitors to update.
|
||||
*/
|
||||
updateMonitors (monitors) {
|
||||
this.emit(Runtime.MONITORS_UPDATE, monitors);
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit a monitor update which removes if exists the given monitors.
|
||||
* @param {!Array} monitors Array of monitors to remove.
|
||||
*/
|
||||
removeMonitors (monitors) {
|
||||
this.emit(Runtime.MONITORS_REMOVED, monitors);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a target by its id.
|
||||
* @param {string} targetId Id of target to find.
|
||||
|
|
|
@ -55,8 +55,11 @@ class VirtualMachine extends EventEmitter {
|
|||
instance.runtime.on(Runtime.SPRITE_INFO_REPORT, spriteInfo => {
|
||||
instance.emit(Runtime.SPRITE_INFO_REPORT, spriteInfo);
|
||||
});
|
||||
instance.runtime.on(Runtime.MONITORS_UPDATE, data => {
|
||||
instance.emit(Runtime.MONITORS_UPDATE, data);
|
||||
instance.runtime.on(Runtime.MONITORS_UPDATE, monitorList => {
|
||||
instance.emit(Runtime.MONITORS_UPDATE, monitorList);
|
||||
});
|
||||
instance.runtime.on(Runtime.MONITORS_REMOVED, monitorList => {
|
||||
instance.emit(Runtime.MONITORS_REMOVED, monitorList);
|
||||
});
|
||||
|
||||
this.blockListener = this.blockListener.bind(this);
|
||||
|
|
Loading…
Reference in a new issue