-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Merged by Bors] - add common run conditions to bevy_input #7806
[Merged by Bors] - add common run conditions to bevy_input #7806
Conversation
9ec7e86
to
414d3a6
Compare
414d3a6
to
42e1a3d
Compare
Quick and dirty! Convenient though. I'll look into adding the same in LWIM too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are well-made, well-documented and useful.
I'd like to see bevy_window::close_on_esc
use these instead of having the keycode baked in, but I think that should be a seperate PR.
Co-authored-by: Carter Weinberg <[email protected]>
/// .run(); | ||
/// } | ||
/// | ||
/// fn update_pause_state(mut paused: ResMut<Paused>, input: Input<KeyCode>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: I think I see what you are going for, but it's a little confusing because I don't think update_pause_state is ever getting called. Should that be in the schedule somewhere?
{ | ||
let mut active = default; | ||
move |inputs: Res<Input<T>>| { | ||
active ^= inputs.just_pressed(input); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind explaining what this symbol is ^=
for my smooth brain pls lol. I think I understand but it'd be worth clarifying haha.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's xor
assign. So basically if just_pressed { active = !active }
.
Reading this I had to think for a minute to know why this works so I should probably just write the simpler clearer way lol
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works because
inactive ^ not pressed -> inactive
inactive ^ pressed -> active
active ^ not pressed -> active
active ^ pressed -> inactive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, okay I think that makes sense to me lol.
/// } | ||
/// | ||
/// ``` | ||
pub fn input_toggle_active<T>(default: bool, input: T) -> impl FnMut(Res<Input<T>>) -> bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ Where is this function getting called?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it mostly looks good! I'd approve once I understand what's happening with input_toggle_active
.
bors r+ |
# Objective Common run conditions can be very useful for quick and ergonomic changes to when a system runs. Specifically what I'd like to be able to do is ```rust use bevy::prelude::*; use bevy::input::common_conditions::input_toggle_active; fn main() { App::new() .add_plugins(DefaultPlugins) .add_plugin( bevy_inspector_egui::quick::WorldInspectorPlugin::default() .run_if(input_toggle_active(true, KeyCode::Escape) ) .run(); } ``` ## Solution - add `bevy_input::common_conditions` module with `input_toggle_active`, `input_pressed`, `input_just_pressed`, `input_just_released` ## Changelog - added common run conditions for `bevy_input` - you can now use `.add_system(jump.run_if(input_just_pressed(KeyCode::Space)))`
# Objective Common run conditions can be very useful for quick and ergonomic changes to when a system runs. Specifically what I'd like to be able to do is ```rust use bevy::prelude::*; use bevy::input::common_conditions::input_toggle_active; fn main() { App::new() .add_plugins(DefaultPlugins) .add_plugin( bevy_inspector_egui::quick::WorldInspectorPlugin::default() .run_if(input_toggle_active(true, KeyCode::Escape) ) .run(); } ``` ## Solution - add `bevy_input::common_conditions` module with `input_toggle_active`, `input_pressed`, `input_just_pressed`, `input_just_released` ## Changelog - added common run conditions for `bevy_input` - you can now use `.add_system(jump.run_if(input_just_pressed(KeyCode::Space)))`
Objective
Common run conditions can be very useful for quick and ergonomic changes to when a system runs.
Specifically what I'd like to be able to do is
Solution
bevy_input::common_conditions
module withinput_toggle_active
,input_pressed
,input_just_pressed
,input_just_released
Changelog
bevy_input
.add_system(jump.run_if(input_just_pressed(KeyCode::Space)))