mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
Merge pull request #1413 from paulkaplan/turbo-mode
Add turbo mode events
This commit is contained in:
commit
f38b96d70a
3 changed files with 42 additions and 0 deletions
|
@ -322,6 +322,22 @@ class Runtime extends EventEmitter {
|
|||
return 'BLOCK_GLOW_OFF';
|
||||
}
|
||||
|
||||
/**
|
||||
* Event name for turning on turbo mode.
|
||||
* @const {string}
|
||||
*/
|
||||
static get TURBO_MODE_ON () {
|
||||
return 'TURBO_MODE_ON';
|
||||
}
|
||||
|
||||
/**
|
||||
* Event name for turning off turbo mode.
|
||||
* @const {string}
|
||||
*/
|
||||
static get TURBO_MODE_OFF () {
|
||||
return 'TURBO_MODE_OFF';
|
||||
}
|
||||
|
||||
/**
|
||||
* Event name when the project is started (threads may not necessarily be
|
||||
* running).
|
||||
|
|
|
@ -148,6 +148,11 @@ class VirtualMachine extends EventEmitter {
|
|||
*/
|
||||
setTurboMode (turboModeOn) {
|
||||
this.runtime.turboMode = !!turboModeOn;
|
||||
if (this.runtime.turboMode) {
|
||||
this.emit(Runtime.TURBO_MODE_ON);
|
||||
} else {
|
||||
this.emit(Runtime.TURBO_MODE_OFF);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -857,3 +857,24 @@ test('shareBlocksToTarget chooses a fresh name for a new global variable checkin
|
|||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('Setting turbo mode emits events', t => {
|
||||
let turboMode = null;
|
||||
|
||||
const vm = new VirtualMachine();
|
||||
|
||||
vm.addListener('TURBO_MODE_ON', () => {
|
||||
turboMode = true;
|
||||
});
|
||||
vm.addListener('TURBO_MODE_OFF', () => {
|
||||
turboMode = false;
|
||||
});
|
||||
|
||||
vm.setTurboMode(true);
|
||||
t.equal(turboMode, true);
|
||||
|
||||
vm.setTurboMode(false);
|
||||
t.equal(turboMode, false);
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue