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,16 +172,16 @@ void CPathManager::LoadModsFromDir(const std::string &dir)
std::string CPathManager::InjectLevelDir(std::string path, const std::string& defaultDir)
{
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);
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);
std::string catDir = CLevelParser::BuildCategoryPath(CRobotMain::GetInstancePointer()->GetSceneName());
boost::replace_all(newPath, "%cat%", catDir);
if(newPath == path && !path.empty())
{
newPath = defaultDir + (!defaultDir.empty() ? "/" : "") + newPath;
}
//TODO: %cat%
std::string langPath = newPath;
std::string langStr(1, CApplication::GetInstancePointer()->GetLanguageChar());

View File

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

View File

@ -43,8 +43,10 @@ public:
~CLevelParser();
//! Build category path
static std::string BuildCategoryPath(std::string category);
//! 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
bool Exists();

View File

@ -5850,9 +5850,9 @@ int CRobotMain::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();
char* GetSceneName();
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 StartPauseMusic(PauseType pause);

View File

@ -3339,13 +3339,13 @@ void CMainDialog::NiceParticle(Math::Point mouse, bool bPress)
// 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
int chapter = 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.
@ -3983,7 +3983,7 @@ void CMainDialog::IOReadName()
//TODO: CLevelParser
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_i18n, "Title.%c", m_app->GetLanguageChar() );

View File

@ -98,7 +98,7 @@ public:
bool GetNiceReset();
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);
std::string & GetFilesDir();