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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
use super::*;
/// The Gamepad class.
/// [`Gamepad`](https://developer.mozilla.org/en-US/docs/Web/API/Gamepad)
#[derive(Clone, Debug, PartialEq, PartialOrd)]
#[repr(transparent)]
pub struct Gamepad {
inner: Any,
}
impl FromVal for Gamepad {
fn from_val(v: &Any) -> Self {
Gamepad {
inner: Any::from_val(v),
}
}
fn take_ownership(v: AnyHandle) -> Self {
Self::from_val(&Any::take_ownership(v))
}
fn as_handle(&self) -> AnyHandle {
self.inner.as_handle()
}
}
impl core::ops::Deref for Gamepad {
type Target = Any;
fn deref(&self) -> &Self::Target {
&self.inner
}
}
impl core::ops::DerefMut for Gamepad {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
}
}
impl AsRef<Any> for Gamepad {
fn as_ref(&self) -> &Any {
&self.inner
}
}
impl AsMut<Any> for Gamepad {
fn as_mut(&mut self) -> &mut Any {
&mut self.inner
}
}
impl From<Gamepad> for Any {
fn from(s: Gamepad) -> Any {
let handle = s.inner.as_handle();
core::mem::forget(s);
Any::take_ownership(handle)
}
}
impl From<&Gamepad> for Any {
fn from(s: &Gamepad) -> Any {
s.inner.clone().into()
}
}
jsbind::utils::impl_dyn_cast!(Gamepad);
impl Gamepad {
/// Getter of the `id` attribute.
/// [`Gamepad.id`](https://developer.mozilla.org/en-US/docs/Web/API/Gamepad/id)
pub fn id(&self) -> JsString {
self.inner.get("id").as_::<JsString>()
}
}
impl Gamepad {
/// Getter of the `index` attribute.
/// [`Gamepad.index`](https://developer.mozilla.org/en-US/docs/Web/API/Gamepad/index)
pub fn index(&self) -> i32 {
self.inner.get("index").as_::<i32>()
}
}
impl Gamepad {
/// Getter of the `connected` attribute.
/// [`Gamepad.connected`](https://developer.mozilla.org/en-US/docs/Web/API/Gamepad/connected)
pub fn connected(&self) -> bool {
self.inner.get("connected").as_::<bool>()
}
}
impl Gamepad {
/// Getter of the `timestamp` attribute.
/// [`Gamepad.timestamp`](https://developer.mozilla.org/en-US/docs/Web/API/Gamepad/timestamp)
pub fn timestamp(&self) -> Any {
self.inner.get("timestamp").as_::<Any>()
}
}
impl Gamepad {
/// Getter of the `mapping` attribute.
/// [`Gamepad.mapping`](https://developer.mozilla.org/en-US/docs/Web/API/Gamepad/mapping)
pub fn mapping(&self) -> GamepadMappingType {
self.inner.get("mapping").as_::<GamepadMappingType>()
}
}
impl Gamepad {
/// Getter of the `axes` attribute.
/// [`Gamepad.axes`](https://developer.mozilla.org/en-US/docs/Web/API/Gamepad/axes)
pub fn axes(&self) -> TypedArray<f64> {
self.inner.get("axes").as_::<TypedArray<f64>>()
}
}
impl Gamepad {
/// Getter of the `buttons` attribute.
/// [`Gamepad.buttons`](https://developer.mozilla.org/en-US/docs/Web/API/Gamepad/buttons)
pub fn buttons(&self) -> TypedArray<GamepadButton> {
self.inner.get("buttons").as_::<TypedArray<GamepadButton>>()
}
}
impl Gamepad {
/// Getter of the `touches` attribute.
/// [`Gamepad.touches`](https://developer.mozilla.org/en-US/docs/Web/API/Gamepad/touches)
pub fn touches(&self) -> TypedArray<GamepadTouch> {
self.inner.get("touches").as_::<TypedArray<GamepadTouch>>()
}
}
impl Gamepad {
/// Getter of the `vibrationActuator` attribute.
/// [`Gamepad.vibrationActuator`](https://developer.mozilla.org/en-US/docs/Web/API/Gamepad/vibrationActuator)
pub fn vibration_actuator(&self) -> GamepadHapticActuator {
self.inner
.get("vibrationActuator")
.as_::<GamepadHapticActuator>()
}
}
impl Gamepad {
/// Getter of the `hand` attribute.
/// [`Gamepad.hand`](https://developer.mozilla.org/en-US/docs/Web/API/Gamepad/hand)
pub fn hand(&self) -> GamepadHand {
self.inner.get("hand").as_::<GamepadHand>()
}
}
impl Gamepad {
/// Getter of the `hapticActuators` attribute.
/// [`Gamepad.hapticActuators`](https://developer.mozilla.org/en-US/docs/Web/API/Gamepad/hapticActuators)
pub fn haptic_actuators(&self) -> TypedArray<GamepadHapticActuator> {
self.inner
.get("hapticActuators")
.as_::<TypedArray<GamepadHapticActuator>>()
}
}
impl Gamepad {
/// Getter of the `pose` attribute.
/// [`Gamepad.pose`](https://developer.mozilla.org/en-US/docs/Web/API/Gamepad/pose)
pub fn pose(&self) -> GamepadPose {
self.inner.get("pose").as_::<GamepadPose>()
}
}