From 1dd230aaafcfc4f372c9dbe7dad4c94148b0077d Mon Sep 17 00:00:00 2001 From: krzys-h Date: Sat, 19 Dec 2015 22:02:24 +0100 Subject: [PATCH] Fixed incombatibility with old save files, closes #686 --- src/level/parser/parser.cpp | 10 +++++++++- src/level/parser/parser.h | 3 +++ src/level/player_profile.cpp | 3 ++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/level/parser/parser.cpp b/src/level/parser/parser.cpp index a3a7fe5a..f0356bca 100644 --- a/src/level/parser/parser.cpp +++ b/src/level/parser/parser.cpp @@ -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) diff --git a/src/level/parser/parser.h b/src/level/parser/parser.h index 4d78c59d..7b6a3148 100644 --- a/src/level/parser/parser.h +++ b/src/level/parser/parser.h @@ -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); diff --git a/src/level/player_profile.cpp b/src/level/player_profile.cpp index 2d6c8f57..d611718d 100644 --- a/src/level/player_profile.cpp +++ b/src/level/player_profile.cpp @@ -451,7 +451,8 @@ std::vector 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()); } }