print controller input

This commit is contained in:
2019-07-31 19:29:54 +02:00
parent 409bbde0d8
commit 205536ce55
4 changed files with 27 additions and 19 deletions

View File

@@ -67,7 +67,7 @@ struct InputConfigAxis {
}
#[derive(Debug)]
pub struct InputState<'a> {
pub struct InputState {
pub virtual_buttons: HashMap<String, VirtualButton>,
pub virtual_axes: HashMap<String, VirtualAxis>,
pub mouse_delta_x: f64,
@@ -77,12 +77,12 @@ pub struct InputState<'a> {
pressed_mouse_buttons: HashSet<MouseButton>,
analog_wheel_state: f32,
config: InputConfigConfig,
log_config: &'a LogConfig,
log_config: LogConfig,
controller_input: Gilrs,
}
impl <'a> InputState<'a> {
pub fn new(toml_path: &str, log_config: &'a LogConfig) -> InputState<'a> {
impl InputState {
pub fn new(toml_path: &str, log_config: LogConfig) -> InputState {
let config: InputConfig = toml::from_slice(&fs::read(toml_path).expect("Failed to read input config!")).expect("Failed to parse input config!");
let mut state = InputState { virtual_buttons: HashMap::new(), virtual_axes: HashMap::new(),
@@ -170,7 +170,7 @@ impl <'a> InputState<'a> {
pub fn on_window_event(self: &mut Self, event: &Event) {
match event {
Event::WindowEvent { event: WindowEvent::KeyboardInput { device_id, input }, .. } => {
if self.log_config.input {
if self.log_config.input_events {
let mods = mods_to_string(&input.modifiers);
if mods.len() > 0 {
println!("Keyboard {:?} {:?} {:?} + {:?}", device_id, input.state, &mods, input.scancode)
@@ -182,7 +182,7 @@ impl <'a> InputState<'a> {
self.on_keyboard_event(input.state, input.scancode, input.modifiers);
},
Event::WindowEvent { event: WindowEvent::MouseInput { device_id, state, button, modifiers }, .. } => {
if self.log_config.input {
if self.log_config.input_events {
let mods = mods_to_string(&modifiers);
if mods.len() > 0 {
println!("Mouse {:?} {:?} {:?} + {:?}", device_id, state, &mods, button)
@@ -194,7 +194,7 @@ impl <'a> InputState<'a> {
self.on_mouse_event(state, button, modifiers);
},
Event::WindowEvent { event: WindowEvent::MouseWheel { device_id, delta, phase, modifiers }, .. } => {
if self.log_config.input {
if self.log_config.input_events {
let mods = mods_to_string(&modifiers);
if mods.len() > 0 {
println!("Scroll {:?} {:?} {:?} + {:?}", device_id, phase, &mods, delta)
@@ -206,7 +206,7 @@ impl <'a> InputState<'a> {
self.on_mouse_wheel_event(delta, modifiers);
},
Event::DeviceEvent { device_id, event: DeviceEvent::MouseMotion { delta: (delta_x, delta_y) } } => {
if self.log_config.input {
if self.log_config.input_events {
println!("MouseMotion {:?}, ({:?},{:?})", device_id, delta_x, delta_y);
}
self.mouse_delta_x += *delta_x;
@@ -385,14 +385,18 @@ impl <'a> InputState<'a> {
while let Some(event) = self.controller_input.next_event() {
match event.event {
EventType::ButtonPressed(button, _) => {
if self.log_config.input_events { println!("ControllerButton Pressed {:?} {:?}", event.id, button); }
self.input_events.insert(DigitalInputEvent::Pressed(DigitalInput::Controller(ControllerInput { button })));
},
EventType::ButtonRepeated(_, _) => {},
EventType::ButtonReleased(button, _) => {
if self.log_config.input_events { println!("ControllerButton Released {:?} {:?}", event.id, button); }
self.input_events.insert(DigitalInputEvent::Released(DigitalInput::Controller(ControllerInput { button })));
},
EventType::ButtonChanged(_, _, _) => {},
EventType::AxisChanged(_, _, _) => {},
EventType::AxisChanged(axis, value, _) => {
if self.log_config.input_events { println!("ControllerAxis {:?} {:?} {:?}", event.id, axis, value); }
},
EventType::Connected => {},
EventType::Disconnected => {},
EventType::Dropped => {},