Input log settings
This commit is contained in:
@@ -12,29 +12,37 @@ name = "print_framerate"
|
||||
scan_code = 33
|
||||
|
||||
[[button]]
|
||||
name = "w"
|
||||
name = "button_forward"
|
||||
scan_code = 17
|
||||
|
||||
[[button]]
|
||||
name = "s"
|
||||
name = "button_backward"
|
||||
scan_code = 31
|
||||
|
||||
[[button]]
|
||||
name = "a"
|
||||
name = "button_left"
|
||||
scan_code = 30
|
||||
|
||||
[[button]]
|
||||
name = "d"
|
||||
name = "button_right"
|
||||
scan_code = 32
|
||||
|
||||
[[button]]
|
||||
name = "test"
|
||||
scan_code = 20
|
||||
|
||||
[[button]]
|
||||
name = "quicksave"
|
||||
scan_code = 63
|
||||
|
||||
[[button]]
|
||||
name = "quickload"
|
||||
scan_code = 64
|
||||
|
||||
[[axis]]
|
||||
name = "move_forward"
|
||||
positive_button = "w"
|
||||
negative_button = "s"
|
||||
positive_button = "button_forward"
|
||||
negative_button = "button_backward"
|
||||
|
||||
[[axis]]
|
||||
name = "move_forward"
|
||||
@@ -46,8 +54,8 @@ controller_axis = "LeftStickY"
|
||||
|
||||
[[axis]]
|
||||
name = "move_sideways"
|
||||
positive_button = "d"
|
||||
negative_button = "a"
|
||||
positive_button = "button_right"
|
||||
negative_button = "button_left"
|
||||
|
||||
[[axis]]
|
||||
name = "move_sideways"
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
input_events = false
|
||||
vulkan_validation_layers = true
|
||||
mesh_load_info = true
|
||||
|
||||
[input]
|
||||
mouse_motion = false
|
||||
buttons = false
|
||||
missing_bindings = true
|
||||
@@ -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 {
|
||||
|
||||
34
src/input.rs
34
src/input.rs
@@ -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 => {},
|
||||
|
||||
Reference in New Issue
Block a user