Skip to main content

Crate inlet

Crate inlet 

Source
Expand description

Input to Action Binding library for Bevy Game Engine.

§Features

  • Maps Actions to input bindings
  • Uses bevy_input internally, supports Keyboard, Gamepad, and Mouse.
  • Can produce Message for common input events.
  • InputBinding lets you bind any axis or button to any axis or button like input.
    • ActionBinding has internal states to best represent button like behavior: JustPressed, Pressed, JustReleased, Released. Can also be used as digital (-1, 0, 1) axis.
    • ValueBinding can return a value (-1.0 to 1.0) from any axis or set of buttons. Can have a stack of generic functions that modify the output. Can be used as a button, by default it is assumed any non-zero value is pressed, but modifiers can enable you to control this behavior more finely.
    • DualValueBinding internally behaves as if it is just 2 ValueBinding’s.
  • ButtonChord (multiple buttons at once) with configurable settings for resolving clashing inputs.
  • ButtonCombo (multiple sequentially pressed buttons). Think GTA cheats but without incorrect buttons interrupting it.

§Usage

§Binding Types to be aware of

§Poll Only

see examples/poll-only.rs for code. below are the sets required for setups without using Message.

  • Create a list of input bindings to be used as a key to register bindings and retrieve values. This type MUST implement Hash + PartialEq + Clone + Eq.

  • Create a Bindings component and add it to your entity.

InputBindingsSimple is just a type definition that fills in the message type with a placeholder for when you don’t want to deal with both generic types required for InputBindings.

InputManagementPluginSimple is just a type definition that fills in the message type with a placeholder type for when you don’t want to deal with both generic types required for InputManagementPlugin.

§Message Based

see examples/events.rs for code. below are the sets required for setups using Message triggered by inputs.

  • Create a list of input bindings to be used as a key to register bindings and retrieve values. This type MUST implement Hash + PartialEq + Eq + Clone

  • Also create a type that implements Message

You can make only 1 type that gets used for both if you want. This example separates them simply to show they can be separate types for cases where you are mixing message-based and polling-based bindings.

  • Create a Bindings component and add it to your entity.

  • Make a system that uses the values from bindings

you can also use polling in this system or other systems if you would like.

§ClashSettings

If you like ButtonChords and have opinions about how inputs that clash should behave: you can configure how that happens.

§Resource

You can spawn a ClashSettings resource (preferably on start up) that all new InputHandler will use. The system that updates bindings will automatically insert InputHandler on entities that have an InputBindings attached to them, acting as a default.

§Component

When you insert ClashSettings as a component on an entity that also has an attached InputBindings the settings will update and all current input states will reset. This means you can allow player to configure this on a per-player basis.

Modules§

axis
Axis Like related types.
button
Button Like related types.
manager
InputHandler related types.

Structs§

InputBindings
Map actions K to an InputBinding<T> where T is a Message. Also tracks the assigned Gamepads.
InputManagementPlugin
Plugin required for InputBindings to function.
SimpleMessage
Simple Message type used by InputManagementPluginSimple.

Enums§

BevyAxisKind
A enum of all supported bevy_input types that can be used as axis-like bindings.
BevyButtonKind
A enum of all supported bevy_input types that can be used as button-like bindings.
BevyInputKind
A enum of all supported bevy_input types that can be used as bindings.
InputBinding
Generic binding for an input.
InputValue
A value from any input.

Traits§

BindEvent
inlet trait for describing Message events, currently only requires Message to be auto-implemented. This type only exists to make it easier for me if a add requirements later.

Functions§

pressed_to_value
Default logic for converting a button press to axis value.
value_to_press
Default logic for converting a axis value to a button press.

Type Aliases§

InputBindingsSimple
Map actions K to an InputBinding<T> without a custom Message type. Also tracks the assigned Gamepads.
InputManagementPluginSimple
InputManagementPlugin where the Message type is already filled with a placeholder for cases where the input manager will not be emitting input events for SimpleMessage is good enough for you.