1use crate::inputs::KeyState::{Held, JustPressed, JustReleased, Released};
2
3#[derive(Debug, Default)]
4pub struct GamePad {
5 pub up: bool,
6 pub down: bool,
7 pub left: bool,
8 pub right: bool,
9 pub b: bool,
10 pub a: bool,
11 pub c: bool,
12 pub start: bool,
13
14 pub x: bool,
16 pub y: bool,
17 pub z: bool,
18 pub mode: bool,
19
20 pub port_select: bool,
21}
22
23#[derive(Copy, Clone, Debug)]
24#[derive(Eq, Hash, PartialEq)]
25pub enum ControllerButton {
26 Up,
27 Down,
28 Left,
29 Right,
30 B,
31 A,
32 Start,
33 C,
34}
35
36#[derive(Copy, Clone, Debug)]
37#[derive(Eq, Hash, PartialEq)]
38pub enum InputCommand {
39 Controller1(ControllerButton),
40 Controller2(ControllerButton),
41 PlayPause,
42 SoftReset,
43 HardReset,
44}
45
46#[derive(Copy, Clone, Debug)]
47#[derive(Eq, Hash, PartialEq)]
48pub enum KeyState {
49 JustPressed,
50 Held,
51 JustReleased,
52 Released
53}
54
55
56impl KeyState {
57 pub fn is_pressed(&self) -> bool {
58 match self {
59 JustPressed => { true }
60 Held => { true }
61 JustReleased => { false }
62 Released => { false }
63 }
64 }
65
66 pub fn new(pressed: bool) -> Self {
67 if pressed {
68 return JustPressed
69 }
70 Released
71 }
72
73 pub fn update_state(&self, pressed: bool) -> Self {
74 if pressed {
75 return match self {
76 JustPressed => { JustPressed }
77 Held => { Held }
78 JustReleased => { JustPressed }
79 Released => { JustPressed }
80 }
81 }
82 match self {
83 JustPressed => { JustReleased }
84 Held => { JustReleased }
85 JustReleased => { Released }
86 Released => { Released }
87 }
88 }
89
90 pub fn update(&self) -> Self {
91 match self {
92 JustPressed => { Held }
93 Held => { Held }
94 JustReleased => { Released }
95 Released => { Released }
96 }
97 }
98}