Fixed %lvl% in saved games, closes #586

master
krzys-h 2015-08-24 20:08:04 +02:00
parent 8ff6fadb75
commit 39d2236be6
3 changed files with 18 additions and 13 deletions

View File

@ -52,26 +52,20 @@ CLevelParser::CLevelParser()
} }
CLevelParser::CLevelParser(std::string filename) CLevelParser::CLevelParser(std::string filename)
: CLevelParser()
{ {
m_filename = filename; m_filename = filename;
m_pathCat = "";
m_pathChap = "";
m_pathLvl = "";
} }
CLevelParser::CLevelParser(std::string category, int chapter, int rank) CLevelParser::CLevelParser(std::string category, int chapter, int rank)
{ : CLevelParser(BuildScenePath(category, chapter, rank))
m_filename = BuildScenePath(category, chapter, rank); {}
m_pathCat = BuildCategoryPath(category);
m_pathChap = BuildScenePath(category, chapter, 0, false);
m_pathLvl = BuildScenePath(category, chapter, rank, false);
}
CLevelParser::CLevelParser(LevelCategory category, int chapter, int rank) CLevelParser::CLevelParser(LevelCategory category, int chapter, int rank)
: CLevelParser(GetLevelCategoryDir(category), chapter, rank) : CLevelParser(GetLevelCategoryDir(category), chapter, rank)
{} {
SetLevelPaths(category, chapter, rank);
}
std::string CLevelParser::BuildCategoryPath(std::string category) std::string CLevelParser::BuildCategoryPath(std::string category)
{ {
@ -320,6 +314,13 @@ void CLevelParser::Save()
file.close(); file.close();
} }
void CLevelParser::SetLevelPaths(LevelCategory category, int chapter, int rank)
{
m_pathCat = BuildCategoryPath(category);
m_pathChap = chapter != 0 ? BuildScenePath(category, chapter, 0, false) : "";
m_pathLvl = chapter != 0 && rank != 0 ? BuildScenePath(category, chapter, rank, false) : "";
}
std::string CLevelParser::InjectLevelPaths(const std::string& path, const std::string& defaultDir) std::string CLevelParser::InjectLevelPaths(const std::string& path, const std::string& defaultDir)
{ {
std::string newPath = path; std::string newPath = path;

View File

@ -69,6 +69,8 @@ public:
//! Save file //! Save file
void Save(); void Save();
//! Configure level paths for the given level
void SetLevelPaths(LevelCategory category, int chapter = 0, int rank = 0);
//! Inject %something% paths //! Inject %something% paths
std::string InjectLevelPaths(const std::string& path, const std::string& defaultDir = ""); std::string InjectLevelPaths(const std::string& path, const std::string& defaultDir = "");
@ -102,6 +104,7 @@ private:
inline std::string InjectLevelPathsForCurrentLevel(const std::string& path, const std::string& defaultDir = "") inline std::string InjectLevelPathsForCurrentLevel(const std::string& path, const std::string& defaultDir = "")
{ {
CRobotMain* main = CRobotMain::GetInstancePointer(); CRobotMain* main = CRobotMain::GetInstancePointer();
auto levelParser = MakeUnique<CLevelParser>(main->GetLevelCategory(), main->GetLevelChap(), main->GetLevelRank()); auto levelParser = MakeUnique<CLevelParser>();
levelParser->SetLevelPaths(main->GetLevelCategory(), main->GetLevelChap(), main->GetLevelRank());
return levelParser->InjectLevelPaths(path, defaultDir); return levelParser->InjectLevelPaths(path, defaultDir);
} }

View File

@ -4740,6 +4740,7 @@ CObject* CRobotMain::IOReadScene(std::string filename, std::string filecbot)
std::string dirname = filename.substr(0, filename.find_last_of("/")); std::string dirname = filename.substr(0, filename.find_last_of("/"));
CLevelParser levelParser(filename); CLevelParser levelParser(filename);
levelParser.SetLevelPaths(m_levelCategory, m_levelChap, m_levelRank);
levelParser.Load(); levelParser.Load();
int numObjects = levelParser.CountLines("CreateObject") + levelParser.CountLines("CreatePower") + levelParser.CountLines("CreateFret"); int numObjects = levelParser.CountLines("CreateObject") + levelParser.CountLines("CreatePower") + levelParser.CountLines("CreateFret");