OpenRaider  0.1.4-dev
Open Source Tomb Raider Game Engine implementation
CommandBind.cpp
Go to the documentation of this file.
1 
8 #include "global.h"
9 #include "Log.h"
10 #include "RunTime.h"
11 #include "commands/CommandBind.h"
12 
13 std::string CommandBind::name() {
14  return "bind";
15 }
16 
17 std::string CommandBind::brief() {
18  return "bind a keyboard/mouse action";
19 }
20 
22  Log::get(LOG_USER) << "bind-Command Usage:" << Log::endl;
23  Log::get(LOG_USER) << " bind ACTION KEY" << Log::endl;
24  Log::get(LOG_USER) << "Available Actions:" << Log::endl;
25  Log::get(LOG_USER) << " menu" << Log::endl;
26  Log::get(LOG_USER) << " debug" << Log::endl;
27  Log::get(LOG_USER) << " forward" << Log::endl;
28  Log::get(LOG_USER) << " backward" << Log::endl;
29  Log::get(LOG_USER) << " left" << Log::endl;
30  Log::get(LOG_USER) << " right" << Log::endl;
31  Log::get(LOG_USER) << " jump" << Log::endl;
32  Log::get(LOG_USER) << " crouch" << Log::endl;
33  Log::get(LOG_USER) << " use" << Log::endl;
34  Log::get(LOG_USER) << " holster" << Log::endl;
35  Log::get(LOG_USER) << " walk" << Log::endl;
36  Log::get(LOG_USER) << "Key-Format:" << Log::endl;
37  Log::get(LOG_USER) << " 'a' or '1' for character/number keys" << Log::endl;
38  Log::get(LOG_USER) << " \"leftctrl\" for symbols and special keys" << Log::endl;
39 }
40 
41 int CommandBind::execute(std::istream& args) {
42  std::string a, b;
43  if (!(args >> a >> b)) {
44  Log::get(LOG_USER) << "Invalid use of bind-command" << Log::endl;
45  return -1;
46  } else {
48  if (e == ActionEventCount) {
49  Log::get(LOG_USER) << "bind-Error: Unknown action (" << a << ")" << Log::endl;
50  return -2;
51  }
52 
54  if (c == unknownKey) {
55  Log::get(LOG_USER) << "bind-Error: Unknown key (" << b << ")" << Log::endl;
56  return -3;
57  }
58 
60  return 0;
61  }
62 }
63 
65  if (action == "menu") {
66  return menuAction;
67  } else if (action == "debug") {
68  return debugAction;
69  } else if (action == "console") {
70  return consoleAction;
71  } else if (action == "forward") {
72  return forwardAction;
73  } else if (action == "backward") {
74  return backwardAction;
75  } else if (action == "left") {
76  return leftAction;
77  } else if (action == "right") {
78  return rightAction;
79  } else if (action == "jump") {
80  return jumpAction;
81  } else if (action == "crouch") {
82  return crouchAction;
83  } else if (action == "use") {
84  return useAction;
85  } else if (action == "holster") {
86  return holsterAction;
87  } else if (action == "walk") {
88  return walkAction;
89  } else {
90  return ActionEventCount;
91  }
92 }
93 
95  if ((key.length() == 3) && (key[0] == '\'') && (key[2] == '\'')) {
96  // Literal character like w, a, s, d, 0, 1...
97  char c = key[1];
98  if (((c >= '0') && (c <= '9'))
99  || ((c >= 'a') && (c <= 'z')))
100  return (KeyboardButton)c;
101  } else if ((key.length() >= 3) && (key[0] == '\"') && (key[key.length() - 1] == '\"')) {
102  // Special characters like tilde, esc, quote...
103  key.erase(key.length() - 1); // Delete " at end
104  key.erase(0, 1); // Delete " at beginning
105  if (key == "quote") {
106  return quoteKey;
107  } else if (key == "backslash") {
108  return backslashKey;
109  } else if (key == "backspace") {
110  return backspaceKey;
111  } else if (key == "capslock") {
112  return capslockKey;
113  } else if (key == "comma") {
114  return commaKey;
115  } else if (key == "del") {
116  return delKey;
117  } else if (key == "up") {
118  return upKey;
119  } else if (key == "down") {
120  return downKey;
121  } else if (key == "left") {
122  return leftKey;
123  } else if (key == "right") {
124  return rightKey;
125  } else if (key == "end") {
126  return endKey;
127  } else if (key == "equals") {
128  return equalsKey;
129  } else if (key == "escape") {
130  return escapeKey;
131  } else if (key == "f1") {
132  return f1Key;
133  } else if (key == "f2") {
134  return f2Key;
135  } else if (key == "f3") {
136  return f3Key;
137  } else if (key == "f4") {
138  return f4Key;
139  } else if (key == "f5") {
140  return f5Key;
141  } else if (key == "f6") {
142  return f6Key;
143  } else if (key == "f7") {
144  return f7Key;
145  } else if (key == "f8") {
146  return f8Key;
147  } else if (key == "f9") {
148  return f9Key;
149  } else if (key == "f10") {
150  return f10Key;
151  } else if (key == "f11") {
152  return f11Key;
153  } else if (key == "f12") {
154  return f12Key;
155  } else if (key == "backquote") {
156  return backquoteKey;
157  } else if (key == "home") {
158  return homeKey;
159  } else if (key == "insert") {
160  return insertKey;
161  } else if (key == "leftalt") {
162  return leftaltKey;
163  } else if (key == "leftctrl") {
164  return leftctrlKey;
165  } else if (key == "leftbracket") {
166  return leftbracketKey;
167  } else if (key == "leftgui") {
168  return leftguiKey;
169  } else if (key == "leftshift") {
170  return leftshiftKey;
171  } else if (key == "minus") {
172  return minusKey;
173  } else if (key == "numlock") {
174  return numlockKey;
175  } else if (key == "pagedown") {
176  return pagedownKey;
177  } else if (key == "pageup") {
178  return pageupKey;
179  } else if (key == "pause") {
180  return pauseKey;
181  } else if (key == "dot") {
182  return dotKey;
183  } else if (key == "rightalt") {
184  return rightaltKey;
185  } else if (key == "rightctrl") {
186  return rightctrlKey;
187  } else if (key == "enter") {
188  return enterKey;
189  } else if (key == "rightgui") {
190  return rightguiKey;
191  } else if (key == "rightbracket") {
192  return rightbracketKey;
193  } else if (key == "rightshift") {
194  return rightshiftKey;
195  } else if (key == "scrolllock") {
196  return scrolllockKey;
197  } else if (key == "semicolon") {
198  return semicolonKey;
199  } else if (key == "slash") {
200  return slashKey;
201  } else if (key == "space") {
202  return spaceKey;
203  } else if (key == "tab") {
204  return tabKey;
205  } else if (key == "leftmouse") {
206  return leftmouseKey;
207  } else if (key == "middlemouse") {
208  return middlemouseKey;
209  } else if (key == "rightmouse") {
210  return rightmouseKey;
211  } else if (key == "fourthmouse") {
212  return fourthmouseKey;
213  } else if (key == "fifthmouse") {
214  return fifthmouseKey;
215  }
216  }
217 
218  return unknownKey;
219 }
220 
Definition: global.h:48
virtual int execute(std::istream &args)
Definition: CommandBind.cpp:41
KeyboardButton stringToKeyboardButton(std::string key)
Definition: CommandBind.cpp:94
Definition: global.h:48
#define LOG_USER
Definition: Log.h:18
Definition: global.h:49
virtual void printHelp()
Definition: CommandBind.cpp:21
virtual std::string name()
Definition: CommandBind.cpp:13
virtual std::string brief()
Definition: CommandBind.cpp:17
Definition: global.h:49
KeyboardButton
Definition: global.h:34
Included everywhere.
Definition: global.h:47
static LogLevel & get(int level)
Definition: Log.cpp:14
Global Logging Utility.
Definition: global.h:49
ActionEvents stringToActionEvent(std::string action)
Definition: CommandBind.cpp:64
ActionEvents
Definition: global.h:15
Definition: global.h:47
static void setKeyBinding(ActionEvents event, KeyboardButton button)
Definition: RunTime.cpp:61
Definition: global.h:49
Definition: global.h:48
Definition: global.h:50
Definition: global.h:52
static const char endl
Definition: Log.h:35
Runtime Configuration Storage.
Definition: global.h:49
Definition: global.h:48
Definition: global.h:48
Definition: global.h:48
Definition: global.h:54
Definition: global.h:47
Definition: global.h:49
Definition: global.h:49
Definition: global.h:47
Bind Command.