Allow the editing of startup schedules (#10969)
# Objective Fixes #10968 ## Solution Pull startup schedules from a list of `ScheduleLabel`s in the same way the update schedules are handled. --- ## Changelog - Added `MainScheduleOrder::startup_labels` to allow the editing of the startup schedule order. ## Migration Guide - Added a new field to `MainScheduleOrder`, `startup_labels`, for editing the startup schedule order.
This commit is contained in:
parent
70a592f31a
commit
a4e0a0c0b9
@ -118,8 +118,10 @@ pub struct Last;
|
|||||||
/// their order.
|
/// their order.
|
||||||
#[derive(Resource, Debug)]
|
#[derive(Resource, Debug)]
|
||||||
pub struct MainScheduleOrder {
|
pub struct MainScheduleOrder {
|
||||||
/// The labels to run for the [`Main`] schedule (in the order they will be run).
|
/// The labels to run for the main phase of the [`Main`] schedule (in the order they will be run).
|
||||||
pub labels: Vec<InternedScheduleLabel>,
|
pub labels: Vec<InternedScheduleLabel>,
|
||||||
|
/// The labels to run for the startup phase of the [`Main`] schedule (in the order they will be run).
|
||||||
|
pub startup_labels: Vec<InternedScheduleLabel>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for MainScheduleOrder {
|
impl Default for MainScheduleOrder {
|
||||||
@ -135,12 +137,13 @@ impl Default for MainScheduleOrder {
|
|||||||
PostUpdate.intern(),
|
PostUpdate.intern(),
|
||||||
Last.intern(),
|
Last.intern(),
|
||||||
],
|
],
|
||||||
|
startup_labels: vec![PreStartup.intern(), Startup.intern(), PostStartup.intern()],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MainScheduleOrder {
|
impl MainScheduleOrder {
|
||||||
/// Adds the given `schedule` after the `after` schedule
|
/// Adds the given `schedule` after the `after` schedule in the main list of schedules.
|
||||||
pub fn insert_after(&mut self, after: impl ScheduleLabel, schedule: impl ScheduleLabel) {
|
pub fn insert_after(&mut self, after: impl ScheduleLabel, schedule: impl ScheduleLabel) {
|
||||||
let index = self
|
let index = self
|
||||||
.labels
|
.labels
|
||||||
@ -149,15 +152,31 @@ impl MainScheduleOrder {
|
|||||||
.unwrap_or_else(|| panic!("Expected {after:?} to exist"));
|
.unwrap_or_else(|| panic!("Expected {after:?} to exist"));
|
||||||
self.labels.insert(index + 1, schedule.intern());
|
self.labels.insert(index + 1, schedule.intern());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Adds the given `schedule` after the `after` schedule in the list of startup schedules.
|
||||||
|
pub fn insert_startup_after(
|
||||||
|
&mut self,
|
||||||
|
after: impl ScheduleLabel,
|
||||||
|
schedule: impl ScheduleLabel,
|
||||||
|
) {
|
||||||
|
let index = self
|
||||||
|
.startup_labels
|
||||||
|
.iter()
|
||||||
|
.position(|current| (**current).eq(&after))
|
||||||
|
.unwrap_or_else(|| panic!("Expected {after:?} to exist"));
|
||||||
|
self.startup_labels.insert(index + 1, schedule.intern());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Main {
|
impl Main {
|
||||||
/// A system that runs the "main schedule"
|
/// A system that runs the "main schedule"
|
||||||
pub fn run_main(world: &mut World, mut run_at_least_once: Local<bool>) {
|
pub fn run_main(world: &mut World, mut run_at_least_once: Local<bool>) {
|
||||||
if !*run_at_least_once {
|
if !*run_at_least_once {
|
||||||
let _ = world.try_run_schedule(PreStartup);
|
world.resource_scope(|world, order: Mut<MainScheduleOrder>| {
|
||||||
let _ = world.try_run_schedule(Startup);
|
for &label in &order.startup_labels {
|
||||||
let _ = world.try_run_schedule(PostStartup);
|
let _ = world.try_run_schedule(label);
|
||||||
|
}
|
||||||
|
});
|
||||||
*run_at_least_once = true;
|
*run_at_least_once = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user