Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend AppBuilder api with add_system_set and similar methods #1453

Merged
merged 3 commits into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion crates/bevy_app/src/app_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
};
use bevy_ecs::{
clear_trackers_system, FromResources, IntoExclusiveSystem, IntoSystem, Resource, Resources,
RunOnce, Schedule, Stage, StateStage, SystemDescriptor, SystemStage, World,
RunOnce, Schedule, Stage, StateStage, SystemDescriptor, SystemSet, SystemStage, World,
};
use bevy_utils::tracing::debug;

Expand Down Expand Up @@ -129,6 +129,10 @@ impl AppBuilder {
self.add_system_to_stage(stage::UPDATE, system)
}

pub fn add_system_set(&mut self, system_set: SystemSet) -> &mut Self {
self.add_system_set_to_stage(stage::UPDATE, system_set)
}

pub fn add_system_to_stage(
&mut self,
stage_name: &'static str,
Expand All @@ -138,6 +142,17 @@ impl AppBuilder {
self
}

pub fn add_system_set_to_stage(
&mut self,
stage_name: &'static str,
system_set: SystemSet,
) -> &mut Self {
self.app
.schedule
.add_system_set_to_stage(stage_name, system_set);
self
}

pub fn add_startup_system(&mut self, system: impl Into<SystemDescriptor>) -> &mut Self {
self.add_startup_system_to_stage(startup_stage::STARTUP, system)
}
Expand Down
17 changes: 17 additions & 0 deletions crates/bevy_ecs/src/schedule/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,23 @@ impl Schedule {
self
}

pub fn add_system_set_to_stage(
&mut self,
stage_name: &'static str,
system_set: SystemSet,
) -> &mut Self {
let stage = self
TheRawMeatball marked this conversation as resolved.
Show resolved Hide resolved
.get_stage_mut::<SystemStage>(stage_name)
.unwrap_or_else(|| {
panic!(
"Stage '{}' does not exist or is not a SystemStage",
stage_name
)
});
stage.add_system_set(system_set);
self
}

pub fn stage<T: Stage, F: FnOnce(&mut T) -> &mut T>(
&mut self,
name: &str,
Expand Down