diff --git a/crates/bevy_app/src/app_builder.rs b/crates/bevy_app/src/app_builder.rs index 9c1bb4f4cc..ce93b337a9 100644 --- a/crates/bevy_app/src/app_builder.rs +++ b/crates/bevy_app/src/app_builder.rs @@ -4,7 +4,9 @@ use crate::{ stage, App, AppExit, Events, }; -use legion::prelude::{Resources, Universe, World}; +use legion::prelude::{Resources, Universe, World, IntoQuery, ResourceSet, into_system, into_resource_system}; +use legion::query::{View, DefaultFilter}; +use legion::filter::EntityFilter; static APP_MISSING_MESSAGE: &str = "This AppBuilder no longer has an App. Check to see if you already called run(). A call to app_builder.run() consumes the AppBuilder's App."; @@ -237,4 +239,46 @@ impl AppBuilder { plugin.build(self); self } + + pub fn add_system_fn<'a, Q, F, R, X>(&mut self, name: &'static str, system: F) -> &mut Self + where + Q: IntoQuery + DefaultFilter, + >::Iter: Iterator + 'a, + F: FnMut(&mut X, Q) + Send + Sync + 'static, + R: EntityFilter + Sync + 'static, + X: ResourceSet + 'static, + { + self.add_system_fn_to_stage(stage::UPDATE, name, system) + } + + pub fn add_system_fn_to_stage<'a, Q, F, R, X>(&mut self, stage_name: &str, name: &'static str, system: F) -> &mut Self + where + Q: IntoQuery + DefaultFilter, + >::Iter: Iterator + 'a, + F: FnMut(&mut X, Q) + Send + Sync + 'static, + R: EntityFilter + Sync + 'static, + X: ResourceSet + 'static, + { + let system = into_system(name, system); + self.add_system_to_stage(stage_name, system); + self + } + + pub fn add_resource_system_fn<'a, F, X>(&mut self, name: &'static str, system: F) -> &mut Self + where + F: FnMut(&mut X) + Send + Sync + 'static, + X: ResourceSet + 'static, + { + self.add_resource_system_fn_to_stage(stage::UPDATE, name, system) + } + + pub fn add_resource_system_fn_to_stage<'a, F, X>(&mut self, stage_name: &str, name: &'static str, system: F) -> &mut Self + where + F: FnMut(&mut X) + Send + Sync + 'static, + X: ResourceSet + 'static, + { + let system = into_resource_system(name, system); + self.add_system_to_stage(stage_name, system); + self + } } diff --git a/examples/event.rs b/examples/event.rs index 13145397bc..5b87008a1a 100644 --- a/examples/event.rs +++ b/examples/event.rs @@ -6,11 +6,8 @@ fn main() { .add_event::() .add_resource(EventTriggerState::default()) .add_resource_init::() - .add_system(into_resource_system("event_trigger", event_trigger_system)) - .add_system(into_resource_system( - "event_listener", - event_listener_system, - )) + .add_resource_system_fn("event_trigger", event_trigger_system) + .add_resource_system_fn("event_listener", event_listener_system) .run(); } @@ -60,4 +57,4 @@ fn event_listener_system( for my_event in my_events.iter(&mut state.my_event_reader) { println!("{}", my_event.message); } -} \ No newline at end of file +} diff --git a/examples/spawner.rs b/examples/spawner.rs index 4848f0c171..4f39a9042a 100644 --- a/examples/spawner.rs +++ b/examples/spawner.rs @@ -9,7 +9,7 @@ fn main() { ..Default::default() }) .add_startup_system(setup) - .add_system(into_system("move", move_system)) + .add_system_fn("move", move_system) .run(); }