mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-09 14:32:07 -05:00
Add green flag and stop button functions
This commit is contained in:
parent
b67558d777
commit
b92a73da0f
3 changed files with 61 additions and 5 deletions
|
@ -195,6 +195,34 @@ Runtime.prototype.toggleStack = function (stackId) {
|
||||||
this._pushThread(stackId);
|
this._pushThread(stackId);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Green flag, which stops currently running threads
|
||||||
|
* and adds all top-level stacks that start with the green flag
|
||||||
|
*/
|
||||||
|
Runtime.prototype.greenFlag = function () {
|
||||||
|
// Remove all existing threads
|
||||||
|
for (var i = 0; i < this.threads.length; i++) {
|
||||||
|
this._removeThread(this.threads[i]);
|
||||||
|
}
|
||||||
|
// Add all top stacks with green flag
|
||||||
|
for (var j = 0; j < this.stacks.length; j++) {
|
||||||
|
var topBlock = this.stacks[j];
|
||||||
|
if (this.blocks[topBlock].opcode === 'event_whenflagclicked') {
|
||||||
|
this._pushThread(this.stacks[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop "everything"
|
||||||
|
*/
|
||||||
|
Runtime.prototype.stopAll = function () {
|
||||||
|
for (var i = 0; i < this.threads.length; i++) {
|
||||||
|
this._removeThread(this.threads[i]);
|
||||||
|
}
|
||||||
|
// @todo call stop function in all extensions/packages/WeDo stub
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Repeatedly run `sequencer.stepThreads` and filter out
|
* Repeatedly run `sequencer.stepThreads` and filter out
|
||||||
* inactive threads after each iteration.
|
* inactive threads after each iteration.
|
||||||
|
|
28
vm.js
28
vm.js
|
@ -1373,6 +1373,34 @@
|
||||||
this._pushThread(stackId);
|
this._pushThread(stackId);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Green flag, which stops currently running threads
|
||||||
|
* and adds all top-level stacks that start with the green flag
|
||||||
|
*/
|
||||||
|
Runtime.prototype.greenFlag = function () {
|
||||||
|
// Remove all existing threads
|
||||||
|
for (var i = 0; i < this.threads.length; i++) {
|
||||||
|
this._removeThread(this.threads[i]);
|
||||||
|
}
|
||||||
|
// Add all top stacks with green flag
|
||||||
|
for (var j = 0; j < this.stacks.length; j++) {
|
||||||
|
var topBlock = this.stacks[j];
|
||||||
|
if (this.blocks[topBlock].opcode === 'event_whenflagclicked') {
|
||||||
|
this._pushThread(this.stacks[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop "everything"
|
||||||
|
*/
|
||||||
|
Runtime.prototype.stopAll = function () {
|
||||||
|
for (var i = 0; i < this.threads.length; i++) {
|
||||||
|
this._removeThread(this.threads[i]);
|
||||||
|
}
|
||||||
|
// @todo call stop function in all extensions/packages/WeDo stub
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Repeatedly run `sequencer.stepThreads` and filter out
|
* Repeatedly run `sequencer.stepThreads` and filter out
|
||||||
* inactive threads after each iteration.
|
* inactive threads after each iteration.
|
||||||
|
|
10
vm.min.js
vendored
10
vm.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue