bevy_controls 1.0.0

Bevy controls library
Documentation
# BEVY CONTROLS

Bevy library for managing control and input mappings. This library abstracts different controls into different contexts where they are active, this allows for an easy check if controls are actually conflicting or just use the same keybind in different situations. The reading of controls also works in the FixedUpdate loop, they will keep their states.

## How to use

You will need to provide your own Context and Actions types for the plugin:

```rust
// The context has to implement PartialEq and States.
#[derive(Debug, Clone, Eq, PartialEq, Hash, Default, States, Reflect)]
enum ControlContext {
    #[default]
    MainMenu,
    Game,
    OpenInventory,
    Paused,
}

// The action has to implement PartialEq
#[derive(Debug, Clone, Copy, PartialEq, Eq, Reflect)]
enum ControlAction {
    Test1,
    TestAnalog1,
    TestMovementX,
    TestMovementY,
}

fn main() {
    App::new()
        // You can register the types for the Button and Analog controls to analyze them in the inspector.
        .register_type::<ButtonControl<ControlContext, ControlAction>>()
        .register_type::<AnalogControl<ControlContext, ControlAction>>()
        .add_plugins((
            DefaultPlugins,
            EguiPlugin::default(),
            WorldInspectorPlugin::new(),
            // Register the controls plugin
            ControlsPlugin::<ControlContext, ControlAction>::default(),
        ))
        .add_systems(Startup, setup)
        .add_systems(Update, (update_state, update))
        .run();
}

fn setup(mut commands: Commands) {
    commands.spawn(Camera2d);

    // Spawn a new control like this:
    // The plugin will handle disabling and enabling it when you change the Context.
    commands.spawn((
        Name::new("Test1 Control"),
        ButtonControl::new(
            ControlAction::Test1,
            vec![ControlContext::MainMenu],
            vec![
                Buttons::Keyboard(KeyCode::Enter),
                Buttons::Mouse(MouseButton::Left),
                Buttons::Gamepad(GamepadButton::North),
            ],
        ),
    ));
}

fn update(
    // Use this exact query to make use of the trait methods.
    mut controls: Query<&mut ButtonControl<ControlContext, ControlAction>>,
) {
    // One line to check if the control was pressed.
    if controls.action_just_pressed(ControlAction::Test1) {
        info!("Executed TEST Action!");
    }
}
```