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();
assert_eq!(map.resolve(InputAction::Jump, &input, None), 0.0);
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");
}