mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
add add monitor action
This commit is contained in:
parent
b1355c6b0b
commit
b2e0a632e3
4 changed files with 35 additions and 9 deletions
|
@ -292,6 +292,21 @@ class Blocks {
|
|||
block.isMonitored = args.value;
|
||||
if (optRuntime && wasMonitored && !block.isMonitored) {
|
||||
optRuntime.removeMonitors([{id: block.id}]);
|
||||
} else if (optRuntime && !wasMonitored && block.isMonitored) {
|
||||
optRuntime.addMonitors(
|
||||
// Ensure that value is not undefined, since React requires it
|
||||
[{
|
||||
// @todo(dd) this will collide if multiple sprites use same block
|
||||
id: block.id,
|
||||
category: 'data',
|
||||
// @todo(dd) how to handle translation here?
|
||||
label: block.opcode,
|
||||
value: '',
|
||||
x: 0,
|
||||
// @todo(dd) place below the last monitor instead
|
||||
y: 0
|
||||
}]
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -87,7 +87,6 @@ const execute = function (sequencer, thread) {
|
|||
} else {
|
||||
// In a non-hat, report the value visually if necessary if
|
||||
// at the top of the thread stack.
|
||||
|
||||
if (typeof resolvedValue !== 'undefined' && thread.atStackTop()) {
|
||||
if (thread.showVisualReport) {
|
||||
runtime.visualReport(currentBlockId, resolvedValue);
|
||||
|
@ -95,15 +94,8 @@ const execute = function (sequencer, thread) {
|
|||
|
||||
if (thread.updateMonitor) {
|
||||
runtime.updateMonitors([{
|
||||
// @todo(dd) this will collide if multiple sprites use same block
|
||||
id: currentBlockId,
|
||||
category: 'data',
|
||||
// @todo(dd) how to handle translation here?
|
||||
label: blockContainer.getOpcode(blockContainer.getBlock(currentBlockId)),
|
||||
value: String(resolvedValue),
|
||||
x: 0,
|
||||
// @todo(dd) place below the last monitor instead
|
||||
y: 0
|
||||
value: String(resolvedValue)
|
||||
}]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -249,6 +249,14 @@ class Runtime extends EventEmitter {
|
|||
return 'MONITORS_REMOVED';
|
||||
}
|
||||
|
||||
/**
|
||||
* Event name for monitors added.
|
||||
* @const {string}
|
||||
*/
|
||||
static get MONITORS_ADDED () {
|
||||
return 'MONITORS_ADDED';
|
||||
}
|
||||
|
||||
/**
|
||||
* How rapidly we try to step threads by default, in ms.
|
||||
*/
|
||||
|
@ -881,6 +889,14 @@ class Runtime extends EventEmitter {
|
|||
this.emit(Runtime.MONITORS_REMOVED, monitors);
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit a monitor update which adds if it doesn't already exist the given monitors.
|
||||
* @param {!Array} monitors Array of monitors to add.
|
||||
*/
|
||||
addMonitors (monitors) {
|
||||
this.emit(Runtime.MONITORS_ADDED, monitors);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a target by its id.
|
||||
* @param {string} targetId Id of target to find.
|
||||
|
|
|
@ -61,6 +61,9 @@ class VirtualMachine extends EventEmitter {
|
|||
instance.runtime.on(Runtime.MONITORS_REMOVED, monitorList => {
|
||||
instance.emit(Runtime.MONITORS_REMOVED, monitorList);
|
||||
});
|
||||
instance.runtime.on(Runtime.MONITORS_ADDED, monitorList => {
|
||||
instance.emit(Runtime.MONITORS_ADDED, monitorList);
|
||||
});
|
||||
|
||||
this.blockListener = this.blockListener.bind(this);
|
||||
this.flyoutBlockListener = this.flyoutBlockListener.bind(this);
|
||||
|
|
Loading…
Reference in a new issue