Skip to content

Commit

Permalink
feat: add raw data on move for data-only usage
Browse files Browse the repository at this point in the history
fix #54
  • Loading branch information
iodev authored and yoannmoinet committed May 8, 2019
1 parent c164597 commit c818fb2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,14 @@ The time it takes for joystick to fade-out and fade-in when activated or de-acti
### `options.multitouch` defaults to false
Enable the multitouch capabilities.

If, for reasons, you need to have multiple nipples into the same zone.
If, for reasons, you need to have multiple nipples in the same zone.

Otherwise it will only get one, and all new touches won't do a thing.
Otherwise, it will only get one, and all new touches won't do a thing.

Please note that multitouch is off when in `static` or `semi` modes.

### `options.maxNumberOfNipples` defaults to 1
If you need to, you can also control the maximum number of instance that could be created.
If you need to, you can also control the maximum number of instances that could be created.

Obviously in a multitouch configuration.

Expand Down Expand Up @@ -314,10 +314,10 @@ If you don't specify the handler but just a type, all handlers for that type wil

#### `manager.get(identifier)`

An helper to get an instance via its identifier.
A helper to get an instance via its identifier.

```javascript
// Will return the nipple instanciated by the touch identified by 0
// Will return the nipple instantiated by the touch identified by 0
manager.get(0);
```

Expand Down Expand Up @@ -526,6 +526,13 @@ Comes with data :
radian: 1.5707963268, // angle in radian
degree: 90
},
raw: { // note: angle is the same, beyond the 50 pixel limit
distance: 25.4, // distance which continues beyond the 50 pixel limit
position: { // position of the finger/mouse in pixels, beyond joystick limits
x: 125,
y: 95
}
},
instance: Nipple // the nipple instance that triggered the event
}
```
Expand Down
6 changes: 6 additions & 0 deletions src/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,11 @@ Collection.prototype.processOnMove = function (evt) {
var rAngle = u.radians(angle);
var force = dist / size;

var raw = {
distance: dist,
position: pos
};

// If distance is bigger than nipple's size
// we clamp the position.
if (dist > size) {
Expand Down Expand Up @@ -420,6 +425,7 @@ Collection.prototype.processOnMove = function (evt) {
radian: rAngle,
degree: angle
},
raw: raw,
instance: nipple,
lockX: opts.lockX,
lockY: opts.lockY
Expand Down
4 changes: 4 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ export interface JoystickOutputData {
x: string;
y: string;
};
raw: {
distance: number;
position: Position;
};
distance: number;
force: number;
identifier: number;
Expand Down

0 comments on commit c818fb2

Please sign in to comment.