diff --git a/src/extensions/scratch3_boost/index.js b/src/extensions/scratch3_boost/index.js index 83eb8dbf5..0ee52ee2f 100644 --- a/src/extensions/scratch3_boost/index.js +++ b/src/extensions/scratch3_boost/index.js @@ -1308,6 +1308,22 @@ class Scratch3BoostBlocks { } } }, + { + opcode: 'seeingColor', + text: formatMessage({ + id: 'boost.seeingColor', + default: 'seeing [COLOR] brick?', + description: 'is the color sensor seeing a certain color?' + }), + blockType: BlockType.BOOLEAN, + arguments: { + COLOR: { + type: ArgumentType.STRING, + menu: 'COLOR', + defaultValue: COLOR_ID_ANY + } + } + }, { opcode: 'whenTilted', text: formatMessage({ @@ -1925,6 +1941,20 @@ class Scratch3BoostBlocks { return this._isColor(args.COLOR); } + /** + * Test whether the vision sensor is detecting a certain color. + * @param {object} args - the block's arguments. + * @return {boolean} - true when the color sensor senses the specified color. + */ + seeingColor (args) { + switch (args.COLOR) { + case COLOR_ID_ANY: + return this._peripheral.color !== COLOR_ID_NONE; + default: + return args.COLOR === this._peripheral.color; + } + } + /** * Test whether the vision sensor is detecting a certain color. * @param {string} colorId - the id of the color to test.