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 #include "K3dConfDataBuild.h" 00032 00033 K3dConfDataBuild::K3dConfDataBuild ( K3dGameData *_pGameData ) 00034 { 00035 m_pGameData = _pGameData; 00036 } 00037 00038 K3dConfDataBuild::~K3dConfDataBuild() 00039 { 00040 } 00041 00043 void K3dConfDataBuild::LoadConf() 00044 { 00045 cout << "void K3dConfDataBuild::LoadConf()" << endl; 00046 K3dString strFc = "void K3dConfDataBuild::LoadConf() -- "; 00047 K3dString strOut; 00048 K3dLua *pLua = m_pGameData->GetLua(); 00049 if(pLua) 00050 { 00051 K3dString strConfFile = m_pGameData->GetSysHome() + K3D_STR_SHARE_PATH + K3D_STR_CONF; 00052 cout << "strConfFile = " << strConfFile.GetString() << endl; 00053 // Load configuration file 00054 if(pLua->LuaLoadFile(strConfFile.GetString().c_str())) 00055 { 00056 // Load log filename 00057 pLua->LuaGetGlobal("LOG_FILENAME"); 00058 if (!pLua->LuaIsString(-1)) 00059 { 00060 strOut = strFc + "LOG_FILENAME"; 00061 strOut += " is not a valid string"; 00062 pLua->LuaError(strOut.GetString().c_str()); 00063 } 00064 m_pGameData->GetLogFilename() = pLua->LuaToString(-1); 00065 cout << "Log file name = " << m_pGameData->GetLogFilename().GetString() << endl; 00066 // Load path table 00067 pLua->LuaGetGlobal("T_PATH"); 00068 if (!pLua->LuaIsTable(-1)) 00069 { 00070 K3dString kStrTable("T_PATH"); 00071 strOut = strFc + kStrTable; 00072 strOut += " is not a valid name table"; 00073 pLua->LuaError(strOut.GetString().c_str()); 00074 } 00075 m_pGameData->GetMapPath() = pLua->LuaGetFieldString("MAPS"); 00076 cout << "Map path = " << m_pGameData->GetMapPath().GetString() << endl; 00077 m_pGameData->GetScriptPath() = pLua->LuaGetFieldString("SCRIPTS"); 00078 cout << "Script path = " << m_pGameData->GetScriptPath().GetString() << endl; 00079 m_pGameData->GetTexturePath() = pLua->LuaGetFieldString("TEXTURES"); 00080 cout << "Texture path = " << m_pGameData->GetTexturePath().GetString() << endl; 00081 m_pGameData->GetDebugPath() = pLua->LuaGetFieldString("DEBUG"); 00082 cout << "Debug path = " << m_pGameData->GetDebugPath().GetString() << endl; 00083 } 00084 else 00085 { 00086 cerr << "Error in void K3dConfDataBuild::LoadConf() -- Doesn`t read conf file" << strConfFile.GetString() << endl; 00087 } 00088 } 00089 else 00090 { 00091 cerr << "Error in void K3dConfDataBuild::LoadConf() -- Lua doesn`t initialized !" << endl; 00092 } 00093 } 00094