Skip to content

Commit 64da9d4

Browse files
Quick and easy keycode math
Credit to @mockersf for the idea
1 parent 25ab96a commit 64da9d4

File tree

1 file changed

+5
-19
lines changed

1 file changed

+5
-19
lines changed

examples/ecs/per_entity_events.rs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -218,31 +218,17 @@ fn input_dispatch(
218218
}
219219

220220
// Inputs for sending numbers to be added
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() {
221+
for key_code in keyboard_input.get_just_pressed() {
222+
if (key_code as u8) < 10 {
237223
add_actions.send(AddNumberAction {
238-
number: num.unwrap(),
224+
// The keycode for KeyCode::Key1 is 0
225+
number: key_code as u8 + 1,
239226
});
240227
}
241228
}
242229
}
243230

244-
// FIXME: make this work without duplication using `EventReader<T>` syntax and specialized behavior
245-
fn cycle_color(mut query: Query<(&mut Rainbow, &mut Events<CycleColorAction>)>) {
231+
fn cycle_color(mut query: Query<(&mut ColorChoices, EventReader<CycleColorAction>)>) {
246232
for (mut color, action_queue) in query.iter_mut() {
247233
let mut reader = action_queue.get_reader();
248234
for _ in reader.iter(&action_queue) {

0 commit comments

Comments
 (0)