- added two new lua methods basxto:
storeSaveGameData(name, value) string loadSaveGameData(name)
This commit is contained in:
parent
2c788e074a
commit
853d531d11
|
@ -390,6 +390,9 @@ void ScriptManager::init(World* world, GameCamera *gameCamera, const XmlNode *ro
|
||||||
luaScript.registerFunction(enableSpeedChange, "enableSpeedChange");
|
luaScript.registerFunction(enableSpeedChange, "enableSpeedChange");
|
||||||
luaScript.registerFunction(getSpeedChangeEnabled, "getSpeedChangeEnabled");
|
luaScript.registerFunction(getSpeedChangeEnabled, "getSpeedChangeEnabled");
|
||||||
|
|
||||||
|
luaScript.registerFunction(storeSaveGameData, "storeSaveGameData");
|
||||||
|
luaScript.registerFunction(loadSaveGameData, "loadSaveGameData");
|
||||||
|
|
||||||
//load code
|
//load code
|
||||||
for(int i= 0; i<scenario->getScriptCount(); ++i){
|
for(int i= 0; i<scenario->getScriptCount(); ++i){
|
||||||
const Script* script= scenario->getScript(i);
|
const Script* script= scenario->getScript(i);
|
||||||
|
@ -450,6 +453,9 @@ void ScriptManager::init(World* world, GameCamera *gameCamera, const XmlNode *ro
|
||||||
else {
|
else {
|
||||||
loadGame(this->rootNode);
|
loadGame(this->rootNode);
|
||||||
this->rootNode = NULL;
|
this->rootNode = NULL;
|
||||||
|
|
||||||
|
luaScript.beginCall("onLoad");
|
||||||
|
luaScript.endCall();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(const megaglest_runtime_error &ex) {
|
catch(const megaglest_runtime_error &ex) {
|
||||||
|
@ -1975,6 +1981,15 @@ bool ScriptManager::getSpeedChangeEnabled() {
|
||||||
void ScriptManager::addMessageToQueue(ScriptManagerMessage msg) {
|
void ScriptManager::addMessageToQueue(ScriptManagerMessage msg) {
|
||||||
messageQueue.push_back(msg);
|
messageQueue.push_back(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScriptManager::storeSaveGameData(string name, string value) {
|
||||||
|
luaSavedGameData[name] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
string ScriptManager::loadSaveGameData(string name) {
|
||||||
|
return luaSavedGameData[name];
|
||||||
|
}
|
||||||
|
|
||||||
// ========================== lua callbacks ===============================================
|
// ========================== lua callbacks ===============================================
|
||||||
|
|
||||||
int ScriptManager::showMessage(LuaHandle* luaHandle){
|
int ScriptManager::showMessage(LuaHandle* luaHandle){
|
||||||
|
@ -4828,6 +4843,47 @@ int ScriptManager::getSpeedChangeEnabled(LuaHandle* luaHandle) {
|
||||||
return luaArguments.getReturnCount();
|
return luaArguments.getReturnCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ScriptManager::storeSaveGameData(LuaHandle* luaHandle) {
|
||||||
|
LuaArguments luaArguments(luaHandle);
|
||||||
|
try {
|
||||||
|
thisScriptManager->storeSaveGameData(luaArguments.getString(-2),luaArguments.getString(-1));
|
||||||
|
}
|
||||||
|
catch(const megaglest_runtime_error &ex) {
|
||||||
|
char szErrBuf[8096]="";
|
||||||
|
snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
||||||
|
string sErrBuf = string(szErrBuf) + string("\nThe game may no longer be stable!\nerror [") + string(ex.what()) + string("]\n");
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str());
|
||||||
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str());
|
||||||
|
|
||||||
|
thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error",-1,-1,true));
|
||||||
|
thisScriptManager->onMessageBoxOk(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return luaArguments.getReturnCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
int ScriptManager::loadSaveGameData(LuaHandle* luaHandle) {
|
||||||
|
LuaArguments luaArguments(luaHandle);
|
||||||
|
try {
|
||||||
|
luaArguments.returnString(thisScriptManager->loadSaveGameData(luaArguments.getString(-1)));
|
||||||
|
}
|
||||||
|
catch(const megaglest_runtime_error &ex) {
|
||||||
|
char szErrBuf[8096]="";
|
||||||
|
snprintf(szErrBuf,8096,"In [%s::%s %d]",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
||||||
|
string sErrBuf = string(szErrBuf) + string("\nThe game may no longer be stable!\nerror [") + string(ex.what()) + string("]\n");
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugError,sErrBuf.c_str());
|
||||||
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,sErrBuf.c_str());
|
||||||
|
|
||||||
|
thisScriptManager->addMessageToQueue(ScriptManagerMessage(sErrBuf.c_str(), "error",-1,-1,true));
|
||||||
|
thisScriptManager->onMessageBoxOk(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return luaArguments.getReturnCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ScriptManager::saveGame(XmlNode *rootNode) {
|
void ScriptManager::saveGame(XmlNode *rootNode) {
|
||||||
std::map<string,string> mapTagReplacements;
|
std::map<string,string> mapTagReplacements;
|
||||||
XmlNode *scriptManagerNode = rootNode->addChild("ScriptManager");
|
XmlNode *scriptManagerNode = rootNode->addChild("ScriptManager");
|
||||||
|
@ -4836,7 +4892,18 @@ void ScriptManager::saveGame(XmlNode *rootNode) {
|
||||||
// string code;
|
// string code;
|
||||||
scriptManagerNode->addAttribute("code",code, mapTagReplacements);
|
scriptManagerNode->addAttribute("code",code, mapTagReplacements);
|
||||||
// LuaScript luaScript;
|
// LuaScript luaScript;
|
||||||
//
|
|
||||||
|
luaScript.beginCall("onSave");
|
||||||
|
luaScript.endCall();
|
||||||
|
for(std::map<string, string>::iterator iterMap = luaSavedGameData.begin();
|
||||||
|
iterMap != luaSavedGameData.end(); ++iterMap) {
|
||||||
|
|
||||||
|
XmlNode *savedGameDataItemNode = scriptManagerNode->addChild("SavedGameDataItem");
|
||||||
|
|
||||||
|
savedGameDataItemNode->addAttribute("key",iterMap->first, mapTagReplacements);
|
||||||
|
savedGameDataItemNode->addAttribute("value",iterMap->second, mapTagReplacements);
|
||||||
|
}
|
||||||
|
|
||||||
// //world
|
// //world
|
||||||
// World *world;
|
// World *world;
|
||||||
// GameCamera *gameCamera;
|
// GameCamera *gameCamera;
|
||||||
|
@ -4952,7 +5019,16 @@ void ScriptManager::loadGame(const XmlNode *rootNode) {
|
||||||
// string code;
|
// string code;
|
||||||
code = scriptManagerNode->getAttribute("code")->getValue();
|
code = scriptManagerNode->getAttribute("code")->getValue();
|
||||||
// LuaScript luaScript;
|
// LuaScript luaScript;
|
||||||
//
|
|
||||||
|
vector<XmlNode *> savedGameDataItemNodeList = scriptManagerNode->getChildList("SavedGameDataItem");
|
||||||
|
for(unsigned int i = 0; i < savedGameDataItemNodeList.size(); ++i) {
|
||||||
|
XmlNode *node = savedGameDataItemNodeList[i];
|
||||||
|
string key = node->getAttribute("key")->getValue();
|
||||||
|
string value = node->getAttribute("value")->getValue();
|
||||||
|
|
||||||
|
luaSavedGameData[key] = value;
|
||||||
|
}
|
||||||
|
|
||||||
// //world
|
// //world
|
||||||
// World *world;
|
// World *world;
|
||||||
// GameCamera *gameCamera;
|
// GameCamera *gameCamera;
|
||||||
|
|
|
@ -218,6 +218,8 @@ private:
|
||||||
RandomGen random;
|
RandomGen random;
|
||||||
const XmlNode *rootNode;
|
const XmlNode *rootNode;
|
||||||
|
|
||||||
|
std::map<string, string> luaSavedGameData;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static ScriptManager* thisScriptManager;
|
static ScriptManager* thisScriptManager;
|
||||||
|
|
||||||
|
@ -418,6 +420,10 @@ private:
|
||||||
void disableSpeedChange();
|
void disableSpeedChange();
|
||||||
void enableSpeedChange();
|
void enableSpeedChange();
|
||||||
bool getSpeedChangeEnabled();
|
bool getSpeedChangeEnabled();
|
||||||
|
void storeSaveGameData(string name, string value);
|
||||||
|
string loadSaveGameData(string name);
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------
|
||||||
|
|
||||||
//callbacks, commands
|
//callbacks, commands
|
||||||
static int networkShowMessageForFaction(LuaHandle* luaHandle);
|
static int networkShowMessageForFaction(LuaHandle* luaHandle);
|
||||||
|
@ -582,6 +588,9 @@ private:
|
||||||
static int disableSpeedChange(LuaHandle* luaHandle);
|
static int disableSpeedChange(LuaHandle* luaHandle);
|
||||||
static int enableSpeedChange(LuaHandle* luaHandle);
|
static int enableSpeedChange(LuaHandle* luaHandle);
|
||||||
static int getSpeedChangeEnabled(LuaHandle* luaHandle);
|
static int getSpeedChangeEnabled(LuaHandle* luaHandle);
|
||||||
|
|
||||||
|
static int storeSaveGameData(LuaHandle* luaHandle);
|
||||||
|
static int loadSaveGameData(LuaHandle* luaHandle);
|
||||||
};
|
};
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
|
Loading…
Reference in New Issue