mirror of
https://github.com/bevyengine/bevy
synced 2024-11-25 14:10:19 +00:00
feat: add insert_after and insert_startup_before (#13941)
# Objective Fixes #13866 ## Solution Add `insert_before` in **FixedMainScheduleOrder** and **MainScheduleOrder**, add `insert_startup_before` in **MainScheduleOrder**, applying the same logic as `insert_after`, except for parameters naming and insertion index.
This commit is contained in:
parent
6eec73a9a5
commit
2f9c42bb33
1 changed files with 34 additions and 0 deletions
|
@ -195,6 +195,16 @@ impl MainScheduleOrder {
|
|||
self.labels.insert(index + 1, schedule.intern());
|
||||
}
|
||||
|
||||
/// Adds the given `schedule` before the `before` schedule in the main list of schedules.
|
||||
pub fn insert_before(&mut self, before: impl ScheduleLabel, schedule: impl ScheduleLabel) {
|
||||
let index = self
|
||||
.labels
|
||||
.iter()
|
||||
.position(|current| (**current).eq(&before))
|
||||
.unwrap_or_else(|| panic!("Expected {before:?} to exist"));
|
||||
self.labels.insert(index, schedule.intern());
|
||||
}
|
||||
|
||||
/// Adds the given `schedule` after the `after` schedule in the list of startup schedules.
|
||||
pub fn insert_startup_after(
|
||||
&mut self,
|
||||
|
@ -208,6 +218,20 @@ impl MainScheduleOrder {
|
|||
.unwrap_or_else(|| panic!("Expected {after:?} to exist"));
|
||||
self.startup_labels.insert(index + 1, schedule.intern());
|
||||
}
|
||||
|
||||
/// Adds the given `schedule` before the `before` schedule in the list of startup schedules.
|
||||
pub fn insert_startup_before(
|
||||
&mut self,
|
||||
before: impl ScheduleLabel,
|
||||
schedule: impl ScheduleLabel,
|
||||
) {
|
||||
let index = self
|
||||
.startup_labels
|
||||
.iter()
|
||||
.position(|current| (**current).eq(&before))
|
||||
.unwrap_or_else(|| panic!("Expected {before:?} to exist"));
|
||||
self.startup_labels.insert(index, schedule.intern());
|
||||
}
|
||||
}
|
||||
|
||||
impl Main {
|
||||
|
@ -291,6 +315,16 @@ impl FixedMainScheduleOrder {
|
|||
.unwrap_or_else(|| panic!("Expected {after:?} to exist"));
|
||||
self.labels.insert(index + 1, schedule.intern());
|
||||
}
|
||||
|
||||
/// Adds the given `schedule` before the `before` schedule
|
||||
pub fn insert_before(&mut self, before: impl ScheduleLabel, schedule: impl ScheduleLabel) {
|
||||
let index = self
|
||||
.labels
|
||||
.iter()
|
||||
.position(|current| (**current).eq(&before))
|
||||
.unwrap_or_else(|| panic!("Expected {before:?} to exist"));
|
||||
self.labels.insert(index, schedule.intern());
|
||||
}
|
||||
}
|
||||
|
||||
impl FixedMain {
|
||||
|
|
Loading…
Reference in a new issue