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

feat: add controller input extensions #3

Merged
merged 8 commits into from
Apr 6, 2024

Conversation

wlsnmrk
Copy link
Contributor

@wlsnmrk wlsnmrk commented Mar 27, 2024

(Edited to more accurately describe the PR after a substantial rework; see comment below.)

This PR adds extension methods to simulate controller button and analog-axis input by firing InputEventJoypadButton and InputEventJoypadMotion. This behavior is analogous to existing behavior for keyboard- and mouse-input simulation.

Simulation of controller input by way of mapped actions is left to the existing action-input simulation code.

This PR also:

  • Provides a workaround, for actions in general, for a possible Godot bug (which has been reported and a fix submitted). The workaround ensures that input strength values are clamped between 0 and 1.
  • Renames the existing *ControlExtensions classes to *InputExtensions (for improved clarity and to avoid ControllerControlExtensions).
  • Bumps the test Godot project to v4.2 and adds a setting to name new scene files using PascalCase (as all existing scenes are).
  • Updates editorconfig to use LF as the default line ending (easing development on Windows). Some file types (e.g., .bat, .cmd) may override this setting.
  • Adds tests for the new controller-input extensions.
  • Updates the README to describe the new controller-input extensions.

The new controller-input methods are extensions on Node (as are the keyboard-input extensions) and are:

  • void PressJoypadButton
  • void ReleaseJoypadButton
  • void TapJoypadButton
  • async Task HoldJoypadButtonFor
  • void MoveJoypadAxisTo
  • void ReleaseJoypadAxis
  • async Task HoldJoypadAxisFor

The "Joypad" naming convention mirrors the names of the associated Godot events.


BREAKING: Classes containing input extension methods have been renamed, so any code that calls them directly (e.g., ActionsControlExtensions.StartAction(myNode, "my_action") instead of the more idiomatic myNode.StartAction("my_action")) will break with this change.

@wlsnmrk wlsnmrk marked this pull request as draft March 27, 2024 22:20
Copy link
Member

@jolexxa jolexxa left a comment

Choose a reason for hiding this comment

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

This looks good to me 😄

wlsnmrk added 3 commits April 3, 2024 12:38
Changed names for clarity and in prep for controller input:
- KeyboardControlExtensions -> KeyboardInputExtensions
- MouseControlExtensions -> MouseInputExtensions
- ActionsControlExtensions -> ActionsInputExtensions

BREAKING: Changed class names; see above
@wlsnmrk wlsnmrk force-pushed the controller-input-extensions branch from ef550f2 to 8c82e6b Compare April 3, 2024 17:17
@wlsnmrk wlsnmrk changed the title feat: add controller analog-axis input extensions feat: add controller input extensions Apr 3, 2024
@wlsnmrk
Copy link
Contributor Author

wlsnmrk commented Apr 3, 2024

Reworked to provide controller-input event simulation. Action-based controller input simulation (for use with Input.GetActionStrength(), Input.GetAxis(), and Input.GetVector()) can still be accomplished with the existing action-input extensions. Convenience methods to provide controller semantics for action inputs, as originally proposed, could be added later if necessary.

Also squashed most commits to make the git history more readable.

@wlsnmrk wlsnmrk marked this pull request as ready for review April 3, 2024 17:36
@wlsnmrk wlsnmrk marked this pull request as draft April 3, 2024 18:50
wlsnmrk added 5 commits April 3, 2024 15:21
Added a new class with extension methods for simulating input from
game controllers. Extension methods fire input events, analogous
to keyboard- and mouse-input extensions. Action-based controller
inputs can be simulated with existing action-input extensions.
Renamed:
- ActionsControlExtensionsTests -> ActionsInputExtensionsTests
to match new naming scheme for input extension classes.
Improved similarity of formatting for XML docs on input-extension
classes and methods.
* Provided section on extension methods to describe event-based input
  simulation
* Provided pointer to action-simulation section for simulating
  controller actions
Updated editorconfig to use LF for all file types unless overridden
(e.g., for bat/cmd files).
@wlsnmrk wlsnmrk force-pushed the controller-input-extensions branch from 8c82e6b to e01444d Compare April 3, 2024 19:22
@wlsnmrk wlsnmrk marked this pull request as ready for review April 3, 2024 19:24
Copy link
Member

@jolexxa jolexxa left a comment

Choose a reason for hiding this comment

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

Thank you so much for doing this 🙌

@jolexxa jolexxa merged commit a2efb65 into chickensoft-games:main Apr 6, 2024
1 check passed
@wlsnmrk wlsnmrk deleted the controller-input-extensions branch April 24, 2024 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants