@gjsify/gamepad 0.4.43 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -0
- package/package.json +5 -5
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# @gjsify/gamepad
|
|
2
|
+
|
|
3
|
+
The W3C Gamepad API for GJS, backed by libmanette 0.2. Provides `navigator.getGamepads()` polling, `Gamepad`, `GamepadButton`, `gamepadconnected`/`gamepaddisconnected` events, and dual-rumble haptics via `GamepadHapticActuator`. The Manette monitor is lazily initialised and degrades gracefully when libmanette is unavailable.
|
|
4
|
+
|
|
5
|
+
Part of the [gjsify](https://github.com/gjsify/gjsify) project — Node.js and Web APIs for GJS (GNOME JavaScript).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
gjsify install @gjsify/gamepad
|
|
11
|
+
|
|
12
|
+
# npm or yarn also work (e.g. adding it to an existing project):
|
|
13
|
+
npm install @gjsify/gamepad
|
|
14
|
+
yarn add @gjsify/gamepad
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { GamepadManager, GamepadEvent } from '@gjsify/gamepad';
|
|
21
|
+
|
|
22
|
+
// Start monitoring connected gamepads
|
|
23
|
+
const manager = new GamepadManager();
|
|
24
|
+
|
|
25
|
+
window.addEventListener('gamepadconnected', (e) => {
|
|
26
|
+
const event = e as GamepadEvent;
|
|
27
|
+
const pad = event.gamepad;
|
|
28
|
+
console.log(`Connected: ${pad.id}, buttons: ${pad.buttons.length}`);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
window.addEventListener('gamepaddisconnected', (e) => {
|
|
32
|
+
console.log(`Disconnected: ${(e as GamepadEvent).gamepad.id}`);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Poll the current state
|
|
36
|
+
const gamepads = navigator.getGamepads();
|
|
37
|
+
for (const pad of gamepads) {
|
|
38
|
+
if (pad) console.log(pad.axes, pad.buttons.map((b) => b.pressed));
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## License
|
|
43
|
+
|
|
44
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/gamepad",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Gamepad Web API for GJS using libmanette as backend",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -43,15 +43,15 @@
|
|
|
43
43
|
"controller"
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@gjsify/dom-events": "^0.
|
|
46
|
+
"@gjsify/dom-events": "^0.5.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@girs/gjs": "4.0.4",
|
|
50
50
|
"@girs/glib-2.0": "2.88.0-4.0.4",
|
|
51
51
|
"@girs/manette-0.2": "0.2.13-4.0.4",
|
|
52
|
-
"@gjsify/cli": "^0.
|
|
53
|
-
"@gjsify/unit": "^0.
|
|
54
|
-
"@types/node": "^25.9.
|
|
52
|
+
"@gjsify/cli": "^0.5.0",
|
|
53
|
+
"@gjsify/unit": "^0.5.0",
|
|
54
|
+
"@types/node": "^25.9.2",
|
|
55
55
|
"typescript": "^6.0.3"
|
|
56
56
|
},
|
|
57
57
|
"gjsify": {
|