-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathcocoon_gamepad.js
More file actions
125 lines (115 loc) · 4.05 KB
/
cocoon_gamepad.js
File metadata and controls
125 lines (115 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
(function () {
if (typeof window.Cocoon === 'undefined' || window.Cocoon === null) throw("The Cocoon object must exist and be valid before creating any extension object.");
/**
* This namespace represents the functionalities related to OUYA android gaming control.
* @namespace
*/
Cocoon.Gamepad = {};
Cocoon.Gamepad.nativeExtensionObjectAvailable = Cocoon.nativeAvailable && typeof window.ext.Gamepad !== 'undefined';
/**
* This enumeration simplifies the access to the indices for button and axis elements according to the HTML5 gamepad standard API specification.
* You may use these values to access the buttons and axes arrays inside the Gamepad objects, according to the W3C gamepad API specification.
* For example:
* gamepad.button[Cocoon.Gamepad.BUTTON_LEFT_TRIGGER];
* gamepad.axes[Cocoon.Gamepad.AXIS_LEFT_JOYSTICK_X];
* @namespace
*/
Cocoon.Gamepad.Indices = {
/**
* Represents the button 0 (the A on the XBOX controller, the O on the OUYA controller)
*/
BUTTON_0 : 0,
/**
* Represents the button 1 (the B on the XBOX controller, the A on the OUYA controller)
*/
BUTTON_1 : 1,
/**
* Represents the button 2 (the X on the XBOX controller, the U on the OUYA controller)
*/
BUTTON_2 : 2,
/**
* Represents the button 3 (the Y on the XBOX controller, the Y on the OUYA controller)
*/
BUTTON_3 : 3,
/**
* Represents the left bumper button.
*/
BUTTON_LEFT_BUMPER : 4,
/**
* Represents the right bumper button.
*/
BUTTON_RIGHT_BUMPER : 5,
/**
* Represents the left trigger button.
*/
BUTTON_LEFT_TRIGGER : 6,
/**
* Represents the right trigger button.
*/
BUTTON_RIGHT_TRIGGER : 7,
/**
* Represents the left joystick button.
*/
BUTTON_LEFT_JOYSTICK : 10,
/**
* Represents the right joystick button.
*/
BUTTON_RIGHT_JOYSTICK : 11,
/**
* Represents the dpad up button.
*/
BUTTON_DPAD_UP : 12,
/**
* Represents the dpad down button.
*/
BUTTON_DPAD_DOWN : 13,
/**
* Represents the dpad left button.
*/
BUTTON_DPAD_LEFT : 14,
/**
* Represents the dpad right button.
*/
BUTTON_DPAD_RIGHT : 15,
/**
* Represents the menu button.
*/
BUTTON_MENU : 16,
/**
* Represents the left joystick horizontal axis.
*/
AXIS_LEFT_JOYSTICK_X : 0,
/**
* Represents the left joystick vertical axis.
*/
AXIS_LEFT_JOYSTICK_Y : 1,
/**
* Represents the right joystick horizontal axis.
*/
AXIS_RIGHT_JOYSTICK_X : 2,
/**
* Represents the right joystick vertical axis.
*/
AXIS_RIGHT_JOYSTICK_Y : 3
};
// If the extension is present and the navigator does not provide the gamepad API:
// 1.- Add the getGamepads function to the navigator object.
// 2.- Replace the window add and remove event listener functions to call to the extension for the gamepad related events.
var systemSupportsGamepads = navigator["getGamepads"] || navigator["webkitGetGamepads"];
if (systemSupportsGamepads)
{
if (!navigator.getGamepads)
{
console.log("navigator.getGamepads does not exist.");
if (navigator.webkitGetGamepads)
{
console.log("navigator.webkitGamepads exists, adding navigator.getGamepads to point to it.");
navigator.getGamepads = navigator.webkitGetGamepads;
}
else
{
console.log("navigator.webkitGetGamepads does not exist either.");
}
}
}
})();