From b5bdc20d1365cdae5536414da84bf528d254b6ee Mon Sep 17 00:00:00 2001 From: Eric Rosenbaum Date: Fri, 22 Mar 2019 17:13:46 -0400 Subject: [PATCH] Move facing options into gesture menu --- src/extensions/scratch3_gdx_for/index.js | 85 +++++++----------------- 1 file changed, 24 insertions(+), 61 deletions(-) diff --git a/src/extensions/scratch3_gdx_for/index.js b/src/extensions/scratch3_gdx_for/index.js index f4eb425f4..9d5f77619 100644 --- a/src/extensions/scratch3_gdx_for/index.js +++ b/src/extensions/scratch3_gdx_for/index.js @@ -417,7 +417,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 +446,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 +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 () { return [ { @@ -600,6 +571,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 +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', text: formatMessage({ @@ -784,8 +755,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,6 +782,10 @@ class Scratch3GdxForBlocks { return this.gestureMagnitude() > SHAKEN_THRESHOLD; case GestureValues.STARTED_FALLING: 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: log.warn(`unknown gesture value in whenGesture: ${args.GESTURE}`); 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 () { // When the peripheral is not connected, the acceleration magnitude // is 0 instead of ~9.8, which ends up calculating as a positive