Skip to content
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 convenience methods for checking a set of inputs #2760

Closed
wants to merge 2 commits into from

Conversation

DJMcNab
Copy link
Member

@DJMcNab DJMcNab commented Aug 31, 2021

Objective

Make it easier to check if some set of inputs matches a key, such as if you want to allow all of space or up or w for jumping.

Currently, this requires:

if keyboard.pressed(KeyCode::Space)
            || keyboard.pressed(KeyCode::Up)
            || keyboard.pressed(KeyCode::W) {
    // ...

Solution

Add an implementation of the helper methods, which very simply iterate through the items, used as:

if keyboard.any_pressed([KeyCode::Space, KeyCode::Up, KeyCode::W]) {

@github-actions github-actions bot added the S-Needs-Triage This issue needs to be labelled label Aug 31, 2021
@DJMcNab DJMcNab added A-Input Player input via keyboard, mouse, gamepad, and more C-Enhancement A new feature and removed S-Needs-Triage This issue needs to be labelled labels Aug 31, 2021
@alice-i-cecile
Copy link
Member

Can you add all_pressed as well? This is particularly useful for modifier keys.

@DJMcNab
Copy link
Member Author

DJMcNab commented Sep 1, 2021

Maybe? I feel like that is less useful, because all the modifier keys have at least two versions - e.g. left control and right control.

I definitely would add that if there's consensus that it's useful though.

@mockersf mockersf added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Sep 1, 2021
@cart
Copy link
Member

cart commented Sep 1, 2021

Definitely looks useful! Some "due diligence" questions:

  1. Would we need this if/when we add a proper "map-able action system"? Ex: action = Jump, mapped_keys = Keyboard::A, Joystick::X. We should reflexively push back against multiple apis that accomplish the same goal.
  2. Should we just build an action system instead? Should we merge this now and then remove it when the action system is built? Should we keep both?

@TheRawMeatball
Copy link
Member

I think merge now, think about action system later is the most reasonable choice.

@DJMcNab
Copy link
Member Author

DJMcNab commented Sep 1, 2021

  1. If the action system would remove the Input struct to force you to use it, then this would naturally slide off.
    If someone would use this method, the alternative that they're going to do is an or of multiple calls to this, which gets messy.
  2. This is solving a pain point now, instead of in (indeterminate time in the future).

@cart
Copy link
Member

cart commented Sep 1, 2021

Cool I agree that merging this now is probably the right choice, just didn't want to bias things when introducing the questions :). I think all_pressed would also be a useful addition.

@cart
Copy link
Member

cart commented Sep 1, 2021

bors r+

bors bot pushed a commit that referenced this pull request Sep 1, 2021
# Objective

Make it easier to check if some set of inputs matches a key, such as if you want to allow all of space or up or w for jumping.

Currently, this requires:
```rust
if keyboard.pressed(KeyCode::Space)
            || keyboard.pressed(KeyCode::Up)
            || keyboard.pressed(KeyCode::W) {
    // ...
```

## Solution

Add an implementation of the helper methods, which very simply iterate through the items, used as:
```rust
if keyboard.any_pressed([KeyCode::Space, KeyCode::Up, KeyCode::W]) {
```
@bors bors bot changed the title Add convenience methods for checking a set of inputs [Merged by Bors] - Add convenience methods for checking a set of inputs Sep 1, 2021
@bors bors bot closed this Sep 1, 2021
@DJMcNab DJMcNab deleted the any_pressed branch September 2, 2021 07:38
DJMcNab pushed a commit to DJMcNab/bevy-series1 that referenced this pull request Sep 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Input Player input via keyboard, mouse, gamepad, and more C-Enhancement A new feature S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants