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 Gamepads resource #3257

Closed
wants to merge 8 commits into from

Conversation

CrazyRoka
Copy link
Contributor

Objective

Fixes #3245

Solution

  • Move GamepadLobby to lib
  • Add connection_system to InputPlugin
  • Updated gamepad_input example

@github-actions github-actions bot added the S-Needs-Triage This issue needs to be labelled label Dec 5, 2021
@alice-i-cecile alice-i-cecile added A-Input Player input via keyboard, mouse, gamepad, and more C-Usability A simple quality-of-life change that makes Bevy easier to use C-Examples An addition or correction to our examples and removed S-Needs-Triage This issue needs to be labelled labels Dec 5, 2021
@alice-i-cecile
Copy link
Member

Looks great! Thanks for tackling this :) I would like to see some basic docs, since this is part of the public API now, but otherwise this LGTM.

@alice-i-cecile
Copy link
Member

I've added the needs-migration-guide label to this. It's not technically breaking, but users should probably replace their copy-pasted code, and use the built-in functionality instead.

@alice-i-cecile
Copy link
Member

Thinking about this a bit further, I think that connection_system should be renamed to gamepad_connection_system, in order to better communicate what it does out of context.

@alice-i-cecile
Copy link
Member

Great! You have my approval :) @CrazyRoka, you should click "Resolve Comment" on the comments that I've left so this PR's state is easier to follow for future reviewers.

crates/bevy_input/src/lib.rs Outdated Show resolved Hide resolved
crates/bevy_input/src/gamepad.rs Outdated Show resolved Hide resolved
@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review labels Dec 5, 2021
Copy link
Contributor

@IceSentry IceSentry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really like the name GamepadLobby, but I can't figure out anything better either. Otherwise, looks good to me.

@CrazyRoka
Copy link
Contributor Author

@alice-i-cecile @MinerSebas Can you review my updates?

///
/// [Gamepad]s are registered and deregistered in [gamepad_connection_system]
pub struct GamepadLobby {
pub gamepads: HashSet<Gamepad>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an implementation detail that we shouldn't expose directly to users (who could accidentally remove "active" gamepad and break guarantees that this list contains "active" gamepads). Instead, lets make this private and implement a method like GamepadLobby::contains(index: usize)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh actually we should probably accept the Gamepad type for consistency with other apis, but I think we should consider making the index private to encourage people to treat Gamepad as an opaque type that must be queried for. And if we don't want that behavior (and want user-specified ids to be a part of our api), then we should consider removing the Gamepad wrapper type.

Also, lets add GamepadLobby::iter() so users can iterate active gamepads.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Made this field private
  • Added contains(gamepad: Gamepad) method
  • Added iter() method
  • Replaced usages with these methods
  • Added register and deregister private methods

/// Container of unique connected [Gamepad]s
///
/// [Gamepad]s are registered and deregistered in [gamepad_connection_system]
pub struct GamepadLobby {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that GamepadLobby isn't the best name for this. Lets use the more descriptive ActiveGamepads unless someone can think of something better.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe just Gamepads

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I like Gamepads more because it is terser

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed it to Gamepads

crates/bevy_input/src/gamepad.rs Outdated Show resolved Hide resolved
crates/bevy_input/src/gamepad.rs Outdated Show resolved Hide resolved
cart and others added 2 commits December 8, 2021 12:10
Co-authored-by: MinerSebas <66798382+MinerSebas@users.noreply.github.com>
Co-authored-by: MinerSebas <66798382+MinerSebas@users.noreply.github.com>
@cart
Copy link
Member

cart commented Dec 8, 2021

bors r+

@bors
Copy link
Contributor

bors bot commented Dec 8, 2021

Canceled.

@cart cart changed the title Added GamepadLobby to library together with connection_system Add Gamepads resource Dec 8, 2021
@cart
Copy link
Member

cart commented Dec 8, 2021

bors r+

bors bot pushed a commit that referenced this pull request Dec 8, 2021
# Objective

Fixes #3245 

## Solution

- Move GamepadLobby to lib
- Add connection_system to InputPlugin
- Updated gamepad_input example


Co-authored-by: CrazyRoka <rokarostuk@gmail.com>
Co-authored-by: Carter Anderson <mcanders1@gmail.com>
@bors
Copy link
Contributor

bors bot commented Dec 8, 2021

Build failed:

@cart
Copy link
Member

cart commented Dec 8, 2021

bors r+

bors bot pushed a commit that referenced this pull request Dec 8, 2021
# Objective

Fixes #3245 

## Solution

- Move GamepadLobby to lib
- Add connection_system to InputPlugin
- Updated gamepad_input example


Co-authored-by: CrazyRoka <rokarostuk@gmail.com>
Co-authored-by: Carter Anderson <mcanders1@gmail.com>
@bors bors bot changed the title Add Gamepads resource [Merged by Bors] - Add Gamepads resource Dec 8, 2021
@bors bors bot closed this Dec 8, 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-Examples An addition or correction to our examples C-Usability A simple quality-of-life change that makes Bevy easier to use 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.

Make GamepadLobby a built-in type
5 participants