Skip to content

Commit e25b8eb

Browse files
authored
Merge pull request #608 from saschanaz/gamepad
Add Gamepad types
2 parents 6036c56 + 26c698e commit e25b8eb

File tree

4 files changed

+82
-6
lines changed

4 files changed

+82
-6
lines changed

baselines/dom.generated.d.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ interface GainOptions extends AudioNodeOptions {
468468
}
469469

470470
interface GamepadEventInit extends EventInit {
471-
gamepad?: Gamepad;
471+
gamepad: Gamepad;
472472
}
473473

474474
interface GetNotificationOptions {
@@ -5247,12 +5247,11 @@ declare var GainNode: {
52475247

52485248
/** The Gamepad interface of the Gamepad API defines an individual gamepad or other controller, allowing access to information such as button presses, axis positions, and id. */
52495249
interface Gamepad {
5250-
readonly axes: number[];
5251-
readonly buttons: GamepadButton[];
5250+
readonly axes: ReadonlyArray<number>;
5251+
readonly buttons: ReadonlyArray<GamepadButton>;
52525252
readonly connected: boolean;
5253-
readonly displayId: number;
52545253
readonly hand: GamepadHand;
5255-
readonly hapticActuators: GamepadHapticActuator[];
5254+
readonly hapticActuators: ReadonlyArray<GamepadHapticActuator>;
52565255
readonly id: string;
52575256
readonly index: number;
52585257
readonly mapping: GamepadMappingType;
@@ -5284,7 +5283,7 @@ interface GamepadEvent extends Event {
52845283

52855284
declare var GamepadEvent: {
52865285
prototype: GamepadEvent;
5287-
new(typeArg: string, eventInitDict?: GamepadEventInit): GamepadEvent;
5286+
new(type: string, eventInitDict: GamepadEventInit): GamepadEvent;
52885287
};
52895288

52905289
/** The GamepadHapticActuator interface of the Gamepad API represents hardware in the controller designed to provide haptic feedback to the user (if available), most commonly vibration hardware. */
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
enum GamepadHand {
2+
"", /* unknown, both hands, or not applicable */
3+
"left",
4+
"right"
5+
};
6+
7+
interface GamepadHapticActuator {
8+
readonly attribute GamepadHapticActuatorType type;
9+
Promise<boolean> pulse(double value, double duration);
10+
};
11+
12+
enum GamepadHapticActuatorType {
13+
"vibration"
14+
};
15+
16+
interface GamepadPose {
17+
readonly attribute boolean hasOrientation;
18+
readonly attribute boolean hasPosition;
19+
20+
readonly attribute Float32Array? position;
21+
readonly attribute Float32Array? linearVelocity;
22+
readonly attribute Float32Array? linearAcceleration;
23+
readonly attribute Float32Array? orientation;
24+
readonly attribute Float32Array? angularVelocity;
25+
readonly attribute Float32Array? angularAcceleration;
26+
};
27+
28+
partial interface Gamepad {
29+
readonly attribute GamepadHand hand;
30+
readonly attribute FrozenArray<GamepadHapticActuator> hapticActuators;
31+
readonly attribute GamepadPose? pose;
32+
};

inputfiles/idl/Gamepad.widl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[Exposed=Window]
2+
interface Gamepad {
3+
readonly attribute DOMString id;
4+
readonly attribute long index;
5+
readonly attribute boolean connected;
6+
readonly attribute DOMHighResTimeStamp timestamp;
7+
readonly attribute GamepadMappingType mapping;
8+
readonly attribute FrozenArray<double> axes;
9+
readonly attribute FrozenArray<GamepadButton> buttons;
10+
};
11+
12+
[Exposed=Window]
13+
interface GamepadButton {
14+
readonly attribute boolean pressed;
15+
readonly attribute boolean touched;
16+
readonly attribute double value;
17+
};
18+
19+
enum GamepadMappingType {
20+
"",
21+
"standard",
22+
};
23+
24+
[Exposed=Window]
25+
partial interface Navigator {
26+
sequence<Gamepad?> getGamepads();
27+
};
28+
29+
[Constructor(DOMString type, GamepadEventInit eventInitDict), Exposed=Window]
30+
31+
interface GamepadEvent : Event {
32+
[SameObject] readonly attribute Gamepad gamepad;
33+
};
34+
35+
dictionary GamepadEventInit : EventInit {
36+
required Gamepad gamepad;
37+
};

inputfiles/idlSources.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@
4444
"url": "https://fullscreen.spec.whatwg.org/",
4545
"title": "Fullscreen"
4646
},
47+
{
48+
"url": "https://www.w3.org/TR/gamepad/",
49+
"title": "Gamepad"
50+
},
51+
{
52+
"url": "https://w3c.github.io/gamepad/extensions.html",
53+
"title": "Gamepad Extensions"
54+
},
4755
{
4856
"url": "https://www.w3.org/TR/geolocation-API/",
4957
"title": "Geolocation"

0 commit comments

Comments
 (0)