• R/O
  • SSH

silny-kombat: Commit

Mercurial repo for silny-kombat project


Commit MetaInfo

Revision980b29188d4fbbadfcfaa83a2fac99b3deb655c6 (tree)
Time2022-02-10 04:03:39
AuthorSecT
CommiterSecT

Log Message

Refactoring - enum for key events

Change Summary

Incremental Difference

diff -r bdcbe80165cc -r 980b29188d4f src/key_processing.rs
--- a/src/key_processing.rs Thu Feb 03 19:54:30 2022 +0100
+++ b/src/key_processing.rs Wed Feb 09 20:03:39 2022 +0100
@@ -6,67 +6,17 @@
66 //use crate::sprite_rendering;
77
88 pub const KEY_BASE : i32 = 10;
9-//delete old standalone definitions - use the definitions from KeyProcessor instead
10-//
11-//
12-// pub fn process_key( key_result: i32, state: &mut i32) {
13-// if key_result == 1
14-// {
15-// *state = 2;
16-//
17-//
18-// } else if key_result == 2
19-// {
20-// *state = 1;
21-//
22-// }
23-// }
24-//
25-// pub fn match_key(event: Event) -> i32 {
26-// match event {
27-// Event::Closed
28-// | Event::KeyPressed {
29-// code: Key::ESCAPE, ..
30-// } => return 0,
31-//
32-// //testing
33-// Event::KeyPressed {
34-// code: Key::F4, ..
35-// } => return 99,
36-//
37-// Event::KeyPressed {
38-// code: Key::LEFT, ..
39-// } => return 1,
40-// Event::KeyPressed {
41-// code: Key::RIGHT, ..
42-// } => return 2,
43-// Event::KeyReleased {
44-// code:Key::RIGHT, ..
45-// } => return 3,
46-// Event::KeyReleased {
47-// code:Key::LEFT, ..
48-// } => return 3,
49-//
50-//
51-// Event::KeyPressed {
52-// code: Key::A, .. //move left for second character
53-// } => return KEY_BASE + 1,
54-// Event::KeyPressed {
55-// code: Key::D, .. //move right for second character
56-// } => return KEY_BASE + 2,
57-// Event::KeyReleased {
58-// code:Key::A, ..
59-// } => return KEY_BASE + 3,
60-// Event::KeyReleased {
61-// code:Key::D, ..
62-// } => return KEY_BASE + 3,
63-// _ => {}
64-// }
65-// return -1;
66-// }
679
68-//end delete
10+enum KeyEvents {
11+ Escape,
12+ Char_Left,
13+ Char_Right,
14+ Char_Key_Release
15+}
6916
17+enum SignalForSM {
18+
19+}
7020
7121 pub struct KeyProcessor {
7222
@@ -84,16 +34,16 @@
8434 }
8535
8636 pub fn process_key(&self, key_result: i32) -> i32 {
87- if key_result == 1
37+ if key_result == KeyEvents::Char_Left as i32
8838 {
8939 return 2;
9040
9141
92- } else if key_result == 2
42+ } else if key_result == KeyEvents::Char_Right as i32
9343 {
9444 return 1;
9545
96- } else if key_result == 3
46+ } else if key_result == KeyEvents::Char_Key_Release as i32
9747 {
9848 return 3;
9949 }
@@ -103,11 +53,14 @@
10353
10454
10555 pub fn match_key(&self, event: Event) -> i32 {
56+
57+ //TODO: refactor enum->i32 conversions, just return a enum
58+
10659 match event {
10760 Event::Closed
10861 | Event::KeyPressed {
10962 code: Key::ESCAPE, ..
110- } => return 0,
63+ } => return KeyEvents::Escape as i32,
11164
11265 //testing
11366 Event::KeyPressed {
@@ -116,30 +69,30 @@
11669
11770 Event::KeyPressed {
11871 code: Key::LEFT, ..
119- } => return 1,
72+ } => return KeyEvents::Char_Left as i32,
12073 Event::KeyPressed {
12174 code: Key::RIGHT, ..
122- } => return 2,
75+ } => return KeyEvents::Char_Right as i32,
12376 Event::KeyReleased {
12477 code:Key::RIGHT, ..
125- } => return 3,
78+ } => return KeyEvents::Char_Key_Release as i32,
12679 Event::KeyReleased {
12780 code:Key::LEFT, ..
128- } => return 3,
81+ } => return KeyEvents::Char_Key_Release as i32,
12982
13083
13184 Event::KeyPressed {
13285 code: Key::A, .. //move left for second character
133- } => return KEY_BASE + 1,
86+ } => return KEY_BASE + KeyEvents::Char_Left as i32,
13487 Event::KeyPressed {
13588 code: Key::D, .. //move right for second character
136- } => return KEY_BASE + 2,
89+ } => return KEY_BASE + KeyEvents::Char_Right as i32,
13790 Event::KeyReleased {
13891 code:Key::A, ..
139- } => return KEY_BASE + 3,
92+ } => return KEY_BASE + KeyEvents::Char_Key_Release as i32,
14093 Event::KeyReleased {
14194 code:Key::D, ..
142- } => return KEY_BASE + 3,
95+ } => return KEY_BASE + KeyEvents::Char_Key_Release as i32,
14396 _ => {}
14497 }
14598 return -1;
Show on old repository browser