Skip to content

Commit 61c683f

Browse files
kettei-sprouttymockersf
authored andcommitted
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.
1 parent 833ee3f commit 61c683f

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

crates/bevy_app/src/main_schedule.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,16 @@ impl MainScheduleOrder {
195195
self.labels.insert(index + 1, schedule.intern());
196196
}
197197

198+
/// Adds the given `schedule` before the `before` schedule in the main list of schedules.
199+
pub fn insert_before(&mut self, before: impl ScheduleLabel, schedule: impl ScheduleLabel) {
200+
let index = self
201+
.labels
202+
.iter()
203+
.position(|current| (**current).eq(&before))
204+
.unwrap_or_else(|| panic!("Expected {before:?} to exist"));
205+
self.labels.insert(index, schedule.intern());
206+
}
207+
198208
/// Adds the given `schedule` after the `after` schedule in the list of startup schedules.
199209
pub fn insert_startup_after(
200210
&mut self,
@@ -208,6 +218,20 @@ impl MainScheduleOrder {
208218
.unwrap_or_else(|| panic!("Expected {after:?} to exist"));
209219
self.startup_labels.insert(index + 1, schedule.intern());
210220
}
221+
222+
/// Adds the given `schedule` before the `before` schedule in the list of startup schedules.
223+
pub fn insert_startup_before(
224+
&mut self,
225+
before: impl ScheduleLabel,
226+
schedule: impl ScheduleLabel,
227+
) {
228+
let index = self
229+
.startup_labels
230+
.iter()
231+
.position(|current| (**current).eq(&before))
232+
.unwrap_or_else(|| panic!("Expected {before:?} to exist"));
233+
self.startup_labels.insert(index, schedule.intern());
234+
}
211235
}
212236

213237
impl Main {
@@ -291,6 +315,16 @@ impl FixedMainScheduleOrder {
291315
.unwrap_or_else(|| panic!("Expected {after:?} to exist"));
292316
self.labels.insert(index + 1, schedule.intern());
293317
}
318+
319+
/// Adds the given `schedule` before the `before` schedule
320+
pub fn insert_before(&mut self, before: impl ScheduleLabel, schedule: impl ScheduleLabel) {
321+
let index = self
322+
.labels
323+
.iter()
324+
.position(|current| (**current).eq(&before))
325+
.unwrap_or_else(|| panic!("Expected {before:?} to exist"));
326+
self.labels.insert(index, schedule.intern());
327+
}
294328
}
295329

296330
impl FixedMain {

0 commit comments

Comments
 (0)