Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
elmarti committed Mar 24, 2023
2 parents 03d8e9f + ed3d9f9 commit 750076d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
node_modules
build
.cache
yarn-error.log
yarn-error.log
.DS_Store
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Component Props - as described by IJoystickProps - all are optional
| disabled | Boolean | When true, block any usage of the Joystick. This will also apply the `joystick-disabled` and `joystick-base-disabled` classNames |
| stickShape | JoystickShape | The shape of the joystick default = circle|
| baseShape | JoystickShape | The shape of the joystick default = circle|
| controlPlaneShape | JoystickShape | Override the default shape behaviour of the control plane|
| controlPlaneShape | JoystickShape | Override the default shape behaviour of the control plane - circle, square, axisX, axisY|
| minDistance | number | Percentage 0-100 - the minimum distance to start receive IJoystickMove events|

```TypeScript
Expand Down
9 changes: 8 additions & 1 deletion src/Joystick.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ joystickStories.add("Yellow (custom colors) joystick",
stickColor={"#FFD300"} move={action("Moved")}
stop={action("Stopped")}/>);


joystickStories.add("Y Axis only",
() => <Joystick
controlPlaneShape={JoystickShape.AxisY} start={action("Started")} throttle={50}
move={action("Moved")} stop={action("Stopped")}/>);
joystickStories.add("X Axis only",
() => <Joystick
controlPlaneShape={JoystickShape.AxisX} start={action("Started")} throttle={50}
move={action("Moved")} stop={action("Stopped")}/>);
joystickStories.add("50ms throttled joystick", () => <Joystick start={action("Started")} throttle={50}
move={action("Moved")} stop={action("Stopped")}/>);

Expand Down
4 changes: 3 additions & 1 deletion src/enums/shape.enum.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export enum JoystickShape {
Circle = 'circle',
Square = 'square'
Square = 'square',
AxisY = 'axisY',
AxisX = 'axisX',
}
8 changes: 8 additions & 0 deletions src/shapes/shape.bounds.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ export const shapeBoundsFactory = (
relativeX = getWithinBounds(absoluteX - parentRect.left - (baseSize / 2), baseSize);
relativeY = getWithinBounds(absoluteY - parentRect.top - (baseSize / 2), baseSize);
return {relativeX, relativeY};
case JoystickShape.AxisX:
relativeX = getWithinBounds(absoluteX - parentRect.left - (baseSize / 2), baseSize);
relativeY = 0;
return {relativeX, relativeY};

case JoystickShape.AxisY:
relativeX = 0
relativeY = getWithinBounds(absoluteY - parentRect.top - (baseSize / 2), baseSize);
return {relativeX, relativeY};
default:
if (dist > radius) {
relativeX *= radius / dist;
Expand Down

0 comments on commit 750076d

Please sign in to comment.