Skip to content

Commit 4f353af

Browse files
committed
Use Direction type for the event helpers
1 parent 5e34aae commit 4f353af

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

lighthouse-protocol/src/input/gamepad_button_event.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use serde::{Deserialize, Serialize};
22

3-
use crate::{Delta, Unity, Zero};
3+
use crate::Direction;
44

55
/// A button event on a gamepad.
66
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
@@ -17,12 +17,12 @@ pub struct GamepadButtonEvent {
1717
impl GamepadButtonEvent {
1818
/// The direction if one of the D-pad buttons was pressed.
1919
/// See https://www.w3.org/TR/gamepad/#dfn-standard-gamepad
20-
pub fn d_pad_direction<T>(&self) -> Option<Delta<T>> where T: Zero + Unity {
20+
pub fn d_pad_direction(&self) -> Option<Direction> {
2121
match self.index {
22-
12 => Some(Delta::UP),
23-
13 => Some(Delta::DOWN),
24-
14 => Some(Delta::LEFT),
25-
15 => Some(Delta::RIGHT),
22+
12 => Some(Direction::Up),
23+
13 => Some(Direction::Down),
24+
14 => Some(Direction::Left),
25+
15 => Some(Direction::Right),
2626
_ => None,
2727
}
2828
}

lighthouse-protocol/src/input/key_event.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use serde::{Deserialize, Serialize};
22

3-
use crate::{Delta, Unity, Zero};
3+
use crate::Direction;
44

55
use super::{EventSource, KeyModifiers};
66

@@ -22,28 +22,28 @@ pub struct KeyEvent {
2222

2323
impl KeyEvent {
2424
/// The direction if either the WASD or arrow keys were pressed.
25-
pub fn direction<T>(&self) -> Option<Delta<T>> where T: Zero + Unity {
25+
pub fn direction(&self) -> Option<Direction> {
2626
self.wasd_direction().or_else(|| self.arrow_direction())
2727
}
2828

2929
/// The direction if one of the WASD keys was pressed.
30-
pub fn wasd_direction<T>(&self) -> Option<Delta<T>> where T: Zero + Unity {
30+
pub fn wasd_direction(&self) -> Option<Direction> {
3131
match self.code.as_str() {
32-
"KeyW" => Some(Delta::UP),
33-
"KeyA" => Some(Delta::LEFT),
34-
"KeyS" => Some(Delta::DOWN),
35-
"KeyD" => Some(Delta::RIGHT),
32+
"KeyW" => Some(Direction::Up),
33+
"KeyA" => Some(Direction::Left),
34+
"KeyS" => Some(Direction::Down),
35+
"KeyD" => Some(Direction::Right),
3636
_ => None,
3737
}
3838
}
3939

4040
/// The direction if one of the arrow keys was pressed.
41-
pub fn arrow_direction<T>(&self) -> Option<Delta<T>> where T: Zero + Unity {
41+
pub fn arrow_direction(&self) -> Option<Direction> {
4242
match self.code.as_str() {
43-
"ArrowUp" => Some(Delta::UP),
44-
"ArrowLeft" => Some(Delta::LEFT),
45-
"ArrowDown" => Some(Delta::DOWN),
46-
"ArrowRight" => Some(Delta::RIGHT),
43+
"ArrowUp" => Some(Direction::Up),
44+
"ArrowLeft" => Some(Direction::Left),
45+
"ArrowDown" => Some(Direction::Down),
46+
"ArrowRight" => Some(Direction::Right),
4747
_ => None,
4848
}
4949
}

0 commit comments

Comments
 (0)