2020-07-10 04:18:35 +00:00
|
|
|
use crate::WindowCloseRequested;
|
2020-07-17 01:47:51 +00:00
|
|
|
use bevy_app::{
|
|
|
|
prelude::{EventReader, Events},
|
|
|
|
AppExit,
|
|
|
|
};
|
2020-07-10 04:18:35 +00:00
|
|
|
use bevy_ecs::{Local, Res, ResMut};
|
2020-04-19 19:13:04 +00:00
|
|
|
|
2020-07-10 04:18:35 +00:00
|
|
|
#[derive(Default)]
|
|
|
|
pub struct ExitOnWindowCloseState {
|
|
|
|
event_reader: EventReader<WindowCloseRequested>,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn exit_on_window_close_system(
|
|
|
|
mut state: Local<ExitOnWindowCloseState>,
|
|
|
|
mut app_exit_events: ResMut<Events<AppExit>>,
|
|
|
|
window_close_requested_events: Res<Events<WindowCloseRequested>>,
|
|
|
|
) {
|
|
|
|
for _ in state.event_reader.iter(&window_close_requested_events) {
|
|
|
|
app_exit_events.send(AppExit);
|
|
|
|
break;
|
|
|
|
}
|
2020-04-25 01:55:15 +00:00
|
|
|
}
|