bevy/crates
MiniaczQ 5ed296ff03
Restore overwrite capabilities of insert_state (#13848)
# Objective

- Fixes #13844
- Warn user when initializing state multiple times

## Solution

- `insert_state` will overwrite previously initialized state value,
reset transition events and re-insert it's own transition event.
- `init_state`, `add_sub_state`, `add_computed_state` are idempotent, so
calling them multiple times will emit a warning.

## Testing

- 2 tests confirming overwrite works.
- Given the example from #13844
```rs
use bevy::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .insert_state(AppState::A)
        .insert_state(AppState::B)
        .add_systems(OnEnter(AppState::A), setup_a)
        .add_systems(OnEnter(AppState::B), setup_b)
        .add_systems(OnExit(AppState::A), cleanup_a)
        .add_systems(OnExit(AppState::B), cleanup_b)
        .run();
}

#[derive(States, Debug, Clone, PartialEq, Eq, Hash)]
enum AppState {
    A,
    B,
}

fn setup_a() {
    info!("setting up A");
}

fn setup_b() {
    info!("setting up B");
}

fn cleanup_a() {
    info!("cleaning up A");
}

fn cleanup_b() {
    info!("cleaning up B");
}
```

We get the following result:
```
INFO states: setting up B
```
which matches our expectations.
2024-06-15 11:02:44 +02:00
..
bevy_a11y Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_animation Make the component types of the new animation players clonable. (#13736) 2024-06-09 01:18:07 +02:00
bevy_app Fix is_plugin_added::<Self>() being true during build (#13817) 2024-06-14 21:52:29 +02:00
bevy_asset Improve error handling for AssetServer::add_async (#13745) 2024-06-10 19:31:41 +02:00
bevy_audio Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_color Wgpu 0.20 (#13186) 2024-06-14 20:55:42 +02:00
bevy_core Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_core_pipeline Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_derive Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_dev_tools Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_diagnostic Poll system information in separate tasks (#13693) 2024-06-10 22:30:56 +02:00
bevy_dylib Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_dynamic_plugin Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_ecs Ensure that events are updated even when using a bare-bones Bevy App (#13808) (#13842) 2024-06-14 20:53:37 +02:00
bevy_encase_derive Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_gilrs Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_gizmos view.inverse_clip_from_world should be world_from_clip (#13756) 2024-06-09 16:55:22 +02:00
bevy_gltf Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_hierarchy Fix EntityCommands::despawn docs (#13774) 2024-06-09 20:52:52 +02:00
bevy_input Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_internal Add missing plugins to doc of DefaultPlugins (#13833) 2024-06-14 20:55:41 +02:00
bevy_log Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_macro_utils Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_math Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_mikktspace Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_pbr Revert "Make FOG_ENABLED a shader_def instead of material flag (#13783)" (#13803) 2024-06-11 02:01:14 +02:00
bevy_ptr Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_reflect Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_render Wgpu 0.20 (#13186) 2024-06-14 20:55:42 +02:00
bevy_scene Update serialize flag for bevy_ecs (#13740) 2024-06-10 19:31:41 +02:00
bevy_sprite Add from_color to StandardMaterial and ColorMaterial (#13791) 2024-06-11 02:01:14 +02:00
bevy_state Restore overwrite capabilities of insert_state (#13848) 2024-06-15 11:02:44 +02:00
bevy_tasks Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_text fix non-exact text h-alignment (#13846) 2024-06-14 21:47:43 +02:00
bevy_time Ensure that events are updated even when using a bare-bones Bevy App (#13808) (#13842) 2024-06-14 20:53:37 +02:00
bevy_transform Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_ui reduce the antialias strength (#13814) 2024-06-14 20:55:41 +02:00
bevy_utils Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_window Release Candidate 0.14.0-rc.2 2024-06-06 23:56:56 +02:00
bevy_winit 13743 app exit hang (#13744) 2024-06-09 01:18:07 +02:00