mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 23:12:24 -05:00
clean up whencolor is seeingcolor functions
This commit is contained in:
parent
1381d2c4c0
commit
07768652f9
1 changed files with 16 additions and 25 deletions
|
@ -1933,45 +1933,36 @@ class Scratch3BoostBlocks {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test whether the vision sensor is detecting a certain color.
|
* Edge-triggering hat function, for when the vision sensor is detecting
|
||||||
|
* a certain color.
|
||||||
* @param {object} args - the block's arguments.
|
* @param {object} args - the block's arguments.
|
||||||
* @return {boolean} - true when the color sensor senses the specified color.
|
* @return {boolean} - true when the color sensor senses the specified color.
|
||||||
*/
|
*/
|
||||||
whenColor (args) {
|
whenColor (args) {
|
||||||
return this._isColor(args.COLOR);
|
if (args.COLOR === COLOR_ID_ANY) {
|
||||||
|
// For "any" color, return true if the color is not "none", and
|
||||||
|
// the color is different from the previous color detected. This
|
||||||
|
// allows the hat to trigger when the color changes from one color
|
||||||
|
// to another.
|
||||||
|
return this._peripheral.color !== COLOR_ID_NONE &&
|
||||||
|
this._peripheral.color !== this._peripheral.previousColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
return args.COLOR === this._peripheral.color;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test whether the vision sensor is detecting a certain color.
|
* A boolean reporter function, for whether the vision sensor is detecting
|
||||||
|
* a certain color.
|
||||||
* @param {object} args - the block's arguments.
|
* @param {object} args - the block's arguments.
|
||||||
* @return {boolean} - true when the color sensor senses the specified color.
|
* @return {boolean} - true when the color sensor senses the specified color.
|
||||||
*/
|
*/
|
||||||
seeingColor (args) {
|
seeingColor (args) {
|
||||||
switch (args.COLOR) {
|
if (args.COLOR === COLOR_ID_ANY) {
|
||||||
case COLOR_ID_ANY:
|
|
||||||
return this._peripheral.color !== COLOR_ID_NONE;
|
return this._peripheral.color !== COLOR_ID_NONE;
|
||||||
default:
|
|
||||||
return args.COLOR === this._peripheral.color;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
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.
|
|
||||||
* @return {boolean} - true when the color sensor senses the specified color.
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
_isColor (colorId) {
|
|
||||||
switch (colorId) {
|
|
||||||
case COLOR_ID_ANY:
|
|
||||||
if (this._peripheral.color !== COLOR_ID_NONE &&
|
|
||||||
this._peripheral.color !== this._peripheral.previousColor) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
default:
|
|
||||||
return colorId === this._peripheral.color;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue