Skip to content

Commit

Permalink
Switch to named fields
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsDoot committed Mar 7, 2023
1 parent 99788a5 commit ab109d1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 7 additions & 1 deletion crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,13 @@ impl App {
continue;
}

self.add_schedule(OnTransition(variant.clone(), second), Schedule::new());
self.add_schedule(
OnTransition {
from: variant.clone(),
to: second,
},
Schedule::new(),
);
}
}

Expand Down
14 changes: 11 additions & 3 deletions crates/bevy_ecs/src/schedule/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,16 @@ pub struct OnEnter<S: States>(pub S);
pub struct OnExit<S: States>(pub S);

/// The label of a [`Schedule`](super::Schedule) that **only** runs whenever [`State<S>`]
/// exits the first given state, AND enters the second given state.
/// exits the `from` state, AND enters the `to` state.
///
/// Systems added to this schedule are always ran *after* [`OnExit`], and *before* [`OnEnter`].
#[derive(ScheduleLabel, Clone, Debug, PartialEq, Eq, Hash)]
pub struct OnTransition<S: States>(pub S, pub S);
pub struct OnTransition<S: States> {
/// The state being exited.
pub from: S,
/// The state being entered.
pub to: S,
}

/// A [`SystemSet`] that will run within `CoreSet::Update` when this state is active.
///
Expand Down Expand Up @@ -113,7 +118,10 @@ pub fn apply_state_transition<S: States>(world: &mut World) {

let exited = mem::replace(&mut world.resource_mut::<State<S>>().0, entered.clone());
world.run_schedule(OnExit(exited.clone()));
world.run_schedule(OnTransition(exited, entered.clone()));
world.run_schedule(OnTransition {
from: exited,
to: entered.clone(),
});
world.run_schedule(OnEnter(entered));
}
}

0 comments on commit ab109d1

Please sign in to comment.