A simple but robust input-action manager for Bevy: intended to be useful both as a plugin and a helpful library.
Inputs from various input sources (keyboard, mouse and gamepad) are collected into a common ActionState
on your player entity,
which can be conveniently used in your game logic.
The mapping between inputs and actions is many-to-many, and easily configured and extended with the InputMap
components on your player entity.
A single action can be triggered by multiple inputs (or set directly by UI elements or gameplay logic),
and a single input can result in multiple actions being triggered, which can be handled contextually.
This library seamlessly supports both single-player and local multiplayer games!
Simply add the InputManagerBundle
to each controllable entity, and customize the InputMap
appropriately.
Of particular note: this plugin allows users to configure which state (i.e. GameState::Playing
) it runs in.
No more characters wandering around while your menu is open!
InputMap
component
Keybindings<KeyCode>
, Keybindings<Gamepad>
headachesActionState
component
input_map.insert(Action::Jump, KeyCode::Space)
XOR input_map.insert(Action::Jump, C)
? Why not both?input_map.insert_chord(Action::Console, [KeyCode::LCtrl, KeyCode::Shift, KeyCode::C])
#![forbid(missing_docs)]
Button
enum only includes KeyCode
, MouseButton
and GamepadButtonType
.
bevy::input::Input
ActionState
are pub
: it's designed to be hooked into and extended.Gamepads
resource and use InputMap::set_gamepad
.leafwing-input-manager
to your Cargo.toml
.Actionlike
trait for it.InputManagerPlugin
to your App
.InputManagerBundle
to your player entity (or entities!).InputMap
component on your player entity.ActionState
component on your player entity to check the collected input state!Use cargo run
.
This repo is set up to always build with full optimizations, so there's no need for a --release
flag in most cases.
Dynamic linking is enabled to ensure build times stay snappy.
To run an example, use cargo run --example_name
, where example_name
is the file name of the example without the .rs
extension.
This repository is open to community contributions! There are a few options if you'd like to help:
Any contributions made are provided under the license(s) listed in this repo at the time of their contribution, and do not require separate attribution.
#
to hide setup code from the doc tests, but use this sparingly.#[cfg(test)]
on the test module to ignore it during builds, and #[test]
on the test functions to ensure they are run.tests
folder, importing functions from lib.rs
.Use cargo test
to run all tests.
The CI will:
cargo fmt
.clippy
lints pass.Check this locally with:
cargo run -p ci
cargo test --workspace
To manually rerun CI:
Actions
tab.Documentation is handled with standard Rust doc strings.
Use cargo doc --open
to build and then open the docs locally.