Skip to content

Commit 6c003ef

Browse files
authored
Loosen add_state_scoped_event trait bound. (#19401)
Fixes #18623, allowing `add_state_scoped_event` to work with computed states. As a side note, should state scoped events be updated to match the recently changed [state scoped entities](https://github.com/bevyengine/bevy/blob/main/release-content/migration-guides/rename_StateScoped.md)?
1 parent 439c0fb commit 6c003ef

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

crates/bevy_state/src/state_scoped_events.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use bevy_ecs::{
1010
};
1111
use bevy_platform::collections::HashMap;
1212

13-
use crate::state::{FreelyMutableState, OnExit, StateTransitionEvent};
13+
use crate::state::{OnExit, StateTransitionEvent, States};
1414

1515
fn clear_event_queue<E: Event>(w: &mut World) {
1616
if let Some(mut queue) = w.get_resource_mut::<Events<E>>() {
@@ -19,11 +19,11 @@ fn clear_event_queue<E: Event>(w: &mut World) {
1919
}
2020

2121
#[derive(Resource)]
22-
struct StateScopedEvents<S: FreelyMutableState> {
22+
struct StateScopedEvents<S: States> {
2323
cleanup_fns: HashMap<S, Vec<fn(&mut World)>>,
2424
}
2525

26-
impl<S: FreelyMutableState> StateScopedEvents<S> {
26+
impl<S: States> StateScopedEvents<S> {
2727
fn add_event<E: Event>(&mut self, state: S) {
2828
self.cleanup_fns
2929
.entry(state)
@@ -41,15 +41,15 @@ impl<S: FreelyMutableState> StateScopedEvents<S> {
4141
}
4242
}
4343

44-
impl<S: FreelyMutableState> Default for StateScopedEvents<S> {
44+
impl<S: States> Default for StateScopedEvents<S> {
4545
fn default() -> Self {
4646
Self {
4747
cleanup_fns: HashMap::default(),
4848
}
4949
}
5050
}
5151

52-
fn cleanup_state_scoped_event<S: FreelyMutableState>(
52+
fn cleanup_state_scoped_event<S: States>(
5353
mut c: Commands,
5454
mut transitions: EventReader<StateTransitionEvent<S>>,
5555
) {
@@ -70,7 +70,7 @@ fn cleanup_state_scoped_event<S: FreelyMutableState>(
7070
});
7171
}
7272

73-
fn add_state_scoped_event_impl<E: Event, S: FreelyMutableState>(
73+
fn add_state_scoped_event_impl<E: Event, S: States>(
7474
app: &mut SubApp,
7575
_p: PhantomData<E>,
7676
state: S,
@@ -94,18 +94,18 @@ pub trait StateScopedEventsAppExt {
9494
/// cleanup and the [`OnExit`] schedule for the target state. All of these (state scoped
9595
/// entities and events cleanup, and `OnExit`) occur within schedule [`StateTransition`](crate::prelude::StateTransition)
9696
/// and system set `StateTransitionSystems::ExitSchedules`.
97-
fn add_state_scoped_event<E: Event>(&mut self, state: impl FreelyMutableState) -> &mut Self;
97+
fn add_state_scoped_event<E: Event>(&mut self, state: impl States) -> &mut Self;
9898
}
9999

100100
impl StateScopedEventsAppExt for App {
101-
fn add_state_scoped_event<E: Event>(&mut self, state: impl FreelyMutableState) -> &mut Self {
101+
fn add_state_scoped_event<E: Event>(&mut self, state: impl States) -> &mut Self {
102102
add_state_scoped_event_impl(self.main_mut(), PhantomData::<E>, state);
103103
self
104104
}
105105
}
106106

107107
impl StateScopedEventsAppExt for SubApp {
108-
fn add_state_scoped_event<E: Event>(&mut self, state: impl FreelyMutableState) -> &mut Self {
108+
fn add_state_scoped_event<E: Event>(&mut self, state: impl States) -> &mut Self {
109109
add_state_scoped_event_impl(self, PhantomData::<E>, state);
110110
self
111111
}

0 commit comments

Comments
 (0)