00001
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "K3dKeyMapBuild.h"
00033
00034
00038 void K3dKeyMapBuild::GenerateKeyMap(std::string _strKeyMap, std::string _strActionMap)
00039 {
00040 bool bActionFound = false;
00041 bool bKeyFound = false;
00042 int iKey = 0;
00043 EKeyMapAction eAction = K_NUM_ACTION;
00044 if (!m_tActionTransferMap.count(_strActionMap))
00045 {
00046 std::cerr << "void K3dKeyMapBuild::GenerateKeyMap() -- Error - "<< _strActionMap << " doesn`t in action map." << std::endl;
00047 }
00048 else
00049 {
00050 eAction = m_tActionTransferMap[_strActionMap];
00051 bActionFound = true;
00052 }
00053 if (!m_tKeyTransferMap.count(_strKeyMap))
00054 {
00055 std::cerr << "void K3dKeyMapBuild::GenerateKeyMap() -- Error - "<< _strKeyMap << " doesn`t in key map." << std::endl;
00056 }
00057 else
00058 {
00059 iKey = m_tKeyTransferMap[_strKeyMap];
00060 bKeyFound = true;
00061 }
00062
00063 if((bActionFound)&&(bKeyFound))
00064 {
00065
00066 m_pGameData->GetKeyMap()->InsertKeyMap(eAction, iKey);
00067 }
00068 }
00069
00071 void K3dKeyMapBuild::LoadKeyMap()
00072 {
00073 cout << "void K3dKeyMapBuild::LoadKeyMap()" << endl;
00074 if(m_bIsKeyMapLoaded == false)
00075 {
00076 K3dString strFc = "void K3dKeyMapBuild::LoadKeyMap() -- ";
00077 K3dString strOut;
00078
00079
00080 K3dLua *pLua = m_pGameData->GetLua();
00081
00082 pLua->LuaGetGlobal(K_STR_KEY_MAP);
00083 if (!pLua->LuaIsTable(-1))
00084 {
00085 strOut = strFc + K_STR_KEY_MAP;
00086 strOut += " is not a valid key map table";
00087 pLua->LuaError(strOut.GetString().c_str());
00088 }
00089 std::string kStr = pLua->LuaGetFieldString(K_STR_GO_FORWARD);
00090 CheckLoadError(kStr, K_STR_GO_FORWARD);
00091 GenerateKeyMap(kStr, K_STR_GO_FORWARD);
00092 kStr = pLua->LuaGetFieldString(K_STR_GO_BACKWARD);
00093 CheckLoadError(kStr, K_STR_GO_BACKWARD);
00094 GenerateKeyMap(kStr, K_STR_GO_BACKWARD);
00095 kStr = pLua->LuaGetFieldString(K_STR_GO_UP);
00096 CheckLoadError(kStr, K_STR_GO_UP);
00097 GenerateKeyMap(kStr, K_STR_GO_UP);
00098 kStr = pLua->LuaGetFieldString(K_STR_GO_DOWN);
00099 CheckLoadError(kStr, K_STR_GO_DOWN);
00100 GenerateKeyMap(kStr, K_STR_GO_DOWN);
00101 kStr = pLua->LuaGetFieldString(K_STR_STRAFE_LEFT);
00102 CheckLoadError(kStr, K_STR_STRAFE_LEFT);
00103 GenerateKeyMap(kStr, K_STR_STRAFE_LEFT);
00104 kStr = pLua->LuaGetFieldString(K_STR_STRAFE_RIGHT);
00105 CheckLoadError(kStr, K_STR_STRAFE_RIGHT);
00106 GenerateKeyMap(kStr, K_STR_STRAFE_RIGHT);
00107 kStr = pLua->LuaGetFieldString(K_STR_LURCH_LEFT);
00108 CheckLoadError(kStr, K_STR_LURCH_LEFT);
00109 GenerateKeyMap(kStr, K_STR_LURCH_LEFT);
00110 kStr = pLua->LuaGetFieldString(K_STR_LURCH_RIGHT);
00111 CheckLoadError(kStr, K_STR_LURCH_RIGHT);
00112 GenerateKeyMap(kStr, K_STR_LURCH_RIGHT);
00113 kStr = pLua->LuaGetFieldString(K_STR_TURN_LEFT);
00114 CheckLoadError(kStr, K_STR_TURN_LEFT);
00115 GenerateKeyMap(kStr, K_STR_TURN_LEFT);
00116 kStr = pLua->LuaGetFieldString(K_STR_TURN_RIGHT);
00117 CheckLoadError(kStr, K_STR_TURN_RIGHT);
00118 GenerateKeyMap(kStr, K_STR_TURN_RIGHT);
00119 kStr = pLua->LuaGetFieldString(K_STR_TURN_UP);
00120 CheckLoadError(kStr, K_STR_TURN_UP);
00121 GenerateKeyMap(kStr, K_STR_TURN_UP);
00122 kStr = pLua->LuaGetFieldString(K_STR_TURN_DOWN);
00123 CheckLoadError(kStr, K_STR_TURN_DOWN);
00124 GenerateKeyMap(kStr, K_STR_TURN_DOWN);
00125 m_bIsKeyMapLoaded = true;
00126 }
00127 }