mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-06-04 17:44:43 -04:00
Complete implementation of stop block (#271)
* "Other scripts in stage" sb2 * Complete implementation of "stop" block
This commit is contained in:
parent
c45b420115
commit
3bfd755e60
4 changed files with 29 additions and 5 deletions
src
|
@ -133,9 +133,16 @@ Scratch3ControlBlocks.prototype.ifElse = function(args, util) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Scratch3ControlBlocks.prototype.stop = function() {
|
Scratch3ControlBlocks.prototype.stop = function(args, util) {
|
||||||
// @todo - don't use this.runtime
|
var option = args.STOP_OPTION;
|
||||||
this.runtime.stopAll();
|
if (option == 'all') {
|
||||||
|
util.stopAll();
|
||||||
|
} else if (option == 'other scripts in sprite' ||
|
||||||
|
option == 'other scripts in stage') {
|
||||||
|
util.stopOtherTargetThreads();
|
||||||
|
} else if (option == 'this script') {
|
||||||
|
util.stopThread();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// @todo (GH-146): remove.
|
// @todo (GH-146): remove.
|
||||||
|
|
|
@ -176,6 +176,15 @@ var execute = function (sequencer, thread) {
|
||||||
startBranch: function (branchNum) {
|
startBranch: function (branchNum) {
|
||||||
sequencer.stepToBranch(thread, branchNum);
|
sequencer.stepToBranch(thread, branchNum);
|
||||||
},
|
},
|
||||||
|
stopAll: function () {
|
||||||
|
runtime.stopAll();
|
||||||
|
},
|
||||||
|
stopOtherTargetThreads: function() {
|
||||||
|
runtime.stopForTarget(target, thread);
|
||||||
|
},
|
||||||
|
stopThread: function() {
|
||||||
|
sequencer.retireThread(thread);
|
||||||
|
},
|
||||||
startProcedure: function (procedureName) {
|
startProcedure: function (procedureName) {
|
||||||
sequencer.stepToProcedure(thread, procedureName);
|
sequencer.stepToProcedure(thread, procedureName);
|
||||||
},
|
},
|
||||||
|
|
|
@ -246,6 +246,9 @@ Runtime.prototype._pushThread = function (id, target) {
|
||||||
* @param {?Thread} thread Thread object to remove from actives
|
* @param {?Thread} thread Thread object to remove from actives
|
||||||
*/
|
*/
|
||||||
Runtime.prototype._removeThread = function (thread) {
|
Runtime.prototype._removeThread = function (thread) {
|
||||||
|
// Inform sequencer to stop executing that thread.
|
||||||
|
this.sequencer.retireThread(thread);
|
||||||
|
// Remove from the list.
|
||||||
var i = this.threads.indexOf(thread);
|
var i = this.threads.indexOf(thread);
|
||||||
if (i > -1) {
|
if (i > -1) {
|
||||||
this.threads.splice(i, 1);
|
this.threads.splice(i, 1);
|
||||||
|
@ -382,10 +385,14 @@ Runtime.prototype.disposeTarget = function (target) {
|
||||||
/**
|
/**
|
||||||
* Stop any threads acting on the target.
|
* Stop any threads acting on the target.
|
||||||
* @param {!Target} target Target to stop threads for.
|
* @param {!Target} target Target to stop threads for.
|
||||||
|
* @param {Thread=} opt_threadException Optional thread to skip.
|
||||||
*/
|
*/
|
||||||
Runtime.prototype.stopForTarget = function (target) {
|
Runtime.prototype.stopForTarget = function (target, opt_threadException) {
|
||||||
// Stop any threads on the target.
|
// Stop any threads on the target.
|
||||||
for (var i = 0; i < this.threads.length; i++) {
|
for (var i = 0; i < this.threads.length; i++) {
|
||||||
|
if (this.threads[i] === opt_threadException) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (this.threads[i].target == target) {
|
if (this.threads[i].target == target) {
|
||||||
this._removeThread(this.threads[i]);
|
this._removeThread(this.threads[i]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -369,7 +369,8 @@ function parseBlock (sb2block) {
|
||||||
if (oldOpcode == 'stopScripts') {
|
if (oldOpcode == 'stopScripts') {
|
||||||
// Mutation for stop block: if the argument is 'other scripts',
|
// Mutation for stop block: if the argument is 'other scripts',
|
||||||
// the block needs a next connection.
|
// the block needs a next connection.
|
||||||
if (sb2block[1] == 'other scripts in sprite') {
|
if (sb2block[1] == 'other scripts in sprite' ||
|
||||||
|
sb2block[1] == 'other scripts in stage') {
|
||||||
activeBlock.mutation = {
|
activeBlock.mutation = {
|
||||||
tagName: 'mutation',
|
tagName: 'mutation',
|
||||||
hasnext: 'true',
|
hasnext: 'true',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue