mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 15:02:52 -05:00
Move facing options into gesture menu
This commit is contained in:
parent
e236d29ff5
commit
b5bdc20d13
1 changed files with 24 additions and 61 deletions
|
@ -417,7 +417,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 +446,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 +533,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 +571,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 +708,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 +755,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,6 +782,10 @@ 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._peripheral.getAccelerationZ() > FACING_THRESHOLD;
|
||||||
|
case GestureValues.TURNED_FACE_DOWN:
|
||||||
|
return this._peripheral.getAccelerationZ() < FACING_THRESHOLD * -1;
|
||||||
default:
|
default:
|
||||||
log.warn(`unknown gesture value in whenGesture: ${args.GESTURE}`);
|
log.warn(`unknown gesture value in whenGesture: ${args.GESTURE}`);
|
||||||
return false;
|
return false;
|
||||||
|
@ -919,17 +893,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
|
||||||
|
|
Loading…
Reference in a new issue