1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// <- controlmap.txt ignores clippy's caution because tab is part of the language use.
//! # ControlMap Parser Library
//!
//! The controlmap.txt parser for Skyrim.
//!
//! ## features
//!
//! - [x] controlmap.txt => json structure
//! - [x] json structure => controlmap.txt
//! - [x] Analysis using enum scanCodes.
//!
//! # Examples
//!
//! ```rust
//! use controlmap_parser::ControlMap;
//!
//! type Result<T, E = Box<dyn std::error::Error + 'static>> = core::result::Result<T, E>;
//! fn main() -> Result<()> {
//! let input = r#"
//! // Lockpicking
//! RotatePick 0xff 0xa 0x000b 0 0 0 0x8
//! RotateLock 0x1e,0xff 0xff 0x000c 0 0 0 0x8
//! DebugMode 0x35 0xff 0x4000 0 0 0 0x8
//! Cancel 0x0f 0xff 0x1000 0 0 0 0x8
//!
//! // Favor
//! Cancel 0x0f 0xff 0x1000 0 0 0 0x108"#;
//!
//! let control_map = ControlMap::from_txt(input)?;
//! println!("txt => Struct:\n{:?}", &control_map);
//!
//! let json = serde_json::to_string_pretty(&control_map)?;
//! let expected_json = r#"{
//! "lines": [
//! "BlankLine",
//! {
//! "Comment": " Lockpicking"
//! },
//! {
//! "EventLine": {
//! "event_name": "RotatePick",
//! "keyboard_id": {
//! "One": "0xff"
//! },
//! "mouse_id": {
//! "One": "0xa"
//! },
//! "gamepad_id": {
//! "One": "0x000b"
//! },
//! "remap_key": false,
//! "remap_mouse": false,
//! "remap_gamepad": false,
//! "event_binary_flag": "0x8"
//! }
//! },
//! {
//! "EventLine": {
//! "event_name": "RotateLock",
//! "keyboard_id": {
//! "Or": [
//! {
//! "One": "0x1e"
//! },
//! {
//! "One": "0xff"
//! }
//! ]
//! },
//! "mouse_id": {
//! "One": "0xff"
//! },
//! "gamepad_id": {
//! "One": "0x000c"
//! },
//! "remap_key": false,
//! "remap_mouse": false,
//! "remap_gamepad": false,
//! "event_binary_flag": "0x8"
//! }
//! },
//! {
//! "EventLine": {
//! "event_name": "DebugMode",
//! "keyboard_id": {
//! "One": "0x35"
//! },
//! "mouse_id": {
//! "One": "0xff"
//! },
//! "gamepad_id": {
//! "One": "0x4000"
//! },
//! "remap_key": false,
//! "remap_mouse": false,
//! "remap_gamepad": false,
//! "event_binary_flag": "0x8"
//! }
//! },
//! {
//! "EventLine": {
//! "event_name": "Cancel",
//! "keyboard_id": {
//! "One": "0x0f"
//! },
//! "mouse_id": {
//! "One": "0xff"
//! },
//! "gamepad_id": {
//! "One": "0x1000"
//! },
//! "remap_key": false,
//! "remap_mouse": false,
//! "remap_gamepad": false,
//! "event_binary_flag": "0x8"
//! }
//! },
//! "BlankLine",
//! {
//! "Comment": " Favor"
//! },
//! {
//! "EventLine": {
//! "event_name": "Cancel",
//! "keyboard_id": {
//! "One": "0x0f"
//! },
//! "mouse_id": {
//! "One": "0xff"
//! },
//! "gamepad_id": {
//! "One": "0x1000"
//! },
//! "remap_key": false,
//! "remap_mouse": false,
//! "remap_gamepad": false,
//! "event_binary_flag": "0x108"
//! }
//! }
//! ]
//! }"#;
//! assert_eq!(&json, expected_json);
//!
//! let control_map: ControlMap = serde_json::from_str(&json)?;
//! // Yes, blank lines are not removed, they are applied as is.
//! // There are places where it would be an error to do otherwise.
//! let formatted_control_map = r#"
//! // Lockpicking
//! RotatePick 0xff 0xa 0x000b 0 0 0 0x8
//! RotateLock 0x1e+0xff 0xff 0x000c 0 0 0 0x8
//! DebugMode 0x35 0xff 0x4000 0 0 0 0x8
//! Cancel 0x0f 0xff 0x1000 0 0 0 0x8
//!
//! // Favor
//! Cancel 0x0f 0xff 0x1000 0 0 0 0x108
//! "#;
//! assert_eq!(control_map.to_string(), formatted_control_map);
//!
//! Ok(())
//! }
//! ```
pub use ;