Add boolean “seeing color brick?”

This commit is contained in:
Eric Rosenbaum 2019-04-15 09:59:03 -04:00
parent bd5bc7947b
commit 1381d2c4c0

View file

@ -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', opcode: 'whenTilted',
text: formatMessage({ text: formatMessage({
@ -1925,6 +1941,20 @@ class Scratch3BoostBlocks {
return this._isColor(args.COLOR); 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. * Test whether the vision sensor is detecting a certain color.
* @param {string} colorId - the id of the color to test. * @param {string} colorId - the id of the color to test.