Implemented %cat%

and renamed BuildSceneName to BuildScenePath
master
krzys-h 2015-03-22 13:51:14 +01:00
parent 47ed73247b
commit d2d0886b76
7 changed files with 33 additions and 18 deletions

View File

@ -172,17 +172,17 @@ void CPathManager::LoadModsFromDir(const std::string &dir)
std::string CPathManager::InjectLevelDir(std::string path, const std::string& defaultDir) std::string CPathManager::InjectLevelDir(std::string path, const std::string& defaultDir)
{ {
std::string newPath = path; std::string newPath = path;
std::string lvlDir = CLevelParser::BuildSceneName(CRobotMain::GetInstancePointer()->GetSceneName(), CRobotMain::GetInstancePointer()->GetSceneRank()/100, CRobotMain::GetInstancePointer()->GetSceneRank()%100, false); std::string lvlDir = CLevelParser::BuildScenePath(CRobotMain::GetInstancePointer()->GetSceneName(), CRobotMain::GetInstancePointer()->GetSceneRank()/100, CRobotMain::GetInstancePointer()->GetSceneRank()%100, false);
boost::replace_all(newPath, "%lvl%", lvlDir); boost::replace_all(newPath, "%lvl%", lvlDir);
std::string chapDir = CLevelParser::BuildSceneName(CRobotMain::GetInstancePointer()->GetSceneName(), CRobotMain::GetInstancePointer()->GetSceneRank()/100, 0, false); std::string chapDir = CLevelParser::BuildScenePath(CRobotMain::GetInstancePointer()->GetSceneName(), CRobotMain::GetInstancePointer()->GetSceneRank()/100, 0, false);
boost::replace_all(newPath, "%chap%", chapDir); boost::replace_all(newPath, "%chap%", chapDir);
std::string catDir = CLevelParser::BuildCategoryPath(CRobotMain::GetInstancePointer()->GetSceneName());
boost::replace_all(newPath, "%cat%", catDir);
if(newPath == path && !path.empty()) if(newPath == path && !path.empty())
{ {
newPath = defaultDir + (!defaultDir.empty() ? "/" : "") + newPath; newPath = defaultDir + (!defaultDir.empty() ? "/" : "") + newPath;
} }
//TODO: %cat%
std::string langPath = newPath; std::string langPath = newPath;
std::string langStr(1, CApplication::GetInstancePointer()->GetLanguageChar()); std::string langStr(1, CApplication::GetInstancePointer()->GetLanguageChar());
boost::replace_all(langPath, "%lng%", langStr); boost::replace_all(langPath, "%lng%", langStr);

View File

@ -51,7 +51,7 @@ CLevelParser::CLevelParser(std::string filename)
CLevelParser::CLevelParser(std::string category, int chapter, int rank) CLevelParser::CLevelParser(std::string category, int chapter, int rank)
{ {
m_filename = BuildSceneName(category, chapter, rank); m_filename = BuildScenePath(category, chapter, rank);
} }
CLevelParser::~CLevelParser() CLevelParser::~CLevelParser()
@ -62,12 +62,27 @@ CLevelParser::~CLevelParser()
} }
} }
std::string CLevelParser::BuildSceneName(std::string category, int chapter, int rank, bool sceneFile) std::string CLevelParser::BuildCategoryPath(std::string category)
{ {
std::ostringstream outstream; std::ostringstream outstream;
outstream << "levels/";
if(category == "perso" || category == "win" || category == "lost")
{
outstream << "other/";
}
else
{
outstream << category << "/";
}
return outstream.str();
}
std::string CLevelParser::BuildScenePath(std::string category, int chapter, int rank, bool sceneFile)
{
std::ostringstream outstream;
outstream << BuildCategoryPath(category);
if(category == "custom") if(category == "custom")
{ {
outstream << "levels/custom/";
outstream << CRobotMain::GetInstancePointer()->GetUserLevelName(chapter); outstream << CRobotMain::GetInstancePointer()->GetUserLevelName(chapter);
if(rank == 000) if(rank == 000)
{ {
@ -87,16 +102,14 @@ std::string CLevelParser::BuildSceneName(std::string category, int chapter, int
} }
else if(category == "perso") else if(category == "perso")
{ {
outstream << "levels/other/perso.txt"; outstream << "perso.txt";
} }
else if(category == "win" || category == "lost") else if(category == "win" || category == "lost")
{ {
outstream << "levels/other/";
outstream << category << std::setfill('0') << std::setw(3) << chapter*100+rank << ".txt"; outstream << category << std::setfill('0') << std::setw(3) << chapter*100+rank << ".txt";
} }
else else
{ {
outstream << "levels/" << category << "/";
outstream << "chapter" << std::setfill('0') << std::setw(3) << chapter; outstream << "chapter" << std::setfill('0') << std::setw(3) << chapter;
if(rank == 000) if(rank == 000)
{ {

View File

@ -43,8 +43,10 @@ public:
~CLevelParser(); ~CLevelParser();
//! Build category path
static std::string BuildCategoryPath(std::string category);
//! Build level filename //! Build level filename
static std::string BuildSceneName(std::string category, int chapter, int rank, bool sceneFile = true); static std::string BuildScenePath(std::string category, int chapter, int rank, bool sceneFile = true);
//! Check if level file exists //! Check if level file exists
bool Exists(); bool Exists();

View File

@ -5850,9 +5850,9 @@ int CRobotMain::GetSceneRank()
return m_dialog->GetSceneRank(); return m_dialog->GetSceneRank();
} }
void CRobotMain::BuildSceneName(std::string &filename, char *base, int rank, bool sceneFile) void CRobotMain::BuildScenePath(std::string &filename, char *base, int rank, bool sceneFile)
{ {
m_dialog->BuildSceneName(filename, base, rank, sceneFile); m_dialog->BuildScenePath(filename, base, rank, sceneFile);
} }

View File

@ -293,7 +293,7 @@ public:
float GetPersoAngle(); float GetPersoAngle();
char* GetSceneName(); char* GetSceneName();
int GetSceneRank(); int GetSceneRank();
void BuildSceneName(std::string &filename, char *base, int rank, bool sceneFile = true); void BuildScenePath(std::string &filename, char *base, int rank, bool sceneFile = true);
void StartMusic(); void StartMusic();
void StartPauseMusic(PauseType pause); void StartPauseMusic(PauseType pause);

View File

@ -3339,13 +3339,13 @@ void CMainDialog::NiceParticle(Math::Point mouse, bool bPress)
// Builds the file name of a mission. // Builds the file name of a mission.
void CMainDialog::BuildSceneName(std::string &filename, char *base, int rank, bool sceneFile) void CMainDialog::BuildScenePath(std::string &filename, char *base, int rank, bool sceneFile)
{ {
//TODO: Support for more than 9 chapters //TODO: Support for more than 9 chapters
int chapter = rank/100; int chapter = rank/100;
int new_rank = rank%100; int new_rank = rank%100;
filename = CLevelParser::BuildSceneName(std::string(base), chapter, new_rank, sceneFile); filename = CLevelParser::BuildScenePath(std::string(base), chapter, new_rank, sceneFile);
} }
// Built the default descriptive name of a mission. // Built the default descriptive name of a mission.
@ -3983,7 +3983,7 @@ void CMainDialog::IOReadName()
//TODO: CLevelParser //TODO: CLevelParser
sprintf(resume, "%s %d", m_sceneName, m_chap[m_index]+1); sprintf(resume, "%s %d", m_sceneName, m_chap[m_index]+1);
BuildSceneName(filename, m_sceneName, (m_chap[m_index]+1)*100); BuildScenePath(filename, m_sceneName, (m_chap[m_index]+1)*100);
sprintf(op, "Title.E"); sprintf(op, "Title.E");
sprintf(op_i18n, "Title.%c", m_app->GetLanguageChar() ); sprintf(op_i18n, "Title.%c", m_app->GetLanguageChar() );

View File

@ -98,7 +98,7 @@ public:
bool GetNiceReset(); bool GetNiceReset();
bool GetHimselfDamage(); bool GetHimselfDamage();
void BuildSceneName(std::string &filename, char *base, int rank, bool sceneFile = true); void BuildScenePath(std::string &filename, char *base, int rank, bool sceneFile = true);
void BuildResumeName(char *filename, char *base, int rank); void BuildResumeName(char *filename, char *base, int rank);
std::string & GetFilesDir(); std::string & GetFilesDir();