2020-04-25 01:55:15 +00:00
|
|
|
use crate::keyboard::{ElementState, KeyboardInput, VirtualKeyCode};
|
|
|
|
use bevy_app::{AppExit, Events, GetEventReader};
|
2020-04-19 19:13:04 +00:00
|
|
|
use legion::prelude::*;
|
|
|
|
|
|
|
|
pub fn exit_on_esc_system(resources: &mut Resources) -> Box<dyn Schedulable> {
|
|
|
|
let mut keyboard_input_event_reader = resources.get_event_reader::<KeyboardInput>();
|
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) {
|
|
|
|
if let Some(virtual_key_code) = event.virtual_key_code {
|
|
|
|
if event.state == ElementState::Pressed
|
|
|
|
&& virtual_key_code == VirtualKeyCode::Escape
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|