Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Shute052 committed Feb 5, 2024
1 parent 655a7f6 commit 8c28761
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 49 deletions.
3 changes: 1 addition & 2 deletions src/input_streams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ impl<'a> InputStreams<'a> {
.iter()
.map(|wheel| Vec2::new(wheel.x, wheel.y))
.sum();
let movement: f32 = match axis_type {
let movement = match axis_type {
MouseWheelAxisType::X => x,
MouseWheelAxisType::Y => y,
};
Expand Down Expand Up @@ -327,7 +327,6 @@ impl<'a> InputStreams<'a> {
/// Get the axis pair associated to the user input.
///
/// If `input` is a chord, returns result of the first dual axis in the chord.
/// If `input` is not a [`DualAxis`] or [`VirtualDPad`](crate::axislike::VirtualDPad), returns [`None`].
///
/// # Warning
Expand Down
67 changes: 20 additions & 47 deletions src/user_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,11 @@ impl UserInput {
/// - A [`Single`][UserInput::Single] input returns 1
/// - A [`Chord`][UserInput::Chord] returns the number of buttons in the chord
/// - A [`VirtualDPad`][UserInput::VirtualDPad] returns 1
/// - A [`VirtualAxis`][UserInput::VirtualAxis] returns 1
pub fn len(&self) -> usize {
match self {
UserInput::Single(_) => 1,
UserInput::Chord(button_set) => button_set.len(),
UserInput::VirtualDPad { .. } => 1,
UserInput::VirtualAxis { .. } => 1,
_ => 1,
}
}

Expand Down Expand Up @@ -102,44 +101,23 @@ impl UserInput {
pub fn n_matching(&self, buttons: &HashSet<InputKind>) -> usize {
match self {
UserInput::Single(button) => usize::from(buttons.contains(button)),
UserInput::Chord(chord_buttons) => {
let mut n_matching = 0;
for button in buttons.iter() {
if chord_buttons.contains(button) {
n_matching += 1;
}
}

n_matching
}
UserInput::VirtualDPad(VirtualDPad {
up,
down,
left,
right,
}) => {
let mut n_matching = 0;
for button in buttons.iter() {
for dpad_button in [up, down, left, right] {
if button == dpad_button {
n_matching += 1;
}
}
}

n_matching
UserInput::Chord(chord_buttons) => buttons
.iter()
.filter(|button| chord_buttons.contains(button))
.count(),
UserInput::VirtualDPad(dpad) => {
let dpad_buttons = [dpad.up, dpad.down, dpad.left, dpad.right];
buttons
.iter()
.filter(|button| dpad_buttons.contains(button))
.count()
}
UserInput::VirtualAxis(VirtualAxis { negative, positive }) => {
let mut n_matching = 0;
for button in buttons.iter() {
for dpad_button in [negative, positive] {
if button == dpad_button {
n_matching += 1;
}
}
}

n_matching
let axis_buttons = [negative, positive];
buttons
.iter()
.filter(|button| axis_buttons.contains(button))
.count()
}
}
}
Expand All @@ -157,14 +135,9 @@ impl UserInput {
raw_inputs.merge_input_data(button);
}
}
UserInput::VirtualDPad(VirtualDPad {
up,
down,
left,
right,
}) => {
for button in [up, down, left, right] {
raw_inputs.merge_input_data(button);
UserInput::VirtualDPad(dpad) => {
for button in [dpad.up, dpad.down, dpad.left, dpad.right] {
raw_inputs.merge_input_data(&button);
}
}
UserInput::VirtualAxis(VirtualAxis { negative, positive }) => {
Expand Down

0 comments on commit 8c28761

Please sign in to comment.