- fix auto loading scenario from commandline

This commit is contained in:
SoftCoder 2013-12-30 12:19:10 -08:00
parent c7c82b56e1
commit 2c788e074a
3 changed files with 33 additions and 5 deletions

View File

@ -313,7 +313,8 @@ void MenuStateScenario::update() {
if(this->autoloadScenarioName != "") {
string scenarioPath = Scenario::getScenarioPath(dirList, this->autoloadScenarioName);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("[%s:%s] Line: %d this->autoloadScenarioName [%s] scenarioPath [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,this->autoloadScenarioName.c_str(),scenarioPath.c_str());
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("[%s:%s] Line: %d this->autoloadScenarioName [%s] scenarioPath [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,this->autoloadScenarioName.c_str(),scenarioPath.c_str());
printf("[%s:%s] Line: %d this->autoloadScenarioName [%s] scenarioPath [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,this->autoloadScenarioName.c_str(),scenarioPath.c_str());
loadScenarioInfo(scenarioPath, &scenarioInfo );
//if(scenarioInfo.namei18n != "") {
@ -323,7 +324,8 @@ void MenuStateScenario::update() {
this->autoloadScenarioName = formatString(this->autoloadScenarioName);
//}
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("[%s:%s] Line: %d this->autoloadScenarioName [%s] scenarioPath [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,this->autoloadScenarioName.c_str(),scenarioPath.c_str());
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("[%s:%s] Line: %d this->autoloadScenarioName [%s] scenarioPath [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,this->autoloadScenarioName.c_str(),scenarioPath.c_str());
printf("[%s:%s] Line: %d this->autoloadScenarioName [%s] scenarioPath [%s] file [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,this->autoloadScenarioName.c_str(),scenarioPath.c_str(),scenarioInfo.file.c_str());
listBoxScenario.setSelectedItem(this->autoloadScenarioName,false);
@ -335,8 +337,15 @@ void MenuStateScenario::update() {
else {
try {
this->autoloadScenarioName = "";
if(listBoxScenario.getItemCount() > 0 && listBoxScenario.getSelectedItemIndex() >= 0 && listBoxScenario.getSelectedItemIndex() < (int)scenarioFiles.size()) {
if(listBoxScenario.getItemCount() > 0 && listBoxScenario.getSelectedItemIndex() >= 0 &&
listBoxScenario.getSelectedItemIndex() < (int)scenarioFiles.size()) {
printf("[%s:%s] Line: %d scenarioFiles[listBoxScenario.getSelectedItemIndex()] [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,scenarioFiles[listBoxScenario.getSelectedItemIndex()].c_str());
loadScenarioInfo(Scenario::getScenarioPath(dirList, scenarioFiles[listBoxScenario.getSelectedItemIndex()]), &scenarioInfo);
printf("[%s:%s] Line: %d scenarioInfo.file [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,scenarioInfo.file.c_str());
labelInfo.setText(scenarioInfo.desc);
if(scenarioInfo.namei18n != "") {
labelScenarioName.setText(scenarioInfo.namei18n);

View File

@ -140,6 +140,7 @@ string Scenario::getScenarioPath(const vector<string> dirList, const string &sce
string currentPath = dirList[idx];
endPathWithSlash(currentPath);
scenarioFile = currentPath + scenarioName + "/" + scenarioName + ".xml";
//printf("\n[%s:%s] Line: %d scenarioName [%s] scenarioFile [%s]\n",__FILE__,__FUNCTION__,__LINE__,scenarioName.c_str(),scenarioFile.c_str());
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\n[%s:%s] Line: %d scenarioName [%s] scenarioFile [%s]\n",__FILE__,__FUNCTION__,__LINE__,scenarioName.c_str(),scenarioFile.c_str());
//printf("\n[%s:%s] Line: %d scenarioName [%s] scenarioFile [%s]\n",__FILE__,__FUNCTION__,__LINE__,scenarioName.c_str(),scenarioFile.c_str());

View File

@ -294,7 +294,7 @@ void LuaScript::saveGame(XmlNode *rootNode) {
break;
case LUA_TTABLE:
{
if(LuaScript::debugModeEnabled == true) printf("LUA TABLE DETECTED - START\n");
if(LuaScript::debugModeEnabled == true) printf("================ LUA TABLE DETECTED - START =================\n");
for (lua_pushnil(L); lua_next(L, -2) ;) {
if(LuaScript::debugModeEnabled == true) printf("LUA TABLE loop A\n");
@ -363,6 +363,7 @@ void LuaScript::saveGame(XmlNode *rootNode) {
lua_pop(L, 1);
}
}
if(LuaScript::debugModeEnabled == true) printf("---------------------------- LUA TABLE DETECTED - END ----------------------------\n");
}
break;
}
@ -429,20 +430,25 @@ void LuaScript::loadGame(const XmlNode *rootNode) {
string variable = node->getAttribute("variable")->getValue();
int value_type = node->getAttribute("value_type")->getIntValue();
if(LuaScript::debugModeEnabled) printf("i: %d [%s] [%d]\n",i,variable.c_str(),value_type);
if(LuaScript::debugModeEnabled) printf(" index #: %d [%s] [%d]\n",i,variable.c_str(),value_type);
switch (value_type) {
case LUA_TSTRING:
if(LuaScript::debugModeEnabled) printf(" value [%s]\n",node->getAttribute("value")->getValue().c_str());
lua_pushstring( luaState, node->getAttribute("value")->getValue().c_str() );
break;
case LUA_TNUMBER:
if(LuaScript::debugModeEnabled) printf(" value [%s]\n",node->getAttribute("value")->getValue().c_str());
lua_pushnumber( luaState, node->getAttribute("value")->getFloatValue() );
break;
case LUA_TBOOLEAN:
if(LuaScript::debugModeEnabled) printf(" value [%s]\n",node->getAttribute("value")->getValue().c_str());
lua_pushboolean( luaState, node->getAttribute("value")->getBoolValue() );
break;
case LUA_TTABLE:
{
if(LuaScript::debugModeEnabled == true) printf("================ LUA TABLE DETECTED - START =================\n");
lua_newtable(luaState); /* We will pass a table */
vector<XmlNode *> luaScriptTableNode = node->getChildList("Table");
@ -452,32 +458,44 @@ void LuaScript::loadGame(const XmlNode *rootNode) {
XmlNode *nodeTable = luaScriptTableNode[j];
int key_type = nodeTable->getAttribute("key_type")->getIntValue();
if(LuaScript::debugModeEnabled == true) printf("Table item key_type: %d [%s]\n",key_type,lua_typename(luaState, key_type));
switch (key_type) {
case LUA_TSTRING:
if(LuaScript::debugModeEnabled) printf(" table item key [%s]\n",nodeTable->getAttribute("key")->getValue().c_str());
lua_pushstring( luaState, nodeTable->getAttribute("key")->getValue().c_str() );
break;
case LUA_TNUMBER:
if(LuaScript::debugModeEnabled) printf(" table item key [%s]\n",nodeTable->getAttribute("key")->getValue().c_str());
lua_pushnumber( luaState, nodeTable->getAttribute("key")->getFloatValue() );
break;
case LUA_TBOOLEAN:
if(LuaScript::debugModeEnabled) printf(" table item key [%s]\n",nodeTable->getAttribute("key")->getValue().c_str());
lua_pushboolean( luaState, nodeTable->getAttribute("key")->getBoolValue() );
break;
}
int value_type = nodeTable->getAttribute("value_type")->getIntValue();
if(LuaScript::debugModeEnabled == true) printf("Table item value_type: %d [%s]\n",value_type,lua_typename(luaState, value_type));
switch (value_type) {
case LUA_TSTRING:
if(LuaScript::debugModeEnabled) printf(" table item value [%s]\n",nodeTable->getAttribute("value")->getValue().c_str());
lua_pushstring( luaState, nodeTable->getAttribute("value")->getValue().c_str() );
break;
case LUA_TNUMBER:
if(LuaScript::debugModeEnabled) printf(" table item value [%s]\n",nodeTable->getAttribute("value")->getValue().c_str());
lua_pushnumber( luaState, nodeTable->getAttribute("value")->getFloatValue() );
break;
case LUA_TBOOLEAN:
if(LuaScript::debugModeEnabled) printf(" table item value [%s]\n",nodeTable->getAttribute("value")->getValue().c_str());
lua_pushboolean( luaState, nodeTable->getAttribute("value")->getBoolValue() );
break;
}
lua_rawset(luaState, -3); /* Stores the pair in the table */
}
if(LuaScript::debugModeEnabled == true) printf("----------------- LUA TABLE DETECTED - END -----------------\n");
}
break;