Fixed incombatibility with old save files, closes #686

dev-time-step
krzys-h 2015-12-19 22:02:24 +01:00
parent 964d3574fd
commit 1dd230aaaf
3 changed files with 14 additions and 2 deletions

View File

@ -358,13 +358,21 @@ void CLevelParser::AddLine(CLevelParserLineUPtr line)
}
CLevelParserLine* CLevelParser::Get(const std::string& command)
{
CLevelParserLine* line = GetIfDefined(command);
if (line == nullptr)
throw CLevelParserException("Command not found: " + command);
return line;
}
CLevelParserLine* CLevelParser::GetIfDefined(const std::string& command)
{
for (auto& line : m_lines)
{
if (line->GetCommand() == command)
return line.get();
}
throw CLevelParserException("Command not found: " + command);
return nullptr;
}
int CLevelParser::CountLines(const std::string& command)

View File

@ -88,6 +88,9 @@ public:
//! Find first line with given command
CLevelParserLine* Get(const std::string& command);
//! Find first line with given command, null if doesn't exist
CLevelParserLine* GetIfDefined(const std::string &command);
//! Count lines with given command
int CountLines(const std::string& command);

View File

@ -451,7 +451,8 @@ std::vector<SavedScene> CPlayerProfile::GetSavedSceneList()
{
CLevelParser levelParser(savegameFile);
levelParser.Load();
int time = levelParser.Get("Created")->GetParam("date")->AsInt();
CLevelParserLine* line = levelParser.GetIfDefined("Created");
int time = line != nullptr ? line->GetParam("date")->AsInt() : 0;
sortedSaveDirs[time] = SavedScene(GetSaveFile(dir), levelParser.Get("Title")->GetParam("text")->AsString());
}
}