Skip to content

Commit

Permalink
Release 0.6 (#263)
Browse files Browse the repository at this point in the history
* Start 0.3 process

* Swap back to a by-value API

* Primitives for working with Axislike inputs

* Split primitives into a dedicated file

* Improve conversion strategy for primitives

* Direction partitionings

* Algebraic operations for Rotation

* Fixed broken tests

* InputAxis -> AxisPair

* AxisPair::new()

* Swap to usize-based hashing to support value-ful actions

* Noted addition of geometric rotation primitives

* Simplify set_state logic

* Correctly initialize ActionState again

* Fix PartialOrd trait for Timing

* Store and set action values

* Use Vec storage internally

Fixes #69.

* Experimentation with action value API

* Revert "Experimentation with action value API"

This reverts commit 76b9d15.

* Don't store action values

* Run examples in CI

Borrowed from https://github.com/bevyengine/bevy/blob/main/.github/workflows/ci.yml

* Remove bevy-specific logic in examples CI

* Don't try to run examples; way too hard

* Use underscores for crate name

* mdlint rules

* Move geometric primitives into leafwing_2d

* Remove dead code in macro

* Underscores in crate name

* Local development

* Relative path for macros crate

* Fix outdated example

* Fix underscores in crate name

* Polish README

* Fix broken doc links

* Simplify CI: no reason to try to run on all platforms

* Refactor `which_pressed` to return a `Vec<VirtualButtonState>`

This is not only cleaner than returning a `HashSet` of indicies, but also opens up the way to add `UserInput` information

* Update `get_clashes` to use a slice instead of a full `Vec`

Clippy recommended this for _performance purposes_

* Run `cargo fmt`

Oops

* Add API method to return which `UserInput` triggered an action

* Move bevy_ui dependency under a feature

* Vendor leafwing_2d orientation code

Should not block a release

* replace_at and clear_at can be used in a device-agnostic way

* Use usize for container sizes

* Fix missing dependencies

* Remove per_mode_cap

* Simplify InputMap API

* Fix docs formatting

* Remove extra pub specifier

* Remove UserInput::Null

* Remove empty_chords test

Doesn't make sense after `UserInput::Null` removal.

* Update RELEASES.md

* Add missing change to RELEASES.md

* Add methods to conveniently iterate over mappings

* Use type alias

* Add InputMap::remove

* Store ClashStrategy in a resource

* Remove clashing input caching

* Enable default for serde

* Fix formatting

* Changed `ActionState.button_states` inserts into direct assignments

* Added helper function for setting `action` as "held"

* Iterate over actions with mapping by default

In previous PR I added a method to iterate over inputs. But I realized
that such iteration should be with action like in normal map.
So I renamed the submitted `iter()` method into `iter_inputs()` and
added `iter()` that iterates over actions with inputs.
I also have to delete `IntoIter` currently because we can't use opaque
type in traits without nightly compiler.
If you know how to implement it properly - I would appreciate your
advice. But for now I removed it.

* Add binding_menu example

* Fix tests (#99)

* Fix which_pressed test

* Remove references to leafwing_2d

* Fix failing doc tests

* Depend on bevy subcrates (#100)

* Fix doc strings

* Use bevy subcrates for faster compiles and easier feature creation

* Replace run_in_state with DisableInput resource (#106)

* Replace run_in_state with DisableInput resource

* Update release notes

* Fix formatting

* Improve system label description

* Apply suggestions

* Systems refactor (#107)

* Refactor plugin systems logic

Insert systems right away instead of putting them into
input_manager_systems system set.

* Rename `InputManagerSystem::Reset` into `InputManagerSystem::Tick`

* Chain add_system_to_stage calls

* Allow use of InputMap and ActionState as resources

* Adding InputResource and supporting system modifications

* Second Attempt

* Cleaning up formatting.

* Adding RELEASES.md notice.

* Update RELEASES.md

New working as provided by alice-i-cecile

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>

* Addressing Shatur's naming Concerns.

* Adding lint exception

* adding clippy:: to too_many_arguments

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>

* Naming nits for systems (#111)

* Tests and refactoring for reasons pressed (#110)

* Move VirtualButtonState and Timing into a more appropriate location

* Use named fields in VirtualButtonState

* Removed poorly motivated ButtonThresholds struct

* reasons_pressed methods

* press and release methods on VirtualButtonState

* VirtualButtonState::tick

* Doc tests for reasons_pressed

* Shorten module names

* Refactor UserInput into its own file

* Fix timing test

* Fix broken doc tests

* ActionState::reset API (#112)

* ActionState::make_held -> ActionState::reset

* Fix rename in doc test

* Fixed misleading merge conflict in RELEASES

* Clean up release notes

* Fix import in doc tests

* More release note polish...

* Fix doc test

* Added example demonstrating how to use reset in system

* Refactor VirtualButtonState (#113)

* Rename VirtualButtonState to ButtonState

* Radically simplify ButtonState

* Re-add reasons_pressed functionality

* Fetch ActionData, not ButtonState

* Re-add Timing functionality

* Consolidate tests

* Updated release notes

* Assorted cleanup

* Fix tests

* Provide functionality to release inputs during mocking (#114)

* Note that mocked inputs will not be automatically released

* Add input releasing to input mocking tools

* Add UserInput::raw_inputs

* Add ActionState::freeze (#115)

* ActionState::freeze and ActionState::unfreeze

* Yeet DisableInput resource

* Fix stray doc test (#116)

* Replace freeze API with improved DisableInput resource (#117)

* Replace freeze API with DisableInput improved resource

ActionState::freeze was introduced to consume actions. But it turns
out not very ergonomic. Also freeze require to spawn an entity or
init the resource should which is not always the case.
In this iteration I used run criteria to make the code nicer.
Also I extended disable_input test to check if global and entity input
is released on disable.

* Use field to control if actions are enabled

* Update RELEASES.md

* Add ActionState::consume (#118)

* Update to Bevy 0.7 (#119)

* Bump dependencies

* New ergonomics!

* Fix typo

* Bump bevy_egui dev-dependency

* Finalize release notes (#120)

* Reduce Bevy dependencies (#126)

* Properly document ToggleActions (#134)

* Fix dead links to ToggleActions

* Add plugin-level documentation to describe how to pause and resume

* Improve plugin-level docs (#137)

* Document the need to specify system ordering

* Document the use of multiple actionlike enums

* Expanded ActionStateDriver docs (#138)

* Don't run CI twice for repo-owned branches (#140)

* Bump LWIM dependency

* Add code snippet to README (#139)

* Remove missed boilerplate from README (#142)

* Update crate name in README (#143)

* Add Bevy Gilrs to Dev Dependency Features (#150)

This way you can run the examples with gamepad support.

* Fix broken duration pressed functionality (#129)

* Improve press_duration example description

* Added integration test for durations

* Test cleanup

* Create seemingly useless test

* Isolate source of problems

* Don't flip the timing unless a state change occurs

* Add bug fix to release notes

* Made duration integration test stricter

* Handle time not having a last update gracefully (#146)

* Identify source(s) of problems

* Improve tricky duration pressed integration test

* Do not advance timing info for consumed actions

* Remove reset_inputs from tests

* Move trivial do_nothing test to top of integration test file

* Remove double updates from duration test

* Improve strategy for computing elapsed time

* Don't sleep in unit tests

* Simplify duration tests

* Start timer at the correct time

* Current duration should be measured from the last frame

* Add missing release note

* Fix CI

* Bump to 0.4 because breaking change needed

Co-authored-by: Aceeri <conmcclusk@gmail.com>

* Reverse order of `InputMap` from `(action, input)` to `(input, action)` (#152)

* Swap order of InputMap methods from (Action, Input) to (Input, Action)

* Update release notes

* Don't duplicate CI checks for Leafwing-Studios PRs (#153)

* Add Support For Gamepad Axes (#151)

* Add Support For Gamepad Axes

* Update Doc Comment

Co-authored-by: Nathan Stocks <cleancut@github.com>

* Demonstrate Button Value in the Analog Stick Demo

* Add Helper Method ActionState::get_value()

* Add Dual Axis Support

* Implement Virtual DPad

* Implement Values and Axis Pairs for Chords

* Address Code Review

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>

* Update README.md and RELEASES.md

* Cargo Format

* Non-Inclusive Comparisons For positive_low/high

* Split Dual Axis Deadzone Into Component Parts

* Apply Updates Suggested in Review

* Apply More Suggestions

* Move VirtualDPad To Its Own Struct

* Apply Updates From Code Review

Co-authored-by: Nathan Stocks <cleancut@github.com>

* Fix Compile Errors

* Fix DPad Clash Detection

* Cargo Format

Co-authored-by: Nathan Stocks <cleancut@github.com>
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>

* Merge changes from main into dev branch (#163)

* Release 0.4 (#141)

* Start 0.3 process

* Swap back to a by-value API

* Primitives for working with Axislike inputs

* Split primitives into a dedicated file

* Improve conversion strategy for primitives

* Direction partitionings

* Algebraic operations for Rotation

* Fixed broken tests

* InputAxis -> AxisPair

* AxisPair::new()

* Swap to usize-based hashing to support value-ful actions

* Noted addition of geometric rotation primitives

* Simplify set_state logic

* Correctly initialize ActionState again

* Fix PartialOrd trait for Timing

* Store and set action values

* Use Vec storage internally

Fixes #69.

* Experimentation with action value API

* Revert "Experimentation with action value API"

This reverts commit 76b9d15.

* Don't store action values

* Run examples in CI

Borrowed from https://github.com/bevyengine/bevy/blob/main/.github/workflows/ci.yml

* Remove bevy-specific logic in examples CI

* Don't try to run examples; way too hard

* Use underscores for crate name

* mdlint rules

* Move geometric primitives into leafwing_2d

* Remove dead code in macro

* Underscores in crate name

* Local development

* Relative path for macros crate

* Fix outdated example

* Fix underscores in crate name

* Polish README

* Fix broken doc links

* Simplify CI: no reason to try to run on all platforms

* Refactor `which_pressed` to return a `Vec<VirtualButtonState>`

This is not only cleaner than returning a `HashSet` of indicies, but also opens up the way to add `UserInput` information

* Update `get_clashes` to use a slice instead of a full `Vec`

Clippy recommended this for _performance purposes_

* Run `cargo fmt`

Oops

* Add API method to return which `UserInput` triggered an action

* Move bevy_ui dependency under a feature

* Vendor leafwing_2d orientation code

Should not block a release

* replace_at and clear_at can be used in a device-agnostic way

* Use usize for container sizes

* Fix missing dependencies

* Remove per_mode_cap

* Simplify InputMap API

* Fix docs formatting

* Remove extra pub specifier

* Remove UserInput::Null

* Remove empty_chords test

Doesn't make sense after `UserInput::Null` removal.

* Update RELEASES.md

* Add missing change to RELEASES.md

* Add methods to conveniently iterate over mappings

* Use type alias

* Add InputMap::remove

* Store ClashStrategy in a resource

* Remove clashing input caching

* Enable default for serde

* Fix formatting

* Changed `ActionState.button_states` inserts into direct assignments

* Added helper function for setting `action` as "held"

* Iterate over actions with mapping by default

In previous PR I added a method to iterate over inputs. But I realized
that such iteration should be with action like in normal map.
So I renamed the submitted `iter()` method into `iter_inputs()` and
added `iter()` that iterates over actions with inputs.
I also have to delete `IntoIter` currently because we can't use opaque
type in traits without nightly compiler.
If you know how to implement it properly - I would appreciate your
advice. But for now I removed it.

* Add binding_menu example

* Fix tests (#99)

* Fix which_pressed test

* Remove references to leafwing_2d

* Fix failing doc tests

* Depend on bevy subcrates (#100)

* Fix doc strings

* Use bevy subcrates for faster compiles and easier feature creation

* Replace run_in_state with DisableInput resource (#106)

* Replace run_in_state with DisableInput resource

* Update release notes

* Fix formatting

* Improve system label description

* Apply suggestions

* Systems refactor (#107)

* Refactor plugin systems logic

Insert systems right away instead of putting them into
input_manager_systems system set.

* Rename `InputManagerSystem::Reset` into `InputManagerSystem::Tick`

* Chain add_system_to_stage calls

* Allow use of InputMap and ActionState as resources

* Adding InputResource and supporting system modifications

* Second Attempt

* Cleaning up formatting.

* Adding RELEASES.md notice.

* Update RELEASES.md

New working as provided by alice-i-cecile

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>

* Addressing Shatur's naming Concerns.

* Adding lint exception

* adding clippy:: to too_many_arguments

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>

* Naming nits for systems (#111)

* Tests and refactoring for reasons pressed (#110)

* Move VirtualButtonState and Timing into a more appropriate location

* Use named fields in VirtualButtonState

* Removed poorly motivated ButtonThresholds struct

* reasons_pressed methods

* press and release methods on VirtualButtonState

* VirtualButtonState::tick

* Doc tests for reasons_pressed

* Shorten module names

* Refactor UserInput into its own file

* Fix timing test

* Fix broken doc tests

* ActionState::reset API (#112)

* ActionState::make_held -> ActionState::reset

* Fix rename in doc test

* Fixed misleading merge conflict in RELEASES

* Clean up release notes

* Fix import in doc tests

* More release note polish...

* Fix doc test

* Added example demonstrating how to use reset in system

* Refactor VirtualButtonState (#113)

* Rename VirtualButtonState to ButtonState

* Radically simplify ButtonState

* Re-add reasons_pressed functionality

* Fetch ActionData, not ButtonState

* Re-add Timing functionality

* Consolidate tests

* Updated release notes

* Assorted cleanup

* Fix tests

* Provide functionality to release inputs during mocking (#114)

* Note that mocked inputs will not be automatically released

* Add input releasing to input mocking tools

* Add UserInput::raw_inputs

* Add ActionState::freeze (#115)

* ActionState::freeze and ActionState::unfreeze

* Yeet DisableInput resource

* Fix stray doc test (#116)

* Replace freeze API with improved DisableInput resource (#117)

* Replace freeze API with DisableInput improved resource

ActionState::freeze was introduced to consume actions. But it turns
out not very ergonomic. Also freeze require to spawn an entity or
init the resource should which is not always the case.
In this iteration I used run criteria to make the code nicer.
Also I extended disable_input test to check if global and entity input
is released on disable.

* Use field to control if actions are enabled

* Update RELEASES.md

* Add ActionState::consume (#118)

* Update to Bevy 0.7 (#119)

* Bump dependencies

* New ergonomics!

* Fix typo

* Bump bevy_egui dev-dependency

* Finalize release notes (#120)

* Reduce Bevy dependencies (#126)

* Properly document ToggleActions (#134)

* Fix dead links to ToggleActions

* Add plugin-level documentation to describe how to pause and resume

* Improve plugin-level docs (#137)

* Document the need to specify system ordering

* Document the use of multiple actionlike enums

* Expanded ActionStateDriver docs (#138)

* Don't run CI twice for repo-owned branches (#140)

* Bump LWIM dependency

* Add code snippet to README (#139)

* Remove missed boilerplate from README (#142)

* Update crate name in README (#143)

* Add Bevy Gilrs to Dev Dependency Features (#150)

This way you can run the examples with gamepad support.

* Fix broken duration pressed functionality (#129)

* Improve press_duration example description

* Added integration test for durations

* Test cleanup

* Create seemingly useless test

* Isolate source of problems

* Don't flip the timing unless a state change occurs

* Add bug fix to release notes

* Made duration integration test stricter

* Handle time not having a last update gracefully (#146)

* Identify source(s) of problems

* Improve tricky duration pressed integration test

* Do not advance timing info for consumed actions

* Remove reset_inputs from tests

* Move trivial do_nothing test to top of integration test file

* Remove double updates from duration test

* Improve strategy for computing elapsed time

* Don't sleep in unit tests

* Simplify duration tests

* Start timer at the correct time

* Current duration should be measured from the last frame

* Add missing release note

* Fix CI

* Bump to 0.4 because breaking change needed

Co-authored-by: Aceeri <conmcclusk@gmail.com>

* Reverse order of `InputMap` from `(action, input)` to `(input, action)` (#152)

* Swap order of InputMap methods from (Action, Input) to (Input, Action)

* Update release notes

Co-authored-by: Rose Peck <olaf223224@gmail.com>
Co-authored-by: Hennadii Chernyshchyk <genaloner@gmail.com>
Co-authored-by: Elfein Landers <patlymlatun@mgail.com>
Co-authored-by: Hans W. Uhlig <huhlig@gmail.com>
Co-authored-by: Christopher Biscardi <chris@christopherbiscardi.com>
Co-authored-by: Zicklag <zicklag@katharostech.com>
Co-authored-by: Aceeri <conmcclusk@gmail.com>

* Hyphens in crate name

* sync up macros dependency with macros crate name (#161)

* sync up macros dependency with macros crate name

* version bump and release notes for 0.4.1

* Update hyphenation of parent crate in docs

* Fix conflict between macro crate name and version (#162)

* Revert "sync up macros dependency with macros crate name (#161)"

This reverts commit ba4e704.

* Swap to underscores in macro crate name only

This matches the published crate name.

* Add release notes

* Bump version of macros crate

* Bump version of main crate

Co-authored-by: Shea Newton <shnewto@gmail.com>

* Bump version numbers

* Fixed release notes

* Specify minor versions

Co-authored-by: Rose Peck <olaf223224@gmail.com>
Co-authored-by: Hennadii Chernyshchyk <genaloner@gmail.com>
Co-authored-by: Elfein Landers <patlymlatun@mgail.com>
Co-authored-by: Hans W. Uhlig <huhlig@gmail.com>
Co-authored-by: Christopher Biscardi <chris@christopherbiscardi.com>
Co-authored-by: Zicklag <zicklag@katharostech.com>
Co-authored-by: Aceeri <conmcclusk@gmail.com>
Co-authored-by: Shea Newton <shnewto@gmail.com>

* Add builder methods for new axislike input types (#165)

* Move VirtualDpad to axislike.rs file

* Work around RA macro import resolution issue

* Add simple builder methods for VirtualDPads

* Move SingleGamepadAxis and DualGamepadAxis to axislike.rs

* Simple builder methods for Single and DualGamepadAxis

* Add builder methods for gamepad analogue sticks

* Update example to use new builders

* Don't store DualGamepadAxis in VirtualDPad

* Silence spurious clippy warning

* Remove reasons_pressed API. (#167)

* Scan all gamepads for inputs if none is registered (#168)

* Remove reasons_pressed API.

* Scan the list of all gamepads if no particular gamepad is registered

* Update examples

* Use same strategies for InputMocking::pressed

* Record FIXME notes

* Search all gamepads if no gamepad is registered

* Remove incorrect Chord logic for axis_pair and input_value

* Use button value in get_input_value as a fallback, rather than 0.0

* Explain weird design choice

* Update docs

* Clippy

* Update to Bevy 0.8-dev (#170)

* Update dependencies to 0.8-dev branch of Bevy

* Fix compile errors

* Use new const Vec2 methods

* Make egui example pass CI

* Align variable naming with bevy_input conventions

* Set axis values when mocking user input (#171)

* Remove resolved FIXME comments

* Allow users to send analog input values

* Clarity rename

* Update doc string to reflect current design

* Fix broken imports (#172)

Thanks merge conflicts :(

* Cleanup old TODO and FIXME comments (#176)

* Remove completed TODO / FIXME comments

* Add Direction::try_new

* Measure rotation counterclockwise from x (#177)

* switch from 'clockwise from midnight' to 'counterclockwise from the positive x axis' for Rotation and Direction

* fix usage

* stop using .normalize(), which can panic

* simplify logic

* remove unused import

* Doc nit

* re-enable all assertions

* add release notes

* clarify why we changed rotation direction

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>

* use Result consistently

* Tweak release notes

* Remove Direction::try_new

Co-authored-by: Nathan Stocks <cleancut@github.com>

* Support mouse wheel inputs (#173)

* Rename SingleGamepadAxis to SingleAxis

* Do not clamp lengths of axis pairs

* Move InputStreams into a dedicated file

UserInput was getting excessively long and InputStreams code is well isolated.

* Add helper methods to construct InputStream types from the World

* Add mouse wheel events to InputStreams

* Generalize GamepadAxisType to AxisType

* Update release notes

* Rename for generality

* Rename AxisPair to DualAxisData

* Store two SingleAxis inside of DualAxis

* Use more descriptive variable names in user_input.rs

* Account for mouse wheel inputs in InputMode conversion

* Yeet InputMode enum

* Variable renaming for generality

* Mock mouse wheel inputs

* Refactor input_value methods on InputStreams

* Take a pair of floats in DualAxisData::new

* Sum mouse wheel events to get input_value

* Add buttonlike MouseWheelDirection InputKind

* Rederive Debug

Fixes #175.

* clippy

* Builder methods for working with mouse wheel inputs

* Add new types to prelude

* Add missing From impls

* Add mouse_wheel example

* Make mouse wheel direction summing less clever

* Actually add code for panning right to example

* Add note about dumb Bevy bug

* Scale 2D cameras correctly :upside_down:

* Fix stated ordering in InputMap docs

* Add tests for working with mouse wheel inputs

* Add DualAxis::from_value helpers

* Add test for raw events

* get_input_value -> input_value

* Add clamped helper methods

* Shorten axis_pair and value method names

* Make CI pass

* Support Single Axis Inputs in Virtual DPads (#180)

* Temporarily Comment Out Bevy Egui

* Make Axis Input Example Slightly More Readable

* Fix Bug in Symmetric Axis Constructor

Axis would always trigger because negative_low was positive.

* Return Axis Pair Results When Action Isn't Pressed

This makes sure that axis_pair() returns `Some` even if the value is
zero because the axis isn't moved.

* Set Dual Axis Value Zero if Not in Trigger Range

* Make Single-Axis Inputs Work in Virtual DPad

This makes sure that SingleAxis inputs will report a value of 0.0 if the
axis value is not withing the triggering zone. This makes it possible to
create a virtual gamepad made up of multiple single-axis inputs on the
same stick.

* Cargo Format

* Add mouse motion support (#186)

* Add MouseMotion events to input streams

* Add discretized MouseMotionDirection buttonlike input support

* Continuous-valued mouse motion inputs

* Doc fixes for AxisData

* Builder methods for Axis types

* Add simple mouse_motion example

* Depend on bevy directly (#187)

This is a) much cleaner and easier to maintain b) makes it easier for others to patch this crate to a specific version and c) slightly more robust to bevy shuffling code around

* Add bevy_asset as a feature for the examples (#190)

* Bump to Bevy 0.8 (#192)

* Bump dependencies

* Re-enable binding_menu example

* Make input stream fields non-optional (#193)

* Add better module-level docs

* Make input streams non-optional

* InputStreams::from_world does not need &mut World

* Satisfy borrow checker in tests

* Fix lifetime of MutableInputStreams -> InputStreams method

* Fix integration test

* Update release notes

* Add mockable_world builder function

* Clean up input mocking code (#194)

* Documentation improvements to input mocking

* (Mostly) implement InputMocking trait for MutableInputStreams

* Use InputStreams::guess_gamepad internally

* Allows conversion by reference from MutableInputStreams

* Add tests for decomposing `UserInput` into raw inputs (#197)

* Documentation improvements to input mocking

* (Mostly) implement InputMocking trait for MutableInputStreams

* Use InputStreams::guess_gamepad internally

* Allows conversion by reference from MutableInputStreams

* Correctly release input

* Swap to a RawInputs struct

* Update docs for UserInput::chord

* Add tests for RawInputs

* Fix Compile Without UI Feature (#198)

* Fix axislike input mocking (kind of) (#200)

* Re-enable tests

* Actually add axislike inputmanagerplugin XD

* Move actionstate init to test setup

* Improve axis-like input mocking tests

* Reorganize MutableInputStreams::send_input

* Actually send discrete mouse motion events

* Add more tests for axislike inputs

* Improve gamepad status handling for axislike gamepad inputs

* Ignore failing tests

* Actually register a gamepad for tests

* Disable tests that are still failing

* Mocking inputs should send raw events (#207)

* Add more fields to mutable input streams

* Rename InputStreams fields for clarity

* Send raw events when doing input mocking

* Don't guess gamepad in send_input_to_gamepad; handled upstream

* Enable fixed gamepad mocking tests

* Always enable bevy_gilrs

* Fix failing tests

* Fix failing gamepad axis tests

* Minor documentation fix, s/pressed/released/ (#206)

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>

* Improve ToggleActions (#228)

* Improve ToggleActions, closes #227

- Make `_phantom` field public and rename into `phantom`.
- Add `ToggleActions::new`.
- Add `ToggleActions::ENABLED` and `ToggleActions::DISABLED`.

* Remove ToggleActions::new

* Add `ActionState::action_data_mut` for retrieving mutable state for an action. (#214)

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>

* Fix clippy warnings to also derive `Eq` (#236)

* Fix clippy warnings to also derive Eq

* Add implementation of Eq for Timing and InputMap to changelog

* Move derive Eq changelog to Usability section

* Run 'cargo check' with no features and default features in CI (#235)

* Run clippy on examples in CI (#234)

* Run clippy on examples in CI

* Fix example lint command

* Change CI workflow to run on ubuntu-latest (#233)

* Change CI workflow to run on ubuntu-latest

* Install required libraries on Linux for CI workflow

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>

* Release inputs when InputMap is removed (#245)

Fixes #244

* Add negative_only and positive_only constructors to SingleAxis (#246)

* Add negative_only and positive_only constructors to SingleAxis

* Update changelog

* Store per-action cooldowns (#253)

* Add very simple cooldowns

* Add cooldowns to ActionState and ActionData

* Add trigger and can_trigger methods to `ActionState`

* Clean up and demo API for ActionState cooldowns

* Update release notes

* Store Cooldowns in a component (#261)

* Store Cooldowns as a component

* Revise RELEASES

* Add simple integration tests

* Actually tick the cooldowns

* Fix tests

* Add cooldown ticking system to plugin

* Fix merge

* Add with_deadzone method (#264)

Authored by @Pulau-Komodo; this is just a rebase

* Add global cooldowns (#262)

* Docs clarity

* Add global cooldowns

* Add tests for GCDs

* More tests

* Fix tests

* Track number of cooldown charges (#265)

* Add cooldown charges

* Remove zero duration cooldown from tests

* Fix bugs

* Fix broken test

* Avoid overflows

* Add direct support for modifier keys (#267)

* Add Modifier type and InputKind variant

* Add convenience method to create modifier + button inputs

* Add InputMap::insert_modified

* Update release notes

* Compile errors

* Add unit tests

* Fix broken doc links

* Fix unit test

Co-authored-by: Rose Peck <olaf223224@gmail.com>
Co-authored-by: Hennadii Chernyshchyk <genaloner@gmail.com>
Co-authored-by: Elfein Landers <patlymlatun@mgail.com>
Co-authored-by: Hans W. Uhlig <huhlig@gmail.com>
Co-authored-by: Christopher Biscardi <chris@christopherbiscardi.com>
Co-authored-by: Zicklag <zicklag@katharostech.com>
Co-authored-by: Aceeri <conmcclusk@gmail.com>
Co-authored-by: Nathan Stocks <cleancut@github.com>
Co-authored-by: Shea Newton <shnewto@gmail.com>
Co-authored-by: Nolan Darilek <nolan@thewordnerd.info>
Co-authored-by: TimJentzsch <tim-jentzsch@gmx.de>
Co-authored-by: Paul Hansen <mail@paul.rs>
Co-authored-by: Rob Parrett <robparrett@gmail.com>
  • Loading branch information
14 people committed Oct 14, 2022
1 parent ef037f9 commit d1afe0b
Show file tree
Hide file tree
Showing 26 changed files with 1,310 additions and 87 deletions.
93 changes: 48 additions & 45 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
toolchain: [stable]
os: [windows-latest]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
Expand All @@ -38,7 +38,7 @@ jobs:
RUSTFLAGS: "-C debuginfo=0 -D warnings"

ci:
runs-on: windows-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
Expand All @@ -55,56 +55,59 @@ jobs:
toolchain: stable
components: rustfmt, clippy
override: true
- name: Install alsa and udev
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev
if: runner.os == 'linux'
- name: CI job
# See tools/ci/src/main.rs for the commands this runs
run: cargo run -p ci

check-markdown-links:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: check dead links
continue-on-error: true
id: run1
uses: gaurav-nelson/github-action-markdown-link-check@9710f0fec812ce0a3b98bef4c9d842fc1f39d976
with:
use-quiet-mode: 'yes'
use-verbose-mode: 'yes'
config-file: '.github/linters/markdown-link-check.json'
- name: Sleep for 30 seconds
if: steps.run1.outcome=='failure'
run: sleep 30s
shell: bash
- name: check dead links (retry)
continue-on-error: true
id: run2
if: steps.run1.outcome=='failure'
uses: gaurav-nelson/github-action-markdown-link-check@9710f0fec812ce0a3b98bef4c9d842fc1f39d976
with:
use-quiet-mode: 'yes'
use-verbose-mode: 'yes'
config-file: '.github/linters/markdown-link-check.json'
- name: Sleep for 30 seconds
if: steps.run2.outcome=='failure'
run: sleep 30s
shell: bash
- name: check dead links (retry 2)
continue-on-error: true
id: run3
if: steps.run2.outcome=='failure'
uses: gaurav-nelson/github-action-markdown-link-check@9710f0fec812ce0a3b98bef4c9d842fc1f39d976
with:
use-quiet-mode: 'yes'
use-verbose-mode: 'yes'
config-file: '.github/linters/markdown-link-check.json'
- name: set the status
if: always()
run: |
if ${{ steps.run1.outcome=='success' || steps.run2.outcome=='success' || steps.run3.outcome=='success' }}; then
echo success
else
exit 1
fi
- uses: actions/checkout@v2
- name: check dead links
continue-on-error: true
id: run1
uses: gaurav-nelson/github-action-markdown-link-check@9710f0fec812ce0a3b98bef4c9d842fc1f39d976
with:
use-quiet-mode: "yes"
use-verbose-mode: "yes"
config-file: ".github/linters/markdown-link-check.json"
- name: Sleep for 30 seconds
if: steps.run1.outcome=='failure'
run: sleep 30s
shell: bash
- name: check dead links (retry)
continue-on-error: true
id: run2
if: steps.run1.outcome=='failure'
uses: gaurav-nelson/github-action-markdown-link-check@9710f0fec812ce0a3b98bef4c9d842fc1f39d976
with:
use-quiet-mode: "yes"
use-verbose-mode: "yes"
config-file: ".github/linters/markdown-link-check.json"
- name: Sleep for 30 seconds
if: steps.run2.outcome=='failure'
run: sleep 30s
shell: bash
- name: check dead links (retry 2)
continue-on-error: true
id: run3
if: steps.run2.outcome=='failure'
uses: gaurav-nelson/github-action-markdown-link-check@9710f0fec812ce0a3b98bef4c9d842fc1f39d976
with:
use-quiet-mode: "yes"
use-verbose-mode: "yes"
config-file: ".github/linters/markdown-link-check.json"
- name: set the status
if: always()
run: |
if ${{ steps.run1.outcome=='success' || steps.run2.outcome=='success' || steps.run3.outcome=='success' }}; then
echo success
else
exit 1
fi
markdownlint:
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "leafwing-input-manager"
name = "leafwing_input_manager"
description = "A powerfully direct stateful input manager for the Bevy game engine."
version = "0.5.2"
version = "0.6.0"
authors = ["Leafwing Studios"]
homepage = "https://leafwing-studios.com/"
repository = "https://github.com/leafwing-studios/leafwing-input-manager"
Expand Down
26 changes: 25 additions & 1 deletion RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# Release Notes

## Version 0.6

### Enhancements

- You can now store `Cooldowns` on a per-action basis.
- This new component / resource is now included in the `InputManagerBundle`
- Set cooldowns for actions using `Cooldowns::set(action, cooldown)` or `Cooldowns::new`.
- Use `Cooldowns::ready` with `Cooldowns::trigger` as part of your action evaluation!
- Cooldowns advance whenever `Cooldowns::tick` is called (this will happen automatically if you add the plugin).
- Added the `Modifier` enum, to ergonomically capture the notion of "either control/alt/shift/windows key".
- The corresponding `InputKind::Modifier` variant was added to match.
- You can conveniently construct these using the `InputKind::modified` or `InputMap::insert_modified` methods.

### Usability

- Implemented `Eq` for `Timing` and `InputMap`.
- Held `ActionState` inputs will now be released when an `InputMap` is removed.
- Improve `ToggleActions`.
- Make `_phantom` field public and rename into `phantom`.
- Add `ToggleActions::ENABLED` and `ToggleActions::DISABLED`.
- Added `SingleAxis::negative_only` and `SingleAxis::positive_only` for triggering separate actions for each direction of an axis.
- `ActionData::action_data` now returns a reference, rather than a clone, for consistency and explicitness
- added `with_deadzone` methods to configure the deadzones for both `SingleAxis` and `DualAxis` inputs

## Version 0.5.2

### Bug fixes
Expand Down Expand Up @@ -53,7 +77,7 @@
- `InputStreams` and `MutableInputStreams` no longer store e.g. `Option<Res<Input<MouseButton>>>`, and instead simply store `Res<Input<MouseButton>>`
- This makes them much easier to work with and dramatically simplifies internal logic.
- `InputStreams::from_world` no longer requires `&mut World`, as it does not require mutable access to any resources.
- Renamed `InputMocking::send_input_to_gamepad` and `InputMocking::release_input_for_gamepad` to `InputMocking::send_input_as_gamepad` and `InputMocking::release_input_as_gamepad`.
- Renamed `InputMocking::send_input_to_gamepad` and `InputMocking::release_input_for_gamepad` to `InputMocking::send_input_as_gamepad` and `InputMocking::send_input_as_gamepad`.
- Added the `guess_gamepad` method to `InputStreams` and `MutableInputStreams`, which attempts to find an appropriate gamepad to use.
- `InputMocking::pressed` and `pressed_for_gamepad` no longer require `&mut self`.
- `UserInput::raw_inputs` now returns a `RawInputs` struct, rather than a tuple struct.
Expand Down
3 changes: 2 additions & 1 deletion examples/arpg_indirection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ fn copy_action_state(
if let Some(&matching_ability) = ability_slot_map.get(&slot) {
// This copies the `ActionData` between the ActionStates,
// including information about how long the buttons have been pressed or released
ability_state.set_action_data(matching_ability, slot_state.action_data(slot));
ability_state
.set_action_data(matching_ability, slot_state.action_data(slot).clone());
}
}
}
Expand Down
1 change: 1 addition & 0 deletions examples/axis_inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ fn spawn_player(mut commands: Commands) {
Action::Rudder,
)
.build(),
..default()
});
}

Expand Down
3 changes: 3 additions & 0 deletions examples/minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ fn spawn_player(mut commands: Commands) {
action_state: ActionState::default(),
// Describes how to convert from player inputs into those actions
input_map: InputMap::new([(KeyCode::Space, Action::Jump)]),
// Any cooling-off period between repeated actions
// By default, there are none.
cooldowns: Cooldowns::default(),
});
}

Expand Down
2 changes: 1 addition & 1 deletion examples/mouse_motion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn setup(mut commands: Commands) {
// Note that you can also use discrete gesture-like motion, via the `MouseMotionDirection` enum
.insert(DualAxis::mouse_motion(), CameraMovement::Pan)
.build(),
action_state: ActionState::default(),
..default()
});

commands.spawn().insert_bundle(SpriteBundle {
Expand Down
2 changes: 1 addition & 1 deletion examples/mouse_wheel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn setup(mut commands: Commands) {
// Or even a continous `DualAxis`!
// .insert(DualAxis::mouse_wheel(), Pan)
.build(),
action_state: ActionState::default(),
..default()
});

commands.spawn().insert_bundle(SpriteBundle {
Expand Down
2 changes: 1 addition & 1 deletion examples/press_duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fn spawn_player(mut commands: Commands) {
velocity: Velocity { x: 0.0 },
input_manager: InputManagerBundle {
input_map: PlayerBundle::default_input_map(),
action_state: ActionState::default(),
..default()
},
sprite: SpriteBundle {
transform: Transform {
Expand Down
2 changes: 1 addition & 1 deletion examples/send_actions_over_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ fn spawn_player(mut commands: Commands) {
input_map: InputMap::new([(W, MoveLeft), (D, MoveRight), (Space, Jump)])
.insert(MouseButton::Left, Shoot)
.build(),
action_state: ActionState::default(),
..default()
})
// This identifier must match on both the client and server
// and be unique between players
Expand Down
2 changes: 1 addition & 1 deletion examples/single_player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fn spawn_player(mut commands: Commands) {
player: Player,
input_manager: InputManagerBundle {
input_map: PlayerBundle::default_input_map(),
action_state: ActionState::default(),
..default()
},
});
}
Expand Down
2 changes: 1 addition & 1 deletion examples/virtual_dpad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ fn spawn_player(mut commands: Commands) {
.insert(Player)
.insert_bundle(InputManagerBundle::<Action> {
// Stores "which actions are currently activated"
action_state: ActionState::default(),
// Map some arbitrary keys into a virtual direction pad that triggers our move action
input_map: InputMap::new([(
VirtualDPad {
Expand All @@ -40,6 +39,7 @@ fn spawn_player(mut commands: Commands) {
Action::Move,
)])
.build(),
..default()
});
}

Expand Down
38 changes: 32 additions & 6 deletions src/action_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub struct ActionState<A: Actionlike> {
/// The [`ActionData`] of each action
///
/// The position in this vector corresponds to [`Actionlike::index`].
pub action_data: Vec<ActionData>,
action_data: Vec<ActionData>,
_phantom: PhantomData<A>,
}

Expand Down Expand Up @@ -160,12 +160,12 @@ impl<A: Actionlike> ActionState<A> {
self.action_data.iter_mut().for_each(|ad| {
// Durations should not advance while actions are consumed
if !ad.consumed {
ad.timing.tick(current_instant, previous_instant)
ad.timing.tick(current_instant, previous_instant);
}
});
}

/// Gets a copy of the [`ActionData`] of the corresponding `action`
/// A reference to the [`ActionData`] of the corresponding `action`
///
/// Generally, it'll be clearer to call `pressed` or so on directly on the [`ActionState`].
/// However, accessing the raw data directly allows you to examine detailed metadata holistically.
Expand All @@ -186,8 +186,34 @@ impl<A: Actionlike> ActionState<A> {
/// ```
#[inline]
#[must_use]
pub fn action_data(&self, action: A) -> ActionData {
self.action_data[action.index()].clone()
pub fn action_data(&self, action: A) -> &ActionData {
&self.action_data[action.index()]
}

/// A mutable reference of the [`ActionData`] of the corresponding `action`
///
/// Generally, it'll be clearer to call `pressed` or so on directly on the [`ActionState`].
/// However, accessing the raw data directly allows you to examine detailed metadata holistically.
///
/// # Example
/// ```rust
/// use leafwing_input_manager::prelude::*;
///
/// #[derive(Actionlike, Clone, Copy, PartialEq, Eq, Debug)]
/// enum Action {
/// Run,
/// Jump,
/// }
/// let mut action_state = ActionState::<Action>::default();
/// let mut run_data = action_state.action_data_mut(Action::Run);
/// run_data.axis_pair = None;
///
/// dbg!(run_data);
/// ```
#[inline]
#[must_use]
pub fn action_data_mut(&mut self, action: A) -> &mut ActionData {
&mut self.action_data[action.index()]
}

/// Get the value associated with the corresponding `action`
Expand Down Expand Up @@ -280,7 +306,7 @@ impl<A: Actionlike> ActionState<A> {
///
/// // And transfer it to the actual ability that we care about
/// // without losing timing information
/// action_state.set_action_data(Action::Run, slot_1_state);
/// action_state.set_action_data(Action::Run, slot_1_state.clone());
/// ```
#[inline]
pub fn set_action_data(&mut self, action: A, data: ActionData) {
Expand Down
40 changes: 40 additions & 0 deletions src/axislike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,38 @@ impl SingleAxis {
value: None,
}
}

/// Creates a [`SingleAxis`] with the `axis_type` and `negative_low` set to `threshold`.
///
/// Positive values will not trigger the input.
pub fn negative_only(axis_type: impl Into<AxisType>, threshold: f32) -> SingleAxis {
SingleAxis {
axis_type: axis_type.into(),
negative_low: threshold,
positive_low: f32::MAX,
value: None,
}
}

/// Creates a [`SingleAxis`] with the `axis_type` and `positive_low` set to `threshold`.
///
/// Negative values will not trigger the input.
pub fn positive_only(axis_type: impl Into<AxisType>, threshold: f32) -> SingleAxis {
SingleAxis {
axis_type: axis_type.into(),
negative_low: f32::MIN,
positive_low: threshold,
value: None,
}
}

/// Returns this [`SingleAxis`] with the deadzone set to the specified value
#[must_use]
pub fn with_deadzone(mut self, deadzone: f32) -> SingleAxis {
self.negative_low = deadzone;
self.positive_low = deadzone;
self
}
}

impl PartialEq for SingleAxis {
Expand Down Expand Up @@ -208,6 +240,14 @@ impl DualAxis {
y: SingleAxis::mouse_motion_y(),
}
}

/// Returns this [`DualAxis`] with the deadzone set to the specified value
#[must_use]
pub fn with_deadzone(mut self, deadzone: f32) -> DualAxis {
self.x = self.x.with_deadzone(deadzone);
self.y = self.y.with_deadzone(deadzone);
self
}
}

#[allow(clippy::doc_markdown)] // False alarm because it thinks DPad is an un-quoted item
Expand Down
2 changes: 2 additions & 0 deletions src/clashing_inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ fn resolve_clash<A: Actionlike>(
}
}

println!("real clash");

// There's a real clash; resolve it according to the `clash_strategy`
match clash_strategy {
// Do nothing
Expand Down
Loading

0 comments on commit d1afe0b

Please sign in to comment.