Merge pull request #1096 from towerofnix/warpspeed-vm

Implement "all at once" block
This commit is contained in:
kchadha 2018-05-01 15:43:37 -04:00 committed by GitHub
commit 2b6f96ae0a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 1 deletions

View file

@ -35,7 +35,8 @@ class Scratch3ControlBlocks {
control_delete_this_clone: this.deleteClone,
control_get_counter: this.getCounter,
control_incr_counter: this.incrCounter,
control_clear_counter: this.clearCounter
control_clear_counter: this.clearCounter,
control_all_at_once: this.allAtOnce
};
}
@ -182,6 +183,16 @@ class Scratch3ControlBlocks {
incrCounter () {
this._counter++;
}
allAtOnce (args, util) {
// Since the "all at once" block is implemented for compatiblity with
// Scratch 2.0 projects, it behaves the same way it did in 2.0, which
// is to simply run the contained script (like "if 1 = 1").
// (In early versions of Scratch 2.0, it would work the same way as
// "run without screen refresh" custom blocks do now, but this was
// removed before the release of 2.0.)
util.startBranch(1, false);
}
}
module.exports = Scratch3ControlBlocks;

View file

@ -899,6 +899,15 @@ const specMap = {
argMap: [
]
},
'warpSpeed': {
opcode: 'control_all_at_once',
argMap: [
{
type: 'input',
inputName: 'SUBSTACK'
}
]
},
'touching:': {
opcode: 'sensing_touchingobject',
argMap: [

View file

@ -208,3 +208,21 @@ test('counter, incrCounter, clearCounter', t => {
t.end();
});
test('allAtOnce', t => {
const rt = new Runtime();
const c = new Control(rt);
// Test harness (mocks `util`)
let ran = false;
const util = {
startBranch: function () {
ran = true;
}
};
// Execute test
c.allAtOnce({}, util);
t.true(ran);
t.end();
});