From 2c7de6380e6971612478d128b665d7d5dd67a639 Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Thu, 5 Jul 2018 09:42:00 -0400 Subject: [PATCH] Add implementation for "When loudness >" block --- src/blocks/scratch3_event.js | 6 ++++-- test/unit/blocks_event.js | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/blocks/scratch3_event.js b/src/blocks/scratch3_event.js index 37a254467..4da1dfae3 100644 --- a/src/blocks/scratch3_event.js +++ b/src/blocks/scratch3_event.js @@ -69,9 +69,11 @@ class Scratch3EventBlocks { hatGreaterThanPredicate (args, util) { const option = Cast.toString(args.WHENGREATERTHANMENU).toLowerCase(); const value = Cast.toNumber(args.VALUE); - // @todo: Other cases :) - if (option === 'timer') { + switch (option) { + case 'timer': return util.ioQuery('clock', 'projectTimer') > value; + case 'loudness': + return this.runtime.audioEngine && this.runtime.audioEngine.getLoudness() > value; } return false; } diff --git a/test/unit/blocks_event.js b/test/unit/blocks_event.js index 672ea332c..0cdc58e54 100644 --- a/test/unit/blocks_event.js +++ b/test/unit/blocks_event.js @@ -96,3 +96,17 @@ test('#760 - broadcastAndWait', t => { 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(); +});