Add green flag and stop button functions

This commit is contained in:
Tim Mickel 2016-04-29 17:58:31 -04:00
parent b67558d777
commit b92a73da0f
3 changed files with 61 additions and 5 deletions

View file

@ -195,6 +195,34 @@ Runtime.prototype.toggleStack = function (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
* inactive threads after each iteration.

28
vm.js
View file

@ -1373,6 +1373,34 @@
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
* inactive threads after each iteration.

10
vm.min.js vendored

File diff suppressed because one or more lines are too long