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::*;

#[test]
fn test_binding_resolution() {
    let mut map = InputMap::new();
    map.bind(
        InputAction::Jump,
        BindingConfig::new(InputBinding::Key(KeyCode::Space)),
    )
    .unwrap();

    let mut input = AdvancedInputState::new();

    // Not pressed
    assert_eq!(map.resolve(InputAction::Jump, &input, None), 0.0);

    // Pressed
    input.keyboard.press(KeyCode::Space, 0.0, 1);
    assert_eq!(map.resolve(InputAction::Jump, &input, None), 1.0);
    assert!(map.is_active(InputAction::Jump, &input, None, 0.5));
}

#[test]
fn test_axis_scale() {
    let mut map = InputMap::new();
    map.bind(
        InputAction::MoveX,
        BindingConfig::new(InputBinding::Key(KeyCode::KeyA))
            .with_scale(-1.0)
            .unwrap(),
    )
    .unwrap();

    let mut input = AdvancedInputState::new();
    input.keyboard.press(KeyCode::KeyA, 0.0, 1);

    assert_eq!(map.resolve(InputAction::MoveX, &input, None), -1.0);
}

#[cfg(feature = "config-files")]
#[test]
fn test_yaml_load() {
    let yaml = "
bindings:
  Jump:
    - input: !Key Space
";
    use reaction::mapping::loader::load_from_yaml;

    let map = load_from_yaml(yaml).expect("Failed to load YAML");
    // Verify binding exists (indirectly via resolve, or just successful load)
    // To verify deeply we'd need to inspect internals or query against an input state
}