mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
Add visual reporting of top-level reporter execution
This commit is contained in:
parent
d4353458ff
commit
9c6dca8131
4 changed files with 32 additions and 0 deletions
|
@ -78,6 +78,9 @@ window.onload = function() {
|
||||||
vm.on('BLOCK_GLOW_OFF', function(data) {
|
vm.on('BLOCK_GLOW_OFF', function(data) {
|
||||||
workspace.glowBlock(data.id, false);
|
workspace.glowBlock(data.id, false);
|
||||||
});
|
});
|
||||||
|
vm.on('VISUAL_REPORT', function(data) {
|
||||||
|
workspace.reportValue(data.id, data.value);
|
||||||
|
});
|
||||||
|
|
||||||
// Run threads
|
// Run threads
|
||||||
vm.start();
|
vm.start();
|
||||||
|
|
|
@ -96,6 +96,10 @@ var execute = function (sequencer, thread) {
|
||||||
primitiveReportedValue.then(function(resolvedValue) {
|
primitiveReportedValue.then(function(resolvedValue) {
|
||||||
// Promise resolved: the primitive reported a value.
|
// Promise resolved: the primitive reported a value.
|
||||||
thread.pushReportedValue(resolvedValue);
|
thread.pushReportedValue(resolvedValue);
|
||||||
|
// Report the value visually if necessary.
|
||||||
|
if (thread.peekStack() === thread.topBlock) {
|
||||||
|
runtime.visualReport(thread.peekStack(), resolvedValue);
|
||||||
|
}
|
||||||
thread.setStatus(Thread.STATUS_RUNNING);
|
thread.setStatus(Thread.STATUS_RUNNING);
|
||||||
sequencer.proceedThread(thread);
|
sequencer.proceedThread(thread);
|
||||||
}, function(rejectionReason) {
|
}, function(rejectionReason) {
|
||||||
|
@ -107,6 +111,10 @@ var execute = function (sequencer, thread) {
|
||||||
});
|
});
|
||||||
} else if (thread.status === Thread.STATUS_RUNNING) {
|
} else if (thread.status === Thread.STATUS_RUNNING) {
|
||||||
thread.pushReportedValue(primitiveReportedValue);
|
thread.pushReportedValue(primitiveReportedValue);
|
||||||
|
// Report the value visually if necessary.
|
||||||
|
if (thread.peekStack() === thread.topBlock) {
|
||||||
|
runtime.visualReport(thread.peekStack(), primitiveReportedValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,12 @@ Runtime.BLOCK_GLOW_ON = 'BLOCK_GLOW_ON';
|
||||||
*/
|
*/
|
||||||
Runtime.BLOCK_GLOW_OFF = 'BLOCK_GLOW_OFF';
|
Runtime.BLOCK_GLOW_OFF = 'BLOCK_GLOW_OFF';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event name for visual value report.
|
||||||
|
* @const {string}
|
||||||
|
*/
|
||||||
|
Runtime.VISUAL_REPORT = 'VISUAL_REPORT';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inherit from EventEmitter
|
* Inherit from EventEmitter
|
||||||
*/
|
*/
|
||||||
|
@ -218,6 +224,15 @@ Runtime.prototype.glowBlock = function (blockId, isGlowing) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emit value for reporter to show in the blocks.
|
||||||
|
* @param {string} blockId ID for the block.
|
||||||
|
* @param {string} value Value to show associated with the block.
|
||||||
|
*/
|
||||||
|
Runtime.prototype.visualReport = function (blockId, value) {
|
||||||
|
this.emit(Runtime.VISUAL_REPORT, blockId, String(value));
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the Target for a particular thread.
|
* Return the Target for a particular thread.
|
||||||
* @param {!Thread} thread Thread to determine target for.
|
* @param {!Thread} thread Thread to determine target for.
|
||||||
|
|
|
@ -53,6 +53,9 @@ function VirtualMachine () {
|
||||||
instance.runtime.on(Runtime.BLOCK_GLOW_OFF, function (id) {
|
instance.runtime.on(Runtime.BLOCK_GLOW_OFF, function (id) {
|
||||||
instance.emit(Runtime.BLOCK_GLOW_OFF, {id: id});
|
instance.emit(Runtime.BLOCK_GLOW_OFF, {id: id});
|
||||||
});
|
});
|
||||||
|
instance.runtime.on(Runtime.VISUAL_REPORT, function (id, value) {
|
||||||
|
instance.emit(Runtime.VISUAL_REPORT, {id: id, value: value});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -158,6 +161,9 @@ if (ENV_WORKER) {
|
||||||
self.vmInstance.runtime.on(Runtime.BLOCK_GLOW_OFF, function (id) {
|
self.vmInstance.runtime.on(Runtime.BLOCK_GLOW_OFF, function (id) {
|
||||||
self.postMessage({method: Runtime.BLOCK_GLOW_OFF, id: id});
|
self.postMessage({method: Runtime.BLOCK_GLOW_OFF, id: id});
|
||||||
});
|
});
|
||||||
|
self.vmInstance.runtime.on(Runtime.VISUAL_REPORT, function (id, value) {
|
||||||
|
self.postMessage({method: Runtime.VISUAL_REPORT, id: id, value: value});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue