mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-10 15:02:06 -05:00
Refactor script glowing into its own runtime function
This commit is contained in:
parent
a991710a4b
commit
94e389c8fb
1 changed files with 17 additions and 2 deletions
|
@ -135,12 +135,14 @@ Runtime.prototype.getOpcodeFunction = function (opcode) {
|
|||
/**
|
||||
* Create a thread and push it to the list of threads.
|
||||
* @param {!string} id ID of block that starts the stack
|
||||
* @return {!Thread} The newly created thread.
|
||||
*/
|
||||
Runtime.prototype._pushThread = function (id) {
|
||||
this.emit(Runtime.STACK_GLOW_ON, id);
|
||||
var thread = new Thread(id);
|
||||
this.glowScript(id, true);
|
||||
thread.pushStack(id);
|
||||
this.threads.push(thread);
|
||||
return thread;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -150,7 +152,7 @@ Runtime.prototype._pushThread = function (id) {
|
|||
Runtime.prototype._removeThread = function (thread) {
|
||||
var i = this.threads.indexOf(thread);
|
||||
if (i > -1) {
|
||||
this.emit(Runtime.STACK_GLOW_OFF, thread.topBlock);
|
||||
this.glowScript(thread.topBlock, false);
|
||||
this.threads.splice(i, 1);
|
||||
}
|
||||
};
|
||||
|
@ -234,6 +236,19 @@ Runtime.prototype.glowBlock = function (blockId, isGlowing) {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Emit feedback for script glowing.
|
||||
* @param {?string} topBlockId ID for the top block to update glow
|
||||
* @param {boolean} isGlowing True to turn on glow; false to turn off.
|
||||
*/
|
||||
Runtime.prototype.glowScript = function (topBlockId, isGlowing) {
|
||||
if (isGlowing) {
|
||||
this.emit(Runtime.STACK_GLOW_ON, topBlockId);
|
||||
} else {
|
||||
this.emit(Runtime.STACK_GLOW_OFF, topBlockId);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Emit value for reporter to show in the blocks.
|
||||
* @param {string} blockId ID for the block.
|
||||
|
|
Loading…
Reference in a new issue