Skip to content

added typescript types #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
added typescript types
  • Loading branch information
Brenden Bunker committed Mar 11, 2022
commit d25604e311e3a98d87429cac6b778f18febd4996
58 changes: 58 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
declare module "gamepad.js" {
class GamepadListener {
constructor(options?: GamepadOptions);
start: () => void;
stop: () => void;
update: () => void;
discover: (gamepad: Gamepad, index: number) => void;
registerHandler: (index: number, gamepad: Gamepad) => void;
removeGamepad: (index: number) => void;
onAxis: (event: Event) => void;
on: GamepadEvent;
off: GamepadEvent;
}

class GamepadHandler {
constructor(index: number, gamepad: Gamepad, options?: GamepadOptions);
update: (gamepad: Gamepad) => void;
updateStick: (
gamepad: Gamepad,
stick: number,
axis: number,
value: number
) => void;
updateButton: (
gamepad: Gamepad,
button: GamepadButton,
index: number
) => void;
}

interface GamepadOptions {
analog: boolean;
precision: number;
deadZone: number;
button: {
analog: boolean;
};
stick: {
analog: boolean;
precision: number;
deadZone: number;
};
}

type GamepadEvent = (
event:
| "gamepad:connected"
| "gamepad:disconnected"
| "gamepad:axis"
| `gamepad:${number}:axis`
| `gamepad:${number}:axis:${number}`
| "gamepad:button"
| `gamepad:${number}:button`
| `gamepad:${number}:button:${number}`
| string,
handler: (e: Event) => void
) => void;
}