Merge pull request #1303 from paulkaplan/loudness-hat

Add implementation for "When loudness >" block
This commit is contained in:
Paul Kaplan 2018-07-05 15:04:22 -04:00 committed by GitHub
commit 26e59969de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View file

@ -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;
} }

View file

@ -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();
});