diff --git a/.github/ISSUE_TEMPLATE/docs_improvement.md b/.github/ISSUE_TEMPLATE/docs_improvement.md index f2dc170a81..4bc84c5fc9 100644 --- a/.github/ISSUE_TEMPLATE/docs_improvement.md +++ b/.github/ISSUE_TEMPLATE/docs_improvement.md @@ -10,4 +10,4 @@ assignees: '' Provide a link to the documentation and describe how it could be improved. In what ways is it incomplete, incorrect, or misleading? -If you have suggestions on exactly what the new docs should say, feel free to include them here. Alternatively, make the changes yourself and [create a pull request](https://bevyengine.org/learn/book/contributing/code/) instead. +If you have suggestions on exactly what the new docs should say, feel free to include them here. Alternatively, make the changes yourself and [create a pull request](https://bevyengine.org/learn/contribute/helping-out/writing-docs/) instead. diff --git a/crates/bevy_state/src/condition.rs b/crates/bevy_state/src/condition.rs index dac281b7a3..f0a6197087 100644 --- a/crates/bevy_state/src/condition.rs +++ b/crates/bevy_state/src/condition.rs @@ -9,11 +9,14 @@ use bevy_ecs::{change_detection::DetectChanges, system::Res}; /// ``` /// # use bevy_ecs::prelude::*; /// # use bevy_state::prelude::*; +/// # use bevy_app::{App, Update}; +/// # use bevy_state::app::StatesPlugin; /// # #[derive(Resource, Default)] /// # struct Counter(u8); -/// # let mut app = Schedule::default(); -/// # let mut world = World::new(); -/// # world.init_resource::(); +/// # let mut app = App::new(); +/// # app +/// # .init_resource::() +/// # .add_plugins(StatesPlugin); /// #[derive(States, Clone, Copy, Default, Eq, PartialEq, Hash, Debug)] /// enum GameState { /// #[default] @@ -21,7 +24,7 @@ use bevy_ecs::{change_detection::DetectChanges, system::Res}; /// Paused, /// } /// -/// app.add_systems( +/// app.add_systems(Update, /// // `state_exists` will only return true if the /// // given state exists /// my_system.run_if(state_exists::), @@ -31,15 +34,15 @@ use bevy_ecs::{change_detection::DetectChanges, system::Res}; /// counter.0 += 1; /// } /// -/// // `GameState` does not yet exist `my_system` won't run -/// app.run(&mut world); -/// assert_eq!(world.resource::().0, 0); +/// // `GameState` does not yet exist so `my_system` won't run +/// app.update(); +/// assert_eq!(app.world().resource::().0, 0); /// -/// world.init_resource::>(); +/// app.init_state::(); /// /// // `GameState` now exists so `my_system` will run -/// app.run(&mut world); -/// assert_eq!(world.resource::().0, 1); +/// app.update(); +/// assert_eq!(app.world().resource::().0, 1); /// ``` pub fn state_exists(current_state: Option>>) -> bool { current_state.is_some() @@ -55,11 +58,14 @@ pub fn state_exists(current_state: Option>>) -> bool { /// ``` /// # use bevy_ecs::prelude::*; /// # use bevy_state::prelude::*; +/// # use bevy_app::{App, Update}; +/// # use bevy_state::app::StatesPlugin; /// # #[derive(Resource, Default)] /// # struct Counter(u8); -/// # let mut app = Schedule::default(); -/// # let mut world = World::new(); -/// # world.init_resource::(); +/// # let mut app = App::new(); +/// # app +/// # .init_resource::() +/// # .add_plugins(StatesPlugin); /// #[derive(States, Clone, Copy, Default, Eq, PartialEq, Hash, Debug)] /// enum GameState { /// #[default] @@ -67,14 +73,14 @@ pub fn state_exists(current_state: Option>>) -> bool { /// Paused, /// } /// -/// world.init_resource::>(); -/// -/// app.add_systems(( -/// // `in_state` will only return true if the -/// // given state equals the given value -/// play_system.run_if(in_state(GameState::Playing)), -/// pause_system.run_if(in_state(GameState::Paused)), -/// )); +/// app +/// .init_state::() +/// .add_systems(Update, ( +/// // `in_state` will only return true if the +/// // given state equals the given value +/// play_system.run_if(in_state(GameState::Playing)), +/// pause_system.run_if(in_state(GameState::Paused)), +/// )); /// /// fn play_system(mut counter: ResMut) { /// counter.0 += 1; @@ -85,14 +91,14 @@ pub fn state_exists(current_state: Option>>) -> bool { /// } /// /// // We default to `GameState::Playing` so `play_system` runs -/// app.run(&mut world); -/// assert_eq!(world.resource::().0, 1); +/// app.update(); +/// assert_eq!(app.world().resource::().0, 1); /// -/// *world.resource_mut::>() = State::new(GameState::Paused); +/// app.insert_state(GameState::Paused); /// /// // Now that we are in `GameState::Pause`, `pause_system` will run -/// app.run(&mut world); -/// assert_eq!(world.resource::().0, 0); +/// app.update(); +/// assert_eq!(app.world().resource::().0, 0); /// ``` pub fn in_state(state: S) -> impl FnMut(Option>>) -> bool + Clone { move |current_state: Option>>| match current_state { @@ -114,11 +120,14 @@ pub fn in_state(state: S) -> impl FnMut(Option>>) -> boo /// ``` /// # use bevy_ecs::prelude::*; /// # use bevy_state::prelude::*; +/// # use bevy_state::app::StatesPlugin; +/// # use bevy_app::{App, Update}; /// # #[derive(Resource, Default)] /// # struct Counter(u8); -/// # let mut app = Schedule::default(); -/// # let mut world = World::new(); -/// # world.init_resource::(); +/// # let mut app = App::new(); +/// # app +/// # .init_resource::() +/// # .add_plugins(StatesPlugin); /// #[derive(States, Clone, Copy, Default, Eq, PartialEq, Hash, Debug)] /// enum GameState { /// #[default] @@ -126,32 +135,32 @@ pub fn in_state(state: S) -> impl FnMut(Option>>) -> boo /// Paused, /// } /// -/// world.init_resource::>(); -/// -/// app.add_systems( -/// // `state_changed` will only return true if the -/// // given states value has just been updated or -/// // the state has just been added -/// my_system.run_if(state_changed::), -/// ); +/// app +/// .init_state::() +/// .add_systems(Update, +/// // `state_changed` will only return true if the +/// // given states value has just been updated or +/// // the state has just been added +/// my_system.run_if(state_changed::), +/// ); /// /// fn my_system(mut counter: ResMut) { /// counter.0 += 1; /// } /// /// // `GameState` has just been added so `my_system` will run -/// app.run(&mut world); -/// assert_eq!(world.resource::().0, 1); +/// app.update(); +/// assert_eq!(app.world().resource::().0, 1); /// /// // `GameState` has not been updated so `my_system` will not run -/// app.run(&mut world); -/// assert_eq!(world.resource::().0, 1); +/// app.update(); +/// assert_eq!(app.world().resource::().0, 1); /// -/// *world.resource_mut::>() = State::new(GameState::Paused); +/// app.insert_state(GameState::Paused); /// /// // Now that `GameState` has been updated `my_system` will run -/// app.run(&mut world); -/// assert_eq!(world.resource::().0, 2); +/// app.update(); +/// assert_eq!(app.world().resource::().0, 2); /// ``` pub fn state_changed(current_state: Option>>) -> bool { let Some(current_state) = current_state else {