@@ -208,40 +208,36 @@ fn input_dispatch(
208
208
selected : Res < Selected > ,
209
209
keyboard_input : ResMut < Input < KeyCode > > ,
210
210
) {
211
+ use KeyCode :: * ;
212
+
211
213
let ( mut cycle_actions, mut add_actions) = query. get_mut ( selected. entity ) . unwrap ( ) ;
212
214
213
215
// Inputs for cycling colors
214
- if keyboard_input. just_pressed ( KeyCode :: Return ) || keyboard_input . just_pressed ( KeyCode :: Space ) {
216
+ if keyboard_input. just_pressed ( Space ) {
215
217
cycle_actions. send ( CycleColorAction ) ;
216
218
}
217
219
218
220
// Inputs for sending numbers to be added
219
- if keyboard_input. just_pressed ( KeyCode :: Key1 ) {
220
- add_actions. send ( AddNumberAction { number : 1 } ) ;
221
- }
222
- if keyboard_input. just_pressed ( KeyCode :: Key2 ) {
223
- add_actions. send ( AddNumberAction { number : 2 } ) ;
224
- }
225
- if keyboard_input. just_pressed ( KeyCode :: Key3 ) {
226
- add_actions. send ( AddNumberAction { number : 3 } ) ;
227
- }
228
- if keyboard_input. just_pressed ( KeyCode :: Key4 ) {
229
- add_actions. send ( AddNumberAction { number : 4 } ) ;
230
- }
231
- if keyboard_input. just_pressed ( KeyCode :: Key5 ) {
232
- add_actions. send ( AddNumberAction { number : 5 } ) ;
233
- }
234
- if keyboard_input. just_pressed ( KeyCode :: Key6 ) {
235
- add_actions. send ( AddNumberAction { number : 6 } ) ;
236
- }
237
- if keyboard_input. just_pressed ( KeyCode :: Key7 ) {
238
- add_actions. send ( AddNumberAction { number : 7 } ) ;
239
- }
240
- if keyboard_input. just_pressed ( KeyCode :: Key8 ) {
241
- add_actions. send ( AddNumberAction { number : 8 } ) ;
242
- }
243
- if keyboard_input. just_pressed ( KeyCode :: Key9 ) {
244
- add_actions. send ( AddNumberAction { number : 9 } ) ;
221
+ for k in keyboard_input. get_just_pressed ( ) {
222
+ let num = match key_code {
223
+ Key0 => Some ( 0 ) ,
224
+ Key1 => Some ( 1 ) ,
225
+ Key2 => Some ( 2 ) ,
226
+ Key3 => Some ( 3 ) ,
227
+ Key4 => Some ( 4 ) ,
228
+ Key5 => Some ( 5 ) ,
229
+ Key6 => Some ( 6 ) ,
230
+ Key7 => Some ( 7 ) ,
231
+ Key8 => Some ( 8 ) ,
232
+ Key9 => Some ( 9 ) ,
233
+ _ => None ,
234
+ } ;
235
+
236
+ if num. is_some ( ) {
237
+ add_actions. send ( AddNumberAction {
238
+ number : num. unwrap ( ) ,
239
+ } ) ;
240
+ }
245
241
}
246
242
}
247
243
0 commit comments