Skip to content

Commit 26e5996

Browse files
authored
Merge pull request scratchfoundation#1303 from paulkaplan/loudness-hat
Add implementation for "When loudness >" block
2 parents 06573f4 + 2c7de63 commit 26e5996

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/blocks/scratch3_event.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@ class Scratch3EventBlocks {
6969
hatGreaterThanPredicate (args, util) {
7070
const option = Cast.toString(args.WHENGREATERTHANMENU).toLowerCase();
7171
const value = Cast.toNumber(args.VALUE);
72-
// @todo: Other cases :)
73-
if (option === 'timer') {
72+
switch (option) {
73+
case 'timer':
7474
return util.ioQuery('clock', 'projectTimer') > value;
75+
case 'loudness':
76+
return this.runtime.audioEngine && this.runtime.audioEngine.getLoudness() > value;
7577
}
7678
return false;
7779
}

test/unit/blocks_event.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,17 @@ test('#760 - broadcastAndWait', t => {
9696

9797
t.end();
9898
});
99+
100+
test('When > hat - loudness', t => {
101+
const rt = new Runtime();
102+
rt.audioEngine = {getLoudness: () => 10};
103+
const e = new Event(rt);
104+
const args = {
105+
WHENGREATERTHANMENU: 'LOUDNESS',
106+
VALUE: '11'
107+
};
108+
t.equal(e.hatGreaterThanPredicate(args), false);
109+
args.VALUE = '5';
110+
t.equal(e.hatGreaterThanPredicate(args), true);
111+
t.end();
112+
});

0 commit comments

Comments
 (0)