mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-08-14 15:28:50 -04:00
Add a block container for monitors that will run in the sequencer
This commit is contained in:
parent
75a9ad4675
commit
706e112082
5 changed files with 54 additions and 6 deletions
src/engine
|
@ -52,6 +52,13 @@ class Runtime extends EventEmitter {
|
|||
*/
|
||||
this.flyoutBlocks = new Blocks();
|
||||
|
||||
/**
|
||||
* Storage container for monitor blocks.
|
||||
* These will execute on a target maybe
|
||||
* @type {!Blocks}
|
||||
*/
|
||||
this.monitorBlocks = new Blocks();
|
||||
|
||||
/**
|
||||
* Currently known editing target for the VM.
|
||||
* @type {?Target}
|
||||
|
@ -416,8 +423,9 @@ class Runtime extends EventEmitter {
|
|||
/**
|
||||
* Toggle a script.
|
||||
* @param {!string} topBlockId ID of block that starts the script.
|
||||
* @param {?string} optTarget target ID for target to run script on. If not supplied, uses editing target.
|
||||
*/
|
||||
toggleScript (topBlockId) {
|
||||
toggleScript (topBlockId, optTarget) {
|
||||
// Remove any existing thread.
|
||||
for (let i = 0; i < this.threads.length; i++) {
|
||||
if (this.threads[i].topBlock === topBlockId) {
|
||||
|
@ -426,7 +434,7 @@ class Runtime extends EventEmitter {
|
|||
}
|
||||
}
|
||||
// Otherwise add it.
|
||||
this._pushThread(topBlockId, this._editingTarget);
|
||||
this._pushThread(topBlockId, optTarget ? optTarget : this._editingTarget);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -632,6 +640,7 @@ class Runtime extends EventEmitter {
|
|||
}
|
||||
}
|
||||
this.redrawRequested = false;
|
||||
this._pushMonitors();
|
||||
const doneThreads = this.sequencer.stepThreads();
|
||||
this._updateGlows(doneThreads);
|
||||
this._setThreadCount(this.threads.length + doneThreads.length);
|
||||
|
@ -641,6 +650,13 @@ class Runtime extends EventEmitter {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Queue monitor blocks to sequencer to be run.
|
||||
*/
|
||||
_pushMonitors () {
|
||||
this.monitorBlocks.runAllMonitored(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current editing target known by the runtime.
|
||||
* @param {!Target} editingTarget New editing target.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue