@@ -144,35 +144,45 @@ impl DPad {
144
144
/// State of the buttons.
145
145
#[ derive( Default ) ]
146
146
pub struct Buttons {
147
- /// If `a` button is pressed.
148
- pub a : bool ,
149
- /// If `b` button is pressed.
150
- pub b : bool ,
151
- /// If `x` button is pressed.
152
- pub x : bool ,
153
- /// If `y` button is pressed.
154
- pub y : bool ,
155
- /// If `menu` button is pressed.
147
+ /// South. The bottom button, like A on the X-Box controller.
156
148
///
157
- /// For singleplayer games, the button press is always intercepted by the runtime.
149
+ /// Typically used for confirmation, main action, jump, etc.
150
+ pub s : bool ,
151
+
152
+ /// East. The right button, like B on the X-Box controller.
153
+ ///
154
+ /// Typically used for cancellation, going to previous screen, etc.
155
+ pub e : bool ,
156
+
157
+ /// West. The left button, like X on the X-Box controller.
158
+ ///
159
+ /// Typically used for attack.
160
+ pub w : bool ,
161
+
162
+ /// North. The top button, like Y on the X-Box controller.
163
+ ///
164
+ /// Typically used for a secondary action, like charged attack.
165
+ pub n : bool ,
166
+
167
+ /// The menu button, almost always handled by the runtime.
158
168
pub menu : bool ,
159
169
}
160
170
161
171
impl Buttons {
162
172
/// Check if any button is pressed.
163
173
#[ must_use]
164
174
pub fn any ( & self ) -> bool {
165
- self . a || self . b || self . x || self . y || self . menu
175
+ self . s || self . e || self . w || self . n || self . menu
166
176
}
167
177
168
178
/// Given the old state, get buttons that were not pressed but are pressed now.
169
179
#[ must_use]
170
180
pub fn just_pressed ( & self , old : & Self ) -> Self {
171
181
Self {
172
- a : self . a && !old. a ,
173
- b : self . b && !old. b ,
174
- x : self . x && !old. x ,
175
- y : self . y && !old. y ,
182
+ s : self . s && !old. s ,
183
+ e : self . e && !old. e ,
184
+ w : self . w && !old. w ,
185
+ n : self . n && !old. n ,
176
186
menu : self . menu && !old. menu ,
177
187
}
178
188
}
@@ -181,10 +191,10 @@ impl Buttons {
181
191
#[ must_use]
182
192
pub fn just_released ( & self , old : & Self ) -> Self {
183
193
Self {
184
- a : !self . a && old. a ,
185
- b : !self . b && old. b ,
186
- x : !self . x && old. x ,
187
- y : !self . y && old. y ,
194
+ s : !self . s && old. s ,
195
+ e : !self . e && old. e ,
196
+ w : !self . w && old. w ,
197
+ n : !self . n && old. n ,
188
198
menu : !self . menu && old. menu ,
189
199
}
190
200
}
@@ -193,10 +203,10 @@ impl Buttons {
193
203
#[ must_use]
194
204
pub fn held ( & self , old : & Self ) -> Self {
195
205
Self {
196
- a : self . a && old. a ,
197
- b : self . b && old. b ,
198
- x : self . x && old. x ,
199
- y : self . y && old. y ,
206
+ s : self . s && old. s ,
207
+ e : self . e && old. e ,
208
+ w : self . w && old. w ,
209
+ n : self . n && old. n ,
200
210
menu : self . menu && old. menu ,
201
211
}
202
212
}
@@ -223,10 +233,10 @@ pub fn read_buttons(p: Peer) -> Buttons {
223
233
let p = u32:: from ( p. 0 ) ;
224
234
let raw = unsafe { bindings:: read_buttons ( p) } ;
225
235
Buttons {
226
- a : has_bit_set ( raw, 0 ) ,
227
- b : has_bit_set ( raw, 1 ) ,
228
- x : has_bit_set ( raw, 2 ) ,
229
- y : has_bit_set ( raw, 3 ) ,
236
+ s : has_bit_set ( raw, 0 ) ,
237
+ e : has_bit_set ( raw, 1 ) ,
238
+ w : has_bit_set ( raw, 2 ) ,
239
+ n : has_bit_set ( raw, 3 ) ,
230
240
menu : has_bit_set ( raw, 4 ) ,
231
241
}
232
242
}
0 commit comments