Merge pull request #1498 from rasmusgo/dev-loadgame-arg
Load game from command linefix-squashed-planets
commit
4541db7f21
|
@ -246,6 +246,7 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[])
|
|||
OPT_DEBUG,
|
||||
OPT_RUNSCENE,
|
||||
OPT_SCENETEST,
|
||||
OPT_LOADSAVE,
|
||||
OPT_LOGLEVEL,
|
||||
OPT_LANGDIR,
|
||||
OPT_DATADIR,
|
||||
|
@ -264,6 +265,7 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[])
|
|||
{ "debug", required_argument, nullptr, OPT_DEBUG },
|
||||
{ "runscene", required_argument, nullptr, OPT_RUNSCENE },
|
||||
{ "scenetest", no_argument, nullptr, OPT_SCENETEST },
|
||||
{ "loadsave", required_argument, nullptr, OPT_LOADSAVE },
|
||||
{ "loglevel", required_argument, nullptr, OPT_LOGLEVEL },
|
||||
{ "langdir", required_argument, nullptr, OPT_LANGDIR },
|
||||
{ "datadir", required_argument, nullptr, OPT_DATADIR },
|
||||
|
@ -309,6 +311,7 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[])
|
|||
GetLogger()->Message(" -debug modes enable debug modes (more info printed in logs; see code for reference of modes)\n");
|
||||
GetLogger()->Message(" -runscene sceneNNN run given scene on start\n");
|
||||
GetLogger()->Message(" -scenetest win every mission right after it's loaded\n");
|
||||
GetLogger()->Message(" -loadsave path load given saved game on start (path is <player>/<save>\n");
|
||||
GetLogger()->Message(" -loglevel level set log level to level (one of: trace, debug, info, warn, error, none)\n");
|
||||
GetLogger()->Message(" -langdir path set custom language directory path\n");
|
||||
GetLogger()->Message(" environment variable: COLOBOT_LANG_DIR\n");
|
||||
|
@ -366,6 +369,22 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[])
|
|||
m_sceneTest = true;
|
||||
break;
|
||||
}
|
||||
case OPT_LOADSAVE:
|
||||
{
|
||||
std::string playerAndPath = optarg;
|
||||
size_t pos = playerAndPath.find_first_of("/");
|
||||
if (pos != std::string::npos && pos > 0 && pos+1 < playerAndPath.length()) // Split player name from path
|
||||
{
|
||||
m_loadSavePlayerName = playerAndPath.substr(0, pos);
|
||||
m_loadSaveDirName = playerAndPath.substr(pos+1, playerAndPath.length()-pos-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
GetLogger()->Error("Invalid path: '%s'\n", optarg);
|
||||
return PARSE_ARGS_FAIL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case OPT_LOGLEVEL:
|
||||
{
|
||||
LogLevel logLevel;
|
||||
|
@ -698,8 +717,15 @@ bool CApplication::Create()
|
|||
|
||||
StartLoadingMusic();
|
||||
|
||||
if (m_runSceneCategory == LevelCategory::Max)
|
||||
if (!m_loadSaveDirName.empty())
|
||||
{
|
||||
m_controller->GetRobotMain()->SelectPlayer(m_loadSavePlayerName);
|
||||
m_controller->GetRobotMain()->LoadSaveFromDirName(m_loadSaveDirName);
|
||||
}
|
||||
else if (m_runSceneCategory == LevelCategory::Max)
|
||||
{
|
||||
m_controller->StartApp();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_controller->GetRobotMain()->UpdateCustomLevelList(); // To load the userlevels
|
||||
|
|
|
@ -405,6 +405,10 @@ protected:
|
|||
int m_runSceneRank;
|
||||
//@}
|
||||
|
||||
//! Game to load on startup
|
||||
std::string m_loadSavePlayerName;
|
||||
std::string m_loadSaveDirName;
|
||||
|
||||
//! Scene test mode
|
||||
bool m_sceneTest;
|
||||
|
||||
|
|
|
@ -525,7 +525,7 @@ void CPlayerProfile::LoadScene(std::string dir)
|
|||
CLevelParserLine* line = levelParser.Get("Mission");
|
||||
cat = GetLevelCategoryFromDir(line->GetParam("base")->AsString());
|
||||
|
||||
if (dir == "../../crashsave")
|
||||
if(!m_levelInfoLoaded[cat])
|
||||
LoadFinishedLevels(cat);
|
||||
|
||||
rank = line->GetParam("rank")->AsInt();
|
||||
|
|
|
@ -5839,6 +5839,17 @@ void CRobotMain::QuickLoad()
|
|||
m_playerProfile->LoadScene(dir);
|
||||
}
|
||||
|
||||
void CRobotMain::LoadSaveFromDirName(const std::string& gameDir)
|
||||
{
|
||||
std::string dir = m_playerProfile->GetSaveFile(gameDir);
|
||||
if(!CResourceManager::Exists(dir))
|
||||
{
|
||||
GetLogger()->Error("Save slot not found\n");
|
||||
return;
|
||||
}
|
||||
m_playerProfile->LoadScene(dir);
|
||||
}
|
||||
|
||||
void CRobotMain::SetExitAfterMission(bool exit)
|
||||
{
|
||||
m_exitAfterMission = exit;
|
||||
|
|
|
@ -368,6 +368,9 @@ public:
|
|||
//! Enable mode where completing mission closes the game
|
||||
void SetExitAfterMission(bool exit);
|
||||
|
||||
//! Load saved game (used by command line argument)
|
||||
void LoadSaveFromDirName(const std::string& gameDir);
|
||||
|
||||
//! Returns true if player can interact with things manually
|
||||
bool CanPlayerInteract();
|
||||
|
||||
|
|
Loading…
Reference in New Issue