From f1c0850b814e203dda8fa0c615b7bbb239a6dc72 Mon Sep 17 00:00:00 2001 From: Niklas Eicker Date: Tue, 14 Feb 2023 21:30:14 +0000 Subject: [PATCH] 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](https://github.com/bevyengine/bevy/pull/7634#issuecomment-1428740311) 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. --- crates/bevy_app/src/app.rs | 4 ++-- crates/bevy_ecs/src/schedule/condition.rs | 2 +- crates/bevy_ecs/src/schedule/state.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index 37f27e6a385bd..ecf9245591995 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -321,7 +321,7 @@ impl App { /// These systems sets only run if the [`State`] resource matches their label. /// /// If you would like to control how other systems run based on the current state, - /// you can emulate this behavior using the [`state_equals`] [`Condition`](bevy_ecs::schedule::Condition). + /// you can emulate this behavior using the [`in_state`] [`Condition`](bevy_ecs::schedule::Condition). /// /// Note that you can also apply state transitions at other points in the schedule /// by adding the [`apply_state_transition`] system manually. @@ -342,7 +342,7 @@ impl App { main_schedule.configure_set( OnUpdate(variant.clone()) .in_base_set(CoreSet::Update) - .run_if(state_equals(variant)) + .run_if(in_state(variant)) .after(apply_state_transition::), ); } diff --git a/crates/bevy_ecs/src/schedule/condition.rs b/crates/bevy_ecs/src/schedule/condition.rs index 763d88d8e0901..957eb806d150c 100644 --- a/crates/bevy_ecs/src/schedule/condition.rs +++ b/crates/bevy_ecs/src/schedule/condition.rs @@ -92,7 +92,7 @@ pub mod common_conditions { /// # Panics /// /// The condition will panic if the resource does not exist. - pub fn state_equals(state: S) -> impl FnMut(Res>) -> bool { + pub fn in_state(state: S) -> impl FnMut(Res>) -> bool { move |current_state: Res>| current_state.0 == state } diff --git a/crates/bevy_ecs/src/schedule/state.rs b/crates/bevy_ecs/src/schedule/state.rs index 2ae15eb888e85..e2b51cf70e8c1 100644 --- a/crates/bevy_ecs/src/schedule/state.rs +++ b/crates/bevy_ecs/src/schedule/state.rs @@ -56,7 +56,7 @@ pub struct OnExit(pub S); /// A [`SystemSet`] that will run within `CoreSet::Update` when this state is active. /// /// This set, when created via `App::add_state`, is configured with both a base set and a run condition. -/// If all you want is the run condition, use the [`state_equals`](crate::schedule::common_conditions::state_equals) +/// If all you want is the run condition, use the [`in_state`](crate::schedule::common_conditions::in_state) /// [condition](super::Condition) directly. #[derive(SystemSet, Clone, Debug, PartialEq, Eq, Hash)] pub struct OnUpdate(pub S);