From 338e728a60fc9135b534be4e8ad0bb43997a1ea4 Mon Sep 17 00:00:00 2001 From: Patrik Gornicz Date: Sun, 21 Sep 2008 23:02:11 -0400 Subject: [PATCH] fixed up the key mapping system a little ... still does comparisons wrong ... --- configs/{test.cfg => test1.cfg} | 2 + configs/test2.cfg | 2 + src/config/config.cpp | 3 +- src/config/keys.cpp | 18 ++++- src/config/keys.h | 28 +++++++ src/config/reader.cpp | 170 +++++++++++++++++++++------------------- src/config/reader.h | 4 +- 7 files changed, 138 insertions(+), 89 deletions(-) rename configs/{test.cfg => test1.cfg} (98%) create mode 100644 configs/test2.cfg diff --git a/configs/test.cfg b/configs/test1.cfg similarity index 98% rename from configs/test.cfg rename to configs/test1.cfg index c4d7b7f..524a754 100644 --- a/configs/test.cfg +++ b/configs/test1.cfg @@ -33,3 +33,5 @@ roger = flag0222 roger =flag2202 roger = flag2220 roger = flag2222 + +follow=k diff --git a/configs/test2.cfg b/configs/test2.cfg new file mode 100644 index 0000000..baf64f5 --- /dev/null +++ b/configs/test2.cfg @@ -0,0 +1,2 @@ +follow=k +well=LCtrl diff --git a/src/config/config.cpp b/src/config/config.cpp index 0980076..3b694ba 100644 --- a/src/config/config.cpp +++ b/src/config/config.cpp @@ -31,7 +31,8 @@ void cfg::init() { - readConfigs(NULL); + key::init(); + readConfigs(); // TODO read in config files } diff --git a/src/config/keys.cpp b/src/config/keys.cpp index 6ac87bb..e6eebf5 100644 --- a/src/config/keys.cpp +++ b/src/config/keys.cpp @@ -21,7 +21,17 @@ #include /// ***** Definitions of the extern keys ***** -SDLKey key::pause = SDLK_p; -SDLKey key::end = SDLK_ESCAPE; -SDLKey key::follow = SDLK_f; -SDLKey key::well = SDLK_SPACE; +SDLKey key::pause = SDLK_p; +SDLKey key::end = SDLK_ESCAPE; +SDLKey key::follow = SDLK_f; +SDLKey key::well = SDLK_SPACE; + +key::inputMap key::sdlMap; + +void key::init() +{ + key::sdlMap["pause"] = &key::pause; + key::sdlMap["end"] = &key::end; + key::sdlMap["follow"] = &key::follow; + key::sdlMap["well"] = &key::well; +} diff --git a/src/config/keys.h b/src/config/keys.h index 42fd378..49fe66f 100644 --- a/src/config/keys.h +++ b/src/config/keys.h @@ -21,6 +21,28 @@ #include +#include +#include + +#include "../debug.h" + +class comparestrings +{ + public: + bool operator() + ( + const std::string& a, + const std::string& b + ) + { + cout << a << endl; + cout << b << endl; + cout << endl; + + return a.compare(b) < 0; + } +}; + /// ***** Header Methods ***** namespace key { @@ -28,6 +50,12 @@ namespace key extern SDLKey end; extern SDLKey follow; extern SDLKey well; + + typedef std::map inputMap; + + extern inputMap sdlMap; + + void init(); } #endif // KEYS_H diff --git a/src/config/reader.cpp b/src/config/reader.cpp index af2c43e..c42e50d 100644 --- a/src/config/reader.cpp +++ b/src/config/reader.cpp @@ -22,28 +22,33 @@ #include #include +#include "keys.h" + using std::ifstream; using std::string; -typedef std::map kMap; +typedef std::map kMap; kMap keyMap; /// ***** Private Method Headers ***** -void processLine(const string& str, inputMap* map); +void processLine(const string& str); bool extractLine(const string& str, string* name, string* value); +void createKeyMap(); /// ***** Private Variables ***** const char* configDir = "configs/"; -const char* testFile = "test.cfg"; +const char* testFile = "test2.cfg"; /// ***** Public Methods ***** -void readConfigs(inputMap* map) +void readConfigs() { char fileName[64]; + createKeyMap(); + strcpy(fileName, configDir); strcat(fileName, testFile); @@ -63,7 +68,7 @@ void readConfigs(inputMap* map) if(file.eof()) break; - processLine(line, map); + processLine(line); } file.close(); @@ -71,7 +76,7 @@ void readConfigs(inputMap* map) /// ***** Private Methods ***** -void processLine(const string& str, inputMap* map) +void processLine(const string& str) { string name; string value; @@ -82,9 +87,15 @@ void processLine(const string& str, inputMap* map) if(extracted) { - //map->insert(name, value); + SDLKey key = keyMap[value]; + + if(0 != key) + { + *(key::sdlMap[name]) = key; + } cout << name << endl; cout << value << endl; + cout << key << endl; } } @@ -182,20 +193,12 @@ bool extractLine(const string& str, string* name, string* value) name->clear(); value->clear(); - name->replace(0, 0, c_str, name_start, name_end-name_start); - value->replace(0, 0, c_str, value_start, value_end-value_start); + name->replace (0, 0, c_str, name_start, name_end - name_start); + value->replace (0, 0, c_str, value_start, value_end - value_start); return true; } -bool extractKey(const string& str, Uint8* key) -{ -// if(str.length() != 1) -// return false; - - return false; -} - void createKeyMap() { // add all the letters @@ -208,6 +211,8 @@ void createKeyMap() for (int i = '0'; i <= '9'; i++) keyMap["" + (char)i] = (SDLKey)i; + keyMap["k"] = (SDLKey)'k'; + /* // add the function keys int F1 = (int)Key.F1; @@ -218,68 +223,71 @@ void createKeyMap() } */ - keyMap["LCtrl"] = SDLK_LCTRL; - keyMap["LeftControl"] = SDLK_LCTRL; - keyMap["LAlt"] = SDLK_LALT; - keyMap["LeftAlt"] = SDLK_LALT; - keyMap["LShift"] = SDLK_LSHIFT; - keyMap["LeftShift"] = SDLK_LSHIFT; - keyMap["LWin"] = SDLK_LSUPER; - keyMap["LeftWindows"] = SDLK_LSUPER; - keyMap["LeftMeta"] = SDLK_LMETA; - keyMap["LMeta"] = SDLK_LMETA; - - keyMap["RCtrl"] = SDLK_RCTRL; - keyMap["RightControl"] = SDLK_RCTRL; - keyMap["RAlt"] = SDLK_RALT; - keyMap["RightAlt"] = SDLK_RALT; - keyMap["RShift"] = SDLK_RSHIFT; - keyMap["RightShift"] = SDLK_RSHIFT; - keyMap["RWin"] = SDLK_RSUPER; - keyMap["RightWindows"] = SDLK_RSUPER; - keyMap["RightMeta"] = SDLK_RMETA; - keyMap["RMeta"] = SDLK_RMETA; - - keyMap["Esc"] = SDLK_ESCAPE; - keyMap["Escape"] = SDLK_ESCAPE; - - keyMap["Return"] = SDLK_RETURN; - keyMap["Enter"] = SDLK_RETURN; - - keyMap["Insert"] = SDLK_INSERT; - keyMap["Home"] = SDLK_HOME; - keyMap["Delete"] = SDLK_DELETE; - keyMap["End"] = SDLK_END; - keyMap["PageUp"] = SDLK_PAGEUP; - keyMap["PageDown"] = SDLK_PAGEDOWN; - - keyMap["Minus"] = SDLK_MINUS; - keyMap["Equal"] = SDLK_EQUALS; - keyMap["Equals"] = SDLK_EQUALS; - keyMap["LeftBracket"] = SDLK_LEFTBRACKET; - keyMap["LBracket"] = SDLK_LEFTBRACKET; - keyMap["RightBracket"] = SDLK_RIGHTBRACKET; - keyMap["RBracket"] = SDLK_RIGHTBRACKET; - keyMap["Backslash"] = SDLK_BACKSLASH; - keyMap["Slash"] = SDLK_SLASH; - keyMap["Semicolon"] = SDLK_SEMICOLON; - keyMap["Semi"] = SDLK_SEMICOLON; - keyMap["Quote"] = SDLK_QUOTE; - keyMap["Comma"] = SDLK_COMMA; - keyMap["Period"] = SDLK_PERIOD; - keyMap["Space"] = SDLK_SPACE; - keyMap["BSpace"] = SDLK_BACKSPACE; - keyMap["Backspace"] = SDLK_BACKSPACE; - keyMap["BackSpace"] = SDLK_BACKSPACE; - - keyMap["Tab"] = SDLK_TAB; - keyMap["BackQuote"] = SDLK_BACKQUOTE; - keyMap["BQuote"] = SDLK_BACKQUOTE; - keyMap["CapsLock"] = SDLK_CAPSLOCK; - keyMap["Caps"] = SDLK_CAPSLOCK; - - keyMap["Up"] = SDLK_UP; - keyMap["Down"] = SDLK_DOWN; - keyMap["Left"] = SDLK_LEFT; - keyMap["Right"] = SDLK_RIGHT; + keyMap["LCtrl"] = SDLK_LCTRL; + keyMap["LeftControl"] = SDLK_LCTRL; + keyMap["LAlt"] = SDLK_LALT; + keyMap["LeftAlt"] = SDLK_LALT; + keyMap["LShift"] = SDLK_LSHIFT; + keyMap["LeftShift"] = SDLK_LSHIFT; + keyMap["LWin"] = SDLK_LSUPER; + keyMap["LeftWindows"] = SDLK_LSUPER; + keyMap["LeftMeta"] = SDLK_LMETA; + keyMap["LMeta"] = SDLK_LMETA; + + keyMap["RCtrl"] = SDLK_RCTRL; + keyMap["RightControl"] = SDLK_RCTRL; + keyMap["RAlt"] = SDLK_RALT; + keyMap["RightAlt"] = SDLK_RALT; + keyMap["RShift"] = SDLK_RSHIFT; + keyMap["RightShift"] = SDLK_RSHIFT; + keyMap["RWin"] = SDLK_RSUPER; + keyMap["RightWindows"] = SDLK_RSUPER; + keyMap["RightMeta"] = SDLK_RMETA; + keyMap["RMeta"] = SDLK_RMETA; + + keyMap["Esc"] = SDLK_ESCAPE; + keyMap["Escape"] = SDLK_ESCAPE; + + keyMap["Return"] = SDLK_RETURN; + keyMap["Enter"] = SDLK_RETURN; + + keyMap["Insert"] = SDLK_INSERT; + keyMap["Home"] = SDLK_HOME; + keyMap["Delete"] = SDLK_DELETE; + keyMap["End"] = SDLK_END; + keyMap["PageUp"] = SDLK_PAGEUP; + keyMap["PageDown"] = SDLK_PAGEDOWN; + + keyMap["Minus"] = SDLK_MINUS; + keyMap["Equal"] = SDLK_EQUALS; + keyMap["Equals"] = SDLK_EQUALS; + keyMap["LeftBracket"] = SDLK_LEFTBRACKET; + keyMap["LBracket"] = SDLK_LEFTBRACKET; + keyMap["RightBracket"] = SDLK_RIGHTBRACKET; + keyMap["RBracket"] = SDLK_RIGHTBRACKET; + keyMap["Backslash"] = SDLK_BACKSLASH; + keyMap["Slash"] = SDLK_SLASH; + keyMap["Semicolon"] = SDLK_SEMICOLON; + keyMap["Semi"] = SDLK_SEMICOLON; + keyMap["Quote"] = SDLK_QUOTE; + keyMap["Comma"] = SDLK_COMMA; + keyMap["Period"] = SDLK_PERIOD; + keyMap["Space"] = SDLK_SPACE; + keyMap["BSpace"] = SDLK_BACKSPACE; + keyMap["Backspace"] = SDLK_BACKSPACE; + keyMap["BackSpace"] = SDLK_BACKSPACE; + + keyMap["Tab"] = SDLK_TAB; + keyMap["BackQuote"] = SDLK_BACKQUOTE; + keyMap["BQuote"] = SDLK_BACKQUOTE; + keyMap["CapsLock"] = SDLK_CAPSLOCK; + keyMap["Caps"] = SDLK_CAPSLOCK; + + keyMap["Up"] = SDLK_UP; + keyMap["Down"] = SDLK_DOWN; + keyMap["Left"] = SDLK_LEFT; + keyMap["Right"] = SDLK_RIGHT; + + cout << "done" << endl; + cout << keyMap["k"] << endl; } diff --git a/src/config/reader.h b/src/config/reader.h index eb13cbc..a978da2 100644 --- a/src/config/reader.h +++ b/src/config/reader.h @@ -25,10 +25,8 @@ using std::string; -typedef std::map inputMap; - /// ***** Header Methods ***** -void readConfigs(inputMap*); +void readConfigs(); #endif // READER_H -- 2.10.2