Merge branch 'develop' into boostextension

This commit is contained in:
Kevin Nørby Andersen 2019-03-27 10:21:32 -07:00 committed by GitHub
commit b608a4856b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 68 additions and 65 deletions

View file

@ -19,10 +19,8 @@ const builtinExtensions = {
speech2text: () => require('../extensions/scratch3_speech2text'), speech2text: () => require('../extensions/scratch3_speech2text'),
ev3: () => require('../extensions/scratch3_ev3'), ev3: () => require('../extensions/scratch3_ev3'),
makeymakey: () => require('../extensions/scratch3_makeymakey'), makeymakey: () => require('../extensions/scratch3_makeymakey'),
boost: () => require('../extensions/scratch3_boost') boost: () => require('../extensions/scratch3_boost'),
// todo: only load this extension once we have a compatible way to load its gdxfor: () => require('../extensions/scratch3_gdx_for')
// Vernier module dependency.
// gdxfor: () => require('../extensions/scratch3_gdx_for')
}; };
/** /**

View file

@ -80,6 +80,12 @@ const SHAKEN_THRESHOLD = 30;
*/ */
const FACING_THRESHOLD = 9; const FACING_THRESHOLD = 9;
/**
* An offset for the facing threshold, used to check that we are no longer facing up.
* @type {number}
*/
const FACING_THRESHOLD_OFFSET = 5;
/** /**
* Threshold for acceleration magnitude, below which we are in freefall. * Threshold for acceleration magnitude, below which we are in freefall.
* @type {number} * @type {number}
@ -417,7 +423,9 @@ const PushPullValues = {
*/ */
const GestureValues = { const GestureValues = {
SHAKEN: 'shaken', SHAKEN: 'shaken',
STARTED_FALLING: 'started falling' STARTED_FALLING: 'started falling',
TURNED_FACE_UP: 'turned face up',
TURNED_FACE_DOWN: 'turned face down'
}; };
/** /**
@ -444,16 +452,6 @@ const AxisValues = {
Z: 'z' Z: 'z'
}; };
/**
* Enum for face menu options.
* @readonly
* @enum {string}
*/
const FaceValues = {
UP: 'up',
DOWN: 'down'
};
/** /**
* Scratch 3.0 blocks to interact with a GDX-FOR peripheral. * Scratch 3.0 blocks to interact with a GDX-FOR peripheral.
*/ */
@ -541,27 +539,6 @@ class Scratch3GdxForBlocks {
]; ];
} }
get FACE_MENU () {
return [
{
text: formatMessage({
id: 'gdxfor.up',
default: 'up',
description: 'the sensor is facing up'
}),
value: FaceValues.UP
},
{
text: formatMessage({
id: 'gdxfor.down',
default: 'down',
description: 'the sensor is facing down'
}),
value: FaceValues.DOWN
}
];
}
get PUSH_PULL_MENU () { get PUSH_PULL_MENU () {
return [ return [
{ {
@ -600,6 +577,22 @@ class Scratch3GdxForBlocks {
description: 'the sensor started free falling' description: 'the sensor started free falling'
}), }),
value: GestureValues.STARTED_FALLING value: GestureValues.STARTED_FALLING
},
{
text: formatMessage({
id: 'gdxfor.turnedFaceUp',
default: 'turned face up',
description: 'the sensor was turned to face up'
}),
value: GestureValues.TURNED_FACE_UP
},
{
text: formatMessage({
id: 'gdxfor.turnedFaceDown',
default: 'turned face down',
description: 'the sensor was turned to face down'
}),
value: GestureValues.TURNED_FACE_DOWN
} }
]; ];
} }
@ -721,22 +714,6 @@ class Scratch3GdxForBlocks {
} }
}, },
'---', '---',
{
opcode: 'isFacing',
text: formatMessage({
id: 'gdxfor.isFacing',
default: 'facing [FACING]?',
description: 'is the device facing up or down?'
}),
blockType: BlockType.BOOLEAN,
arguments: {
FACING: {
type: ArgumentType.STRING,
menu: 'faceOptions',
defaultValue: FaceValues.UP
}
}
},
{ {
opcode: 'isFreeFalling', opcode: 'isFreeFalling',
text: formatMessage({ text: formatMessage({
@ -784,8 +761,7 @@ class Scratch3GdxForBlocks {
gestureOptions: this.GESTURE_MENU, gestureOptions: this.GESTURE_MENU,
axisOptions: this.AXIS_MENU, axisOptions: this.AXIS_MENU,
tiltOptions: this.TILT_MENU, tiltOptions: this.TILT_MENU,
tiltAnyOptions: this.TILT_MENU_ANY, tiltAnyOptions: this.TILT_MENU_ANY
faceOptions: this.FACE_MENU
} }
}; };
} }
@ -812,12 +788,45 @@ class Scratch3GdxForBlocks {
return this.gestureMagnitude() > SHAKEN_THRESHOLD; return this.gestureMagnitude() > SHAKEN_THRESHOLD;
case GestureValues.STARTED_FALLING: case GestureValues.STARTED_FALLING:
return this.isFreeFalling(); return this.isFreeFalling();
case GestureValues.TURNED_FACE_UP:
return this._isFacing(GestureValues.TURNED_FACE_UP);
case GestureValues.TURNED_FACE_DOWN:
return this._isFacing(GestureValues.TURNED_FACE_DOWN);
default: default:
log.warn(`unknown gesture value in whenGesture: ${args.GESTURE}`); log.warn(`unknown gesture value in whenGesture: ${args.GESTURE}`);
return false; return false;
} }
} }
_isFacing (direction) {
if (typeof this._facingUp === 'undefined') {
this._facingUp = false;
}
if (typeof this._facingDown === 'undefined') {
this._facingDown = false;
}
// If the sensor is already facing up or down, reduce the threshold.
// This prevents small fluctations in acceleration while it is being
// turned from causing the hat block to trigger multiple times.
let threshold = FACING_THRESHOLD;
if (this._facingUp || this._facingDown) {
threshold -= FACING_THRESHOLD_OFFSET;
}
this._facingUp = this._peripheral.getAccelerationZ() > threshold;
this._facingDown = this._peripheral.getAccelerationZ() < threshold * -1;
switch (direction) {
case GestureValues.TURNED_FACE_UP:
return this._facingUp;
case GestureValues.TURNED_FACE_DOWN:
return this._facingDown;
default:
return false;
}
}
whenTilted (args) { whenTilted (args) {
return this._isTilted(args.TILT); return this._isTilted(args.TILT);
} }
@ -919,17 +928,6 @@ class Scratch3GdxForBlocks {
); );
} }
isFacing (args) {
switch (args.FACING) {
case FaceValues.UP:
return this._peripheral.getAccelerationZ() > FACING_THRESHOLD;
case FaceValues.DOWN:
return this._peripheral.getAccelerationZ() < FACING_THRESHOLD * -1;
default:
log.warn(`Unknown direction in isFacing: ${args.FACING}`);
}
}
isFreeFalling () { isFreeFalling () {
// When the peripheral is not connected, the acceleration magnitude // When the peripheral is not connected, the acceleration magnitude
// is 0 instead of ~9.8, which ends up calculating as a positive // is 0 instead of ~9.8, which ends up calculating as a positive

View file

@ -84,6 +84,7 @@ const DUTCH_ID = 'nl';
const ENGLISH_ID = 'en'; const ENGLISH_ID = 'en';
const FRENCH_ID = 'fr'; const FRENCH_ID = 'fr';
const GERMAN_ID = 'de'; const GERMAN_ID = 'de';
const HINDI_ID = 'hi';
const ICELANDIC_ID = 'is'; const ICELANDIC_ID = 'is';
const ITALIAN_ID = 'it'; const ITALIAN_ID = 'it';
const JAPANESE_ID = 'ja'; const JAPANESE_ID = 'ja';
@ -241,6 +242,12 @@ class Scratch3Text2SpeechBlocks {
locales: ['de'], locales: ['de'],
speechSynthLocale: 'de-DE' speechSynthLocale: 'de-DE'
}, },
[HINDI_ID]: {
name: 'Hindi',
locales: ['hi'],
speechSynthLocale: 'hi-IN',
singleGender: true
},
[ICELANDIC_ID]: { [ICELANDIC_ID]: {
name: 'Icelandic', name: 'Icelandic',
locales: ['is'], locales: ['is'],