Add tilted any option

This commit is contained in:
Eric Rosenbaum 2019-02-20 10:49:03 -05:00
parent a19585af75
commit 7da54dd067

View file

@ -422,7 +422,8 @@ const TiltAxisValues = {
FRONT: 'front', FRONT: 'front',
BACK: 'back', BACK: 'back',
LEFT: 'left', 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 () { get FACE_MENU () {
return [ return [
{ {
@ -644,8 +659,8 @@ class Scratch3GdxForBlocks {
arguments: { arguments: {
TILT: { TILT: {
type: ArgumentType.STRING, type: ArgumentType.STRING,
menu: 'tiltOptions', menu: 'tiltAnyOptions',
defaultValue: TiltAxisValues.FRONT defaultValue: TiltAxisValues.ANY
} }
} }
}, },
@ -750,8 +765,8 @@ class Scratch3GdxForBlocks {
arguments: { arguments: {
TILT: { TILT: {
type: ArgumentType.STRING, type: ArgumentType.STRING,
menu: 'tiltOptions', menu: 'tiltAnyOptions',
defaultValue: TiltAxisValues.FRONT defaultValue: TiltAxisValues.ANY
} }
} }
} }
@ -761,6 +776,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,
faceOptions: this.FACE_MENU faceOptions: this.FACE_MENU
} }
}; };
@ -795,15 +811,27 @@ class Scratch3GdxForBlocks {
} }
whenTilted (args) { whenTilted (args) {
return this._getTiltAngle(args.TILT) > TILT_THRESHOLD; return this._isTilted(args.TILT);
}
isTilted (args) {
return this._isTilted(args.TILT);
} }
getTilt (args) { getTilt (args) {
return this._getTiltAngle(args.TILT); return this._getTiltAngle(args.TILT);
} }
isTilted (args) { _isTilted (direction) {
return this._getTiltAngle(args.TILT) > TILT_THRESHOLD; 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) { _getTiltAngle (direction) {