fixed up the key mapping system a little ... still does comparisons wrong ...
authorPatrik Gornicz <Gornicz.P@gmail.com>
Mon, 22 Sep 2008 03:02:11 +0000 (23:02 -0400)
committerPatrik Gornicz <Gornicz.P@gmail.com>
Mon, 22 Sep 2008 03:02:11 +0000 (23:02 -0400)
configs/test1.cfg [moved from configs/test.cfg with 98% similarity]
configs/test2.cfg [new file with mode: 0644]
src/config/config.cpp
src/config/keys.cpp
src/config/keys.h
src/config/reader.cpp
src/config/reader.h

similarity index 98%
rename from configs/test.cfg
rename to configs/test1.cfg
index c4d7b7f..524a754 100644 (file)
@@ -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 (file)
index 0000000..baf64f5
--- /dev/null
@@ -0,0 +1,2 @@
+follow=k
+well=LCtrl
index 0980076..3b694ba 100644 (file)
@@ -31,7 +31,8 @@
 
 void cfg::init()
 {
-    readConfigs(NULL);
+    key::init();
+    readConfigs();
 
     // TODO read in config files
 }
index 6ac87bb..e6eebf5 100644 (file)
 #include <SDL/SDL.h>
 
 /// ***** 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;
+}
index 42fd378..49fe66f 100644 (file)
 
 #include <SDL/SDL.h>
 
+#include <map>
+#include <string>
+
+#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<std::string, SDLKey*, comparestrings> inputMap;
+
+    extern inputMap sdlMap;
+
+    void init();
 }
 
 #endif // KEYS_H
index af2c43e..c42e50d 100644 (file)
 #include <fstream>
 #include <string>
 
+#include "keys.h"
+
 using std::ifstream;
 using std::string;
 
-typedef std::map<string,SDLKey> kMap;
+typedef std::map<string, SDLKey, comparestrings> 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;
 }
index eb13cbc..a978da2 100644 (file)
 
 using std::string;
 
-typedef std::map<string,Uint8> inputMap;
-
 /// ***** Header Methods *****
 
-void readConfigs(inputMap*);
+void readConfigs();
 
 #endif // READER_H