mirror of
https://github.com/bevyengine/bevy
synced 2024-11-26 06:30:19 +00:00
add app builder shorthand for system function
This commit is contained in:
parent
092f3888ca
commit
92182060a9
3 changed files with 49 additions and 8 deletions
|
@ -4,7 +4,9 @@ use crate::{
|
||||||
stage, App, AppExit, Events,
|
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.";
|
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);
|
plugin.build(self);
|
||||||
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<Filter = R>,
|
||||||
|
<Q as View<'a>>::Iter: Iterator<Item = Q> + 'a,
|
||||||
|
F: FnMut(&mut X, Q) + Send + Sync + 'static,
|
||||||
|
R: EntityFilter + Sync + 'static,
|
||||||
|
X: ResourceSet<PreparedResources = X> + '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<Filter = R>,
|
||||||
|
<Q as View<'a>>::Iter: Iterator<Item = Q> + 'a,
|
||||||
|
F: FnMut(&mut X, Q) + Send + Sync + 'static,
|
||||||
|
R: EntityFilter + Sync + 'static,
|
||||||
|
X: ResourceSet<PreparedResources = X> + '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<PreparedResources = X> + '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<PreparedResources = X> + 'static,
|
||||||
|
{
|
||||||
|
let system = into_resource_system(name, system);
|
||||||
|
self.add_system_to_stage(stage_name, system);
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,8 @@ fn main() {
|
||||||
.add_event::<MyEvent>()
|
.add_event::<MyEvent>()
|
||||||
.add_resource(EventTriggerState::default())
|
.add_resource(EventTriggerState::default())
|
||||||
.add_resource_init::<EventListenerState>()
|
.add_resource_init::<EventListenerState>()
|
||||||
.add_system(into_resource_system("event_trigger", event_trigger_system))
|
.add_resource_system_fn("event_trigger", event_trigger_system)
|
||||||
.add_system(into_resource_system(
|
.add_resource_system_fn("event_listener", event_listener_system)
|
||||||
"event_listener",
|
|
||||||
event_listener_system,
|
|
||||||
))
|
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ fn main() {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.add_startup_system(setup)
|
.add_startup_system(setup)
|
||||||
.add_system(into_system("move", move_system))
|
.add_system_fn("move", move_system)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue