rkg_utils/input_data/input.rs
1use crate::input_data::dpad_input::DPadButton;
2use crate::input_data::face_input::FaceButton;
3
4/// A fully decoded controller input state for one or more consecutive frames.
5///
6/// Combines the face button state, analog stick position, and D-pad button
7/// from a single encoded input triplet (face + stick + D-pad) into
8/// one convenient struct. The `frame_duration` field records how many
9/// consecutive frames this exact input state was held.
10#[derive(Debug, Clone, PartialEq)]
11pub struct Input {
12 /// The set of face buttons active during this input state.
13 face_buttons: Vec<FaceButton>,
14 /// Horizontal stick axis (−7 to +7; negative = left, positive = right).
15 stick_x: i8,
16 /// Vertical stick axis (−7 to +7; negative = down, positive = up).
17 stick_y: i8,
18 /// The D-pad button held during this input state.
19 dpad_button: DPadButton,
20 /// The number of consecutive frames this input state was held.
21 frame_duration: u32,
22}
23
24impl Input {
25 /// Creates a new [`Input`] from its individual components.
26 pub fn new(
27 face_buttons: Vec<FaceButton>,
28 stick_x: i8,
29 stick_y: i8,
30 dpad_button: DPadButton,
31 frame_duration: u32,
32 ) -> Self {
33 Self {
34 face_buttons,
35 stick_x,
36 stick_y,
37 dpad_button,
38 frame_duration,
39 }
40 }
41
42 /// Returns the set of face buttons active during this input state.
43 pub fn face_buttons(&self) -> &[FaceButton] {
44 &self.face_buttons
45 }
46
47 /// Returns the horizontal stick axis value (−7 to +7).
48 pub fn stick_x(&self) -> i8 {
49 self.stick_x
50 }
51
52 /// Returns the vertical stick axis value (−7 to +7).
53 pub fn stick_y(&self) -> i8 {
54 self.stick_y
55 }
56
57 /// Returns the D-pad button held during this input state.
58 pub fn dpad_button(&self) -> DPadButton {
59 self.dpad_button
60 }
61
62 /// Returns the number of consecutive frames this input state was held.
63 pub fn frame_duration(&self) -> u32 {
64 self.frame_duration
65 }
66}