mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-25 15:32:40 -05:00
Merge pull request #1303 from paulkaplan/loudness-hat
Add implementation for "When loudness >" block
This commit is contained in:
commit
26e59969de
2 changed files with 18 additions and 2 deletions
|
@ -69,9 +69,11 @@ class Scratch3EventBlocks {
|
||||||
hatGreaterThanPredicate (args, util) {
|
hatGreaterThanPredicate (args, util) {
|
||||||
const option = Cast.toString(args.WHENGREATERTHANMENU).toLowerCase();
|
const option = Cast.toString(args.WHENGREATERTHANMENU).toLowerCase();
|
||||||
const value = Cast.toNumber(args.VALUE);
|
const value = Cast.toNumber(args.VALUE);
|
||||||
// @todo: Other cases :)
|
switch (option) {
|
||||||
if (option === 'timer') {
|
case 'timer':
|
||||||
return util.ioQuery('clock', 'projectTimer') > value;
|
return util.ioQuery('clock', 'projectTimer') > value;
|
||||||
|
case 'loudness':
|
||||||
|
return this.runtime.audioEngine && this.runtime.audioEngine.getLoudness() > value;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,3 +96,17 @@ test('#760 - broadcastAndWait', t => {
|
||||||
|
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('When > hat - loudness', t => {
|
||||||
|
const rt = new Runtime();
|
||||||
|
rt.audioEngine = {getLoudness: () => 10};
|
||||||
|
const e = new Event(rt);
|
||||||
|
const args = {
|
||||||
|
WHENGREATERTHANMENU: 'LOUDNESS',
|
||||||
|
VALUE: '11'
|
||||||
|
};
|
||||||
|
t.equal(e.hatGreaterThanPredicate(args), false);
|
||||||
|
args.VALUE = '5';
|
||||||
|
t.equal(e.hatGreaterThanPredicate(args), true);
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue