Skip to content

Commit

Permalink
Merge pull request #1096 from towerofnix/warpspeed-vm
Browse files Browse the repository at this point in the history
Implement "all at once" block
  • Loading branch information
kchadha committed May 1, 2018
2 parents 3161831 + 8d13bf3 commit 2b6f96a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/blocks/scratch3_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}

Expand Down Expand Up @@ -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;
9 changes: 9 additions & 0 deletions src/serialization/sb2_specmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,15 @@ const specMap = {
argMap: [
]
},
'warpSpeed': {
opcode: 'control_all_at_once',
argMap: [
{
type: 'input',
inputName: 'SUBSTACK'
}
]
},
'touching:': {
opcode: 'sensing_touchingobject',
argMap: [
Expand Down
18 changes: 18 additions & 0 deletions test/unit/blocks_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

0 comments on commit 2b6f96a

Please sign in to comment.