From 7da54dd0677a6ba954cda64dc87ca0c33615fe41 Mon Sep 17 00:00:00 2001 From: Eric Rosenbaum Date: Wed, 20 Feb 2019 10:49:03 -0500 Subject: [PATCH] Add tilted any option --- src/extensions/scratch3_gdx_for/index.js | 44 +++++++++++++++++++----- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/src/extensions/scratch3_gdx_for/index.js b/src/extensions/scratch3_gdx_for/index.js index 8bff84dc4..2714d33c7 100644 --- a/src/extensions/scratch3_gdx_for/index.js +++ b/src/extensions/scratch3_gdx_for/index.js @@ -422,7 +422,8 @@ const TiltAxisValues = { FRONT: 'front', BACK: 'back', LEFT: 'left', - RIGHT: 'right' + RIGHT: 'right', + ANY: 'any' }; /** @@ -519,6 +520,20 @@ class Scratch3GdxForBlocks { ]; } + get TILT_MENU_ANY () { + return [ + ...this.TILT_MENU, + { + text: formatMessage({ + id: 'gdxfor.tiltDirectionMenu.any', + default: 'any', + description: 'label for any direction element in tilt direction picker for gdxfor extension' + }), + value: TiltAxisValues.ANY + } + ]; + } + get FACE_MENU () { return [ { @@ -644,8 +659,8 @@ class Scratch3GdxForBlocks { arguments: { TILT: { type: ArgumentType.STRING, - menu: 'tiltOptions', - defaultValue: TiltAxisValues.FRONT + menu: 'tiltAnyOptions', + defaultValue: TiltAxisValues.ANY } } }, @@ -750,8 +765,8 @@ class Scratch3GdxForBlocks { arguments: { TILT: { type: ArgumentType.STRING, - menu: 'tiltOptions', - defaultValue: TiltAxisValues.FRONT + menu: 'tiltAnyOptions', + defaultValue: TiltAxisValues.ANY } } } @@ -761,6 +776,7 @@ class Scratch3GdxForBlocks { gestureOptions: this.GESTURE_MENU, axisOptions: this.AXIS_MENU, tiltOptions: this.TILT_MENU, + tiltAnyOptions: this.TILT_MENU_ANY, faceOptions: this.FACE_MENU } }; @@ -795,15 +811,27 @@ class Scratch3GdxForBlocks { } whenTilted (args) { - return this._getTiltAngle(args.TILT) > TILT_THRESHOLD; + return this._isTilted(args.TILT); + } + + isTilted (args) { + return this._isTilted(args.TILT); } getTilt (args) { return this._getTiltAngle(args.TILT); } - isTilted (args) { - return this._getTiltAngle(args.TILT) > TILT_THRESHOLD; + _isTilted (direction) { + switch (direction) { + case TiltAxisValues.ANY: + return this._getTiltAngle(TiltAxisValues.FRONT) > TILT_THRESHOLD || + this._getTiltAngle(TiltAxisValues.BACK) > TILT_THRESHOLD || + this._getTiltAngle(TiltAxisValues.LEFT) > TILT_THRESHOLD || + this._getTiltAngle(TiltAxisValues.RIGHT) > TILT_THRESHOLD; + default: + return this._getTiltAngle(direction) > TILT_THRESHOLD; + } } _getTiltAngle (direction) {