mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 12:43:34 +00:00
system_fn: port exit_on_esc
This commit is contained in:
parent
e5a99fde4f
commit
b11a7f177b
1 changed files with 12 additions and 15 deletions
|
@ -4,20 +4,17 @@ 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>();
|
||||
SystemBuilder::new("exit_on_esc")
|
||||
.read_resource::<Events<KeyboardInput>>()
|
||||
.write_resource::<Events<AppExit>>()
|
||||
.build(
|
||||
move |_, _, (ref keyboard_input_events, ref mut app_exit_events), _| {
|
||||
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);
|
||||
}
|
||||
}
|
||||
(move |keyboard_input_events: Resource<Events<KeyboardInput>>,
|
||||
mut app_exit_events: ResourceMut<Events<AppExit>>| {
|
||||
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);
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
.system_named("exit_on_esc")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue