2020-06-15 19:47:35 +00:00
|
|
|
use crate::keyboard::{ElementState, KeyCode, KeyboardInput};
|
2020-06-04 06:53:00 +00:00
|
|
|
use bevy_app::{AppExit, EventReader, Events};
|
2020-04-19 19:13:04 +00:00
|
|
|
use legion::prelude::*;
|
|
|
|
|
2020-06-04 06:53:00 +00:00
|
|
|
pub fn exit_on_esc_system(_resources: &mut Resources) -> Box<dyn Schedulable> {
|
|
|
|
let mut keyboard_input_event_reader = EventReader::<KeyboardInput>::default();
|
2020-05-14 00:52:47 +00:00
|
|
|
(move |keyboard_input_events: Res<Events<KeyboardInput>>,
|
|
|
|
mut app_exit_events: ResMut<Events<AppExit>>| {
|
2020-04-30 23:29:52 +00:00
|
|
|
for event in keyboard_input_event_reader.iter(&keyboard_input_events) {
|
2020-06-05 05:48:53 +00:00
|
|
|
if let Some(key_code) = event.key_code {
|
2020-06-15 19:47:35 +00:00
|
|
|
if event.state == ElementState::Pressed && key_code == KeyCode::Escape {
|
2020-04-30 23:29:52 +00:00
|
|
|
app_exit_events.send(AppExit);
|
2020-04-19 19:13:04 +00:00
|
|
|
}
|
2020-04-30 23:29:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.system_named("exit_on_esc")
|
2020-04-25 01:55:15 +00:00
|
|
|
}
|