reaction 0.2.0

Universal low-latency input handling for game engines
Documentation
use reaction::mapping::action::InputAction;
use reaction::mapping::binding::{BindingConfig, InputBinding};
use reaction::mapping::resolver::InputMap;
use reaction::prelude::*;

fn main() {
    // 1. Define bindings
    let mut map = InputMap::new();

    // Bind Space AND Gamepad 'A' to Jump
    map.bind(
        InputAction::Jump,
        BindingConfig::new(InputBinding::Key(KeyCode::Space)),
    )
    .unwrap();
    map.bind(
        InputAction::Jump,
        BindingConfig::new(InputBinding::GamepadButton(GamepadButton::A)),
    )
    .unwrap();

    // Bind W/S to MoveY (Axis)
    map.bind(
        InputAction::MoveY,
        BindingConfig::new(InputBinding::Key(KeyCode::KeyW)),
    )
    .unwrap();
    map.bind(
        InputAction::MoveY,
        BindingConfig::new(InputBinding::Key(KeyCode::KeyS))
            .with_scale(-1.0)
            .unwrap(),
    )
    .unwrap();

    // 2. Simulate Input
    let mut input = AdvancedInputState::new();

    println!("Frame 1: Pressing Space");
    input.keyboard.press(KeyCode::Space, 0.0, 1);

    if map.is_active(InputAction::Jump, &input, None, 0.5) {
        println!(" -> Jump Action Triggered!");
    } else {
        println!(" -> Jump NOT Triggered");
    }

    println!("Frame 2: Pressing S (Backward)");
    input.keyboard.press(KeyCode::KeyS, 0.0, 2);

    let move_y = map.resolve(InputAction::MoveY, &input, None);
    println!(" -> MoveY Value: {}", move_y);

    if move_y < -0.1 {
        println!(" -> Walking Backward");
    }
}