mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
Merge branch 'develop' into boostextension
This commit is contained in:
commit
b608a4856b
3 changed files with 68 additions and 65 deletions
|
@ -19,10 +19,8 @@ const builtinExtensions = {
|
|||
speech2text: () => require('../extensions/scratch3_speech2text'),
|
||||
ev3: () => require('../extensions/scratch3_ev3'),
|
||||
makeymakey: () => require('../extensions/scratch3_makeymakey'),
|
||||
boost: () => require('../extensions/scratch3_boost')
|
||||
// todo: only load this extension once we have a compatible way to load its
|
||||
// Vernier module dependency.
|
||||
// gdxfor: () => require('../extensions/scratch3_gdx_for')
|
||||
boost: () => require('../extensions/scratch3_boost'),
|
||||
gdxfor: () => require('../extensions/scratch3_gdx_for')
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -80,6 +80,12 @@ const SHAKEN_THRESHOLD = 30;
|
|||
*/
|
||||
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.
|
||||
* @type {number}
|
||||
|
@ -417,7 +423,9 @@ const PushPullValues = {
|
|||
*/
|
||||
const GestureValues = {
|
||||
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'
|
||||
};
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
@ -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 () {
|
||||
return [
|
||||
{
|
||||
|
@ -600,6 +577,22 @@ class Scratch3GdxForBlocks {
|
|||
description: 'the sensor started free 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',
|
||||
text: formatMessage({
|
||||
|
@ -784,8 +761,7 @@ class Scratch3GdxForBlocks {
|
|||
gestureOptions: this.GESTURE_MENU,
|
||||
axisOptions: this.AXIS_MENU,
|
||||
tiltOptions: this.TILT_MENU,
|
||||
tiltAnyOptions: this.TILT_MENU_ANY,
|
||||
faceOptions: this.FACE_MENU
|
||||
tiltAnyOptions: this.TILT_MENU_ANY
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -812,12 +788,45 @@ class Scratch3GdxForBlocks {
|
|||
return this.gestureMagnitude() > SHAKEN_THRESHOLD;
|
||||
case GestureValues.STARTED_FALLING:
|
||||
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:
|
||||
log.warn(`unknown gesture value in whenGesture: ${args.GESTURE}`);
|
||||
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) {
|
||||
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 () {
|
||||
// When the peripheral is not connected, the acceleration magnitude
|
||||
// is 0 instead of ~9.8, which ends up calculating as a positive
|
||||
|
|
|
@ -84,6 +84,7 @@ const DUTCH_ID = 'nl';
|
|||
const ENGLISH_ID = 'en';
|
||||
const FRENCH_ID = 'fr';
|
||||
const GERMAN_ID = 'de';
|
||||
const HINDI_ID = 'hi';
|
||||
const ICELANDIC_ID = 'is';
|
||||
const ITALIAN_ID = 'it';
|
||||
const JAPANESE_ID = 'ja';
|
||||
|
@ -241,6 +242,12 @@ class Scratch3Text2SpeechBlocks {
|
|||
locales: ['de'],
|
||||
speechSynthLocale: 'de-DE'
|
||||
},
|
||||
[HINDI_ID]: {
|
||||
name: 'Hindi',
|
||||
locales: ['hi'],
|
||||
speechSynthLocale: 'hi-IN',
|
||||
singleGender: true
|
||||
},
|
||||
[ICELANDIC_ID]: {
|
||||
name: 'Icelandic',
|
||||
locales: ['is'],
|
||||
|
|
Loading…
Reference in a new issue