[colobot] 151/377: Fixed incombatibility with old save files, closes #686

Didier Raboud odyx at moszumanska.debian.org
Wed Mar 30 13:34:09 UTC 2016


This is an automated email from the git hooks/post-receive script.

odyx pushed a commit to branch debian/master
in repository colobot.

commit 1dd230aaafcfc4f372c9dbe7dad4c94148b0077d
Author: krzys-h <krzys_h at interia.pl>
Date:   Sat Dec 19 22:02:24 2015 +0100

    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 a3a7fe5..f0356bc 100644
--- a/src/level/parser/parser.cpp
+++ b/src/level/parser/parser.cpp
@@ -359,12 +359,20 @@ 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 4d78c59..7b6a314 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 2d6c8f5..d611718 100644
--- a/src/level/player_profile.cpp
+++ b/src/level/player_profile.cpp
@@ -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());
         }
     }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git



More information about the Pkg-games-commits mailing list