Skip to content

Commit f1c0850

Browse files
committed
Rename state_equals condition to in_state (#7677)
# Objective - Improve readability of the run condition for systems only running in a certain state ## Solution - Rename `state_equals` to `in_state` (see [comment by cart](#7634 (comment)) in #7634 ) - `.run_if(state_equals(variant))` now is `.run_if(in_state(variant))` This breaks the naming pattern a bit with the related conditions `state_exists` and `state_exists_and_equals` but I could not think of better names for those and think the improved readability of `in_state` is worth it.
1 parent fae61ad commit f1c0850

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

crates/bevy_app/src/app.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ impl App {
321321
/// These systems sets only run if the [`State<S>`] resource matches their label.
322322
///
323323
/// If you would like to control how other systems run based on the current state,
324-
/// you can emulate this behavior using the [`state_equals`] [`Condition`](bevy_ecs::schedule::Condition).
324+
/// you can emulate this behavior using the [`in_state`] [`Condition`](bevy_ecs::schedule::Condition).
325325
///
326326
/// Note that you can also apply state transitions at other points in the schedule
327327
/// by adding the [`apply_state_transition`] system manually.
@@ -342,7 +342,7 @@ impl App {
342342
main_schedule.configure_set(
343343
OnUpdate(variant.clone())
344344
.in_base_set(CoreSet::Update)
345-
.run_if(state_equals(variant))
345+
.run_if(in_state(variant))
346346
.after(apply_state_transition::<S>),
347347
);
348348
}

crates/bevy_ecs/src/schedule/condition.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub mod common_conditions {
9292
/// # Panics
9393
///
9494
/// The condition will panic if the resource does not exist.
95-
pub fn state_equals<S: States>(state: S) -> impl FnMut(Res<State<S>>) -> bool {
95+
pub fn in_state<S: States>(state: S) -> impl FnMut(Res<State<S>>) -> bool {
9696
move |current_state: Res<State<S>>| current_state.0 == state
9797
}
9898

crates/bevy_ecs/src/schedule/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub struct OnExit<S: States>(pub S);
5656
/// A [`SystemSet`] that will run within `CoreSet::Update` when this state is active.
5757
///
5858
/// This set, when created via `App::add_state`, is configured with both a base set and a run condition.
59-
/// If all you want is the run condition, use the [`state_equals`](crate::schedule::common_conditions::state_equals)
59+
/// If all you want is the run condition, use the [`in_state`](crate::schedule::common_conditions::in_state)
6060
/// [condition](super::Condition) directly.
6161
#[derive(SystemSet, Clone, Debug, PartialEq, Eq, Hash)]
6262
pub struct OnUpdate<S: States>(pub S);

0 commit comments

Comments
 (0)