Input log settings

This commit is contained in:
2020-11-29 22:02:49 +01:00
parent 62ec222749
commit 0edd6b6411
4 changed files with 50 additions and 24 deletions

View File

@@ -1,12 +1,18 @@
use serde_derive::{Serialize, Deserialize};
use toml;
use std::fs;
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
pub struct LogConfigInput {
pub mouse_motion: bool,
pub buttons: bool,
pub missing_bindings: bool
}
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
pub struct LogConfig {
pub input_events: bool,
pub vulkan_validation_layers: bool,
pub mesh_load_info: bool,
pub input: LogConfigInput
}
impl LogConfig {

View File

@@ -191,19 +191,19 @@ impl InputState {
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_events {
if self.log_config.input.buttons {
let mods = mods_to_string(&KeyboardModifierState::from_deprecated_state(&input.modifiers));
if mods.len() > 0 {
println!("Keyboard {:?} {:?} {:?} + {:?}", device_id, input.state, &mods, input.virtual_keycode)
println!("Keyboard {:?} {:?} {:?} + {:?} {:?}", device_id, input.state, &mods, input.virtual_keycode, input.scancode)
} else {
println!("Keyboard {:?} {:?} {:?}", device_id, input.state, input.virtual_keycode)
println!("Keyboard {:?} {:?} {:?} {:?}", device_id, input.state, input.virtual_keycode, input.scancode)
}
}
self.on_keyboard_event(input.state, input.scancode, KeyboardModifierState::from_deprecated_state(&input.modifiers));
},
Event::WindowEvent { event: WindowEvent::MouseInput { device_id, state, button, modifiers }, .. } => {
if self.log_config.input_events {
if self.log_config.input.buttons {
let mods = mods_to_string(&KeyboardModifierState::from_deprecated_state(&modifiers));
if mods.len() > 0 {
println!("Mouse {:?} {:?} {:?} + {:?}", device_id, state, &mods, button)
@@ -215,7 +215,7 @@ impl InputState {
self.on_mouse_event(state, button, &KeyboardModifierState::from_deprecated_state(&modifiers));
},
Event::WindowEvent { event: WindowEvent::MouseWheel { device_id, delta, phase, modifiers }, .. } => {
if self.log_config.input_events {
if self.log_config.input.buttons {
let mods = mods_to_string(&KeyboardModifierState::from_deprecated_state(&modifiers));
if mods.len() > 0 {
println!("Scroll {:?} {:?} {:?} + {:?}", device_id, phase, &mods, delta)
@@ -227,7 +227,7 @@ impl InputState {
self.on_mouse_wheel_event(delta, &KeyboardModifierState::from_deprecated_state(&modifiers));
},
Event::DeviceEvent { device_id, event: DeviceEvent::MouseMotion { delta: (delta_x, delta_y) } } => {
if self.log_config.input_events {
if self.log_config.input.mouse_motion {
println!("MouseMotion {:?}, ({:?},{:?})", device_id, delta_x, delta_y);
}
self.mouse_delta_x += *delta_x;
@@ -243,7 +243,9 @@ impl InputState {
virtual_button.digital_inputs.iter().any(|vi| self.digital_input_pressed(vi))
}
None => {
assert!(false, format!("Button {:?} not found!", button_code));
if self.log_config.input.buttons {
println!("Button {:?} not found!", button_code);
}
false
}
}
@@ -261,7 +263,9 @@ impl InputState {
})
}
None => {
assert!(false, format!("Button {:?} not found!", button_code));
if self.log_config.input.missing_bindings {
println!("Button {:?} not found!", button_code);
}
false
}
}
@@ -279,7 +283,9 @@ impl InputState {
})
}
None => {
assert!(false, format!("Button {:?} not found!", button_code));
if self.log_config.input.missing_bindings {
println!("Button {:?} not found!", button_code);
}
false
}
}
@@ -313,7 +319,9 @@ impl InputState {
}
}).fold(0.0, fold_axis_value)
} else {
assert!(false, format!("Axis {:?} not found!", axis_code));
if self.log_config.input.missing_bindings {
println!("Axis {:?} not found!", axis_code);
}
0.0
}
}
@@ -407,17 +415,17 @@ impl InputState {
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); }
if self.log_config.input.buttons { 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); }
if self.log_config.input.buttons { println!("ControllerButton Released {:?} {:?}", event.id, button); }
self.input_events.insert(DigitalInputEvent::Released(DigitalInput::Controller(ControllerInput { button })));
},
EventType::ButtonChanged(_, _, _) => {},
EventType::AxisChanged(axis, value, _) => {
if self.log_config.input_events { println!("ControllerAxis {:?} {:?} {:?}", event.id, axis, value); }
if self.log_config.input.buttons { println!("ControllerAxis {:?} {:?} {:?}", event.id, axis, value); }
},
EventType::Connected => {},
EventType::Disconnected => {},