K3dKeyMapBuild.cpp

Go to the documentation of this file.
00001 
00011 /***************************************************************************
00012  *   Copyright (C) 2007 by Jan Koci   *
00013  *   honza.koci@email.cz   *
00014  *   http://kengine.sourceforge.net/tutorial/
00015  *                                                                         *
00016  *   This program is free software; you can redistribute it and/or modify  *
00017  *   it under the terms of the GNU General Public License as published by  *
00018  *   the Free Software Foundation; either version 2 of the License, or     *
00019  *   (at your option) any later version.                                   *
00020  *                                                                         *
00021  *   This program is distributed in the hope that it will be useful,       *
00022  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00023  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00024  *   GNU General Public License for more details.                          *
00025  *                                                                         *
00026  *   You should have received a copy of the GNU General Public License     *
00027  *   along with this program; if not, write to the                         *
00028  *   Free Software Foundation, Inc.,                                       *
00029  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
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                 // Insert results to result key map
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                 // Get Lua from global data
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 }

Generated on Thu Aug 16 23:53:25 2007 for K3dEngine by  doxygen 1.5.0