use reaction::mapping::action::InputAction;
use reaction::mapping::binding::{BindingConfig, InputBinding};
use reaction::mapping::resolver::InputMap;
use reaction::prelude::*;
fn main() {
let mut map = InputMap::new();
map.bind(
InputAction::Jump,
BindingConfig::new(InputBinding::Key(KeyCode::Space)),
)
.unwrap();
map.bind(
InputAction::Jump,
BindingConfig::new(InputBinding::GamepadButton(GamepadButton::A)),
)
.unwrap();
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();
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");
}
}