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 10, 2023
1 parent 8c4f8b4 commit ae7383e
Showing 1 changed file with 11 additions and 3 deletions.
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 ae7383e

Please sign in to comment.