Open alice-i-cecile opened 7 months ago
A simple working prototype:
fn set_next_state<S: States + Clone>(next_state: S) -> Self {
On::run(move |mut state: ResMut<NextState<S>>| {
state.set(next_state.clone());
})
}
The Clone
bound is required as NextState::set
takes ownership, and we need to be able to reuse the callback.
You might want to change this to take a closure instead, like mentioned here: https://github.com/aevyrie/bevy_eventlistener/issues/25
That would avoid the need for Clone, and you would be able to react to the contents of the event that is causing a state change.
set_next_state<S: States>(impl FnMut(E) -> S) -> Self
This is a common simple pattern that uses a surprising amount of boilerplate. We could simplify this to a single method call.