$ show simgine/bevy_enhanced_input
This repository is the `bevy_enhanced_input` library, a fully‑featured, observer‑based input management system for the Bevy game engine, inspired by Unreal Engine's Enhanced Input. It provides a component‑driven ECS architecture where actions, bindings, input conditions, and modifiers are all first‑class Bevy components or relationships. The system supports context layering (priorities, activity states), state synchronization, mocking for tests/cutscenes, and a built‑in preset system for common input patterns (e.g., WASD, gamepad sticks). At its core, the library defines the `InputAction` derive macro, the `InputCondition` and `InputModifier` traits, and an evaluation pipeline that runs during `PreUpdate`. Input reading is handled via a dedicated `InputReader` system parameter that also manages input consumption and ignoring. The library is `no_std` compatible and supports reflection and serialization via feature flags. The code is well‑structured with heavy use of Bevy's observer and relationship APIs, and includes extensive integration tests and a comprehensive set of examples ranging from basic action management to rebindable keybinding menus with persistence.
The LLM identified 3 files worth highlighting for reuse:
Implements a generic combo condition that triggers an action only when a sequence of sub‑actions is triggered in order within a configurable timeout. Supports cancellation on any step timeout or out‑of‑order press, and fires on completion with the final action's value. The implementation uses a multi‑step state machine with per‑step timeout tracking and handles edge cases like action removal during a combo. It is reusable as a standalone input pattern for any action type (Bool, 1D, 2D, 3D) and demonstrates careful handling of ECS lifetimes and observer removal.
Provides a modifier that reorders the axes of an `ActionValue` (Bool, 1D, 2D, or 3D) according to a user‑defined permutation. The implementation handles all 24 possible permutations for 3D (and their 2D/1D counterparts) via a compact set of permutation constants, avoiding branching or runtime allocation. It also supports negation via a separate bitflag and works correctly with axis‑limited action values (e.g., discarding extra components). This is a clean, reusable component for any game that needs to remap input axes (e.g., swapping X and Y, negating Z) and can be extracted with minimal dependency on the rest of the system.
Implements the `Cardinal` preset, which spawns four directional `BindingOf` entities (Up, Down, Left, Right) each with multiple input bindings (keyboard keys or gamepad axis directions) and a `ModifierBundle` for applying modifiers to all bindings. The preset implements `SpawnableList<BindingOf>` and the `WithBundle` trait, making it composable and reusable in any context. It reduces boilerplate for common 4‑direction input setups and demonstrates a clean pattern for creating reusable, parameterized input presets that can be extended to other preset types.