bevy/crates/bevy_ecs/src/schedule
Lee-Orr 63eb151619
Optional state (#11417)
# Objective

Adjust bevy internals to utilize `Option<Res<State<S>>>` instead of
`Res<State<S>>`, to allow for adding/removing states at runtime and
avoid unexpected panics.

As requested here:
https://github.com/bevyengine/bevy/pull/10088#issuecomment-1869185413

---

## Changelog

- Changed the use of `world.resource`/`world.resource_mut` to
`world.get_resource`/`world.get_resource_mut` in the
`run_enter_schedule` and `apply_state_transition` systems and handled
the `None` option.
- `in_state` now returns a ` FnMut(Option<Res<State<S>>>) -> bool +
Clone`, returning `false` if the resource doesn't exist.
- `state_exists_and_equals` was marked as deprecated, and now just runs
and returns `in_state`, since their bevhaviour is now identical
- `state_changed` now takes an `Option<Res<State<S>>>` and returns
`false` if it does not exist.

I would like to remove `state_exists_and_equals` fully, but wanted to
ensure that is acceptable before doing so.

---------

Co-authored-by: Mike <mike.hsu@gmail.com>
2024-01-19 21:38:04 +00:00
..
executor Reorder impl to be the same as the trait (#10964) 2023-12-13 21:19:49 +00:00
condition.rs Optional state (#11417) 2024-01-19 21:38:04 +00:00
config.rs Auto insert sync points (#9822) 2023-12-14 16:34:01 +00:00
graph_utils.rs Auto insert sync points (#9822) 2023-12-14 16:34:01 +00:00
mod.rs Simplify equality assertions (#10988) 2023-12-16 23:58:41 +00:00
schedule.rs Fix doc of [Schedules] to mention exclusion of current schedule. (#11360) 2024-01-15 19:13:13 +00:00
set.rs Reorder impl to be the same as the trait (#10964) 2023-12-13 21:19:49 +00:00
state.rs Optional state (#11417) 2024-01-19 21:38:04 +00:00