From 41cd5618e48f8b07c9bcbe9a5760c02e3cadb529 Mon Sep 17 00:00:00 2001 From: Johan Nyman Date: Wed, 7 Apr 2021 08:53:51 +0200 Subject: [PATCH] fix: bug for joystick deltaZ --- src/xkeys.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/xkeys.ts b/src/xkeys.ts index bd2b681..7987147 100644 --- a/src/xkeys.ts +++ b/src/xkeys.ts @@ -334,7 +334,7 @@ export class XKeys extends EventEmitter { const emitValue: JoystickValueEmit = { ...newValue, // Calculate deltaZ, since that is not trivial to do: - deltaZ: XKeys.calculateDelta(newValue.z, oldValue.z, 255), + deltaZ: XKeys.calculateDelta(newValue.z, oldValue.z), } this.emit('joystick', index, emitValue, eventMetadata) } @@ -753,7 +753,7 @@ export class XKeys extends EventEmitter { if (!this._initialized) throw new Error('XKeys.init() must be run first!') } /** Calcuate delta value */ - static calculateDelta(newValue: number, oldValue: number, overflow: number = 256): number { + static calculateDelta(newValue: number, oldValue: number, overflow = 256): number { let delta = newValue - oldValue if (delta < -overflow * 0.5) delta += overflow // Deal with when the new value overflows if (delta > overflow * 0.5) delta -= overflow // Deal with when the new value underflows