From de375548ade0015f6466fae74dc1fe9bba7c8357 Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 26 Sep 2014 20:53:11 +0200 Subject: Userlevel listing --- src/object/level/parser.cpp | 31 +++++++++++++++++++++++++------ src/object/level/parserparam.cpp | 15 ++++++++++----- src/object/level/parserparam.h | 5 +++-- 3 files changed, 38 insertions(+), 13 deletions(-) (limited to 'src/object/level') diff --git a/src/object/level/parser.cpp b/src/object/level/parser.cpp index 89059d0..e73142e 100644 --- a/src/object/level/parser.cpp +++ b/src/object/level/parser.cpp @@ -23,6 +23,8 @@ #include "object/level/parserexceptions.h" +#include "object/robotmain.h" + #include #include #include @@ -57,12 +59,25 @@ CLevelParser::~CLevelParser() std::string CLevelParser::BuildSceneName(std::string category, int chapter, int rank, bool sceneFile) { std::ostringstream outstream; - if(category == "user") + if(category == "custom") { - //TODO: Change this to point user dir according to operating system - /*rankStream << std::setfill('0') << std::setw(2) << rank%100; - filename = m_userDir + "/" + m_userList[rank/100-1] + "/" + rankStream.str() + ".txt";*/ - assert(false); //TODO: Userlevel support + outstream << "levels/custom/"; + outstream << CRobotMain::GetInstancePointer()->GetUserLevelName(chapter) << "/"; + if(rank == 000) + { + if(sceneFile) + { + outstream << "/chaptertitle.txt"; + } + } + else + { + outstream << "/level" << std::setfill('0') << std::setw(3) << rank; + if(sceneFile) + { + outstream << "/scene.txt"; + } + } } else if(category == "perso") { @@ -217,5 +232,9 @@ void CLevelParser::AddLine(CLevelParserLine* line) CLevelParserLine* CLevelParser::Get(std::string command) { - assert(false); //TODO + for(auto& line : m_lines) { + if(line->GetCommand() == command) + return line; + } + throw CLevelParserException("Command not found: "+command); } \ No newline at end of file diff --git a/src/object/level/parserparam.cpp b/src/object/level/parserparam.cpp index ec043b4..39a953b 100644 --- a/src/object/level/parserparam.cpp +++ b/src/object/level/parserparam.cpp @@ -168,9 +168,6 @@ std::string CLevelParserParam::InjectLevelDir(std::string path, const std::strin if(newPath == path) { newPath = defaultDir + (!defaultDir.empty() ? "/" : "") + newPath; - } else { - if(defaultDir == "") - throw CLevelParserException("TODO: Param "+m_name+" does not yet support %lvl%! :("); } //TODO: Fallback to English std::string langStr(1, CApplication::GetInstancePointer()->GetLanguageChar()); @@ -178,12 +175,20 @@ std::string CLevelParserParam::InjectLevelDir(std::string path, const std::strin return newPath; } +std::string CLevelParserParam::ToPath(std::string path, const std::string defaultDir) +{ + if(defaultDir == "" && path.find("%lvl%") != std::string::npos) + throw CLevelParserException("TODO: Param "+m_name+" does not yet support %lvl%! :("); + + return InjectLevelDir(path, defaultDir); +} + std::string CLevelParserParam::AsPath(const std::string defaultDir) { if(m_empty) throw CLevelParserExceptionMissingParam(this); - return InjectLevelDir(AsString(), defaultDir); + return ToPath(AsString(), defaultDir); } std::string CLevelParserParam::AsPath(const std::string defaultDir, std::string def) @@ -191,7 +196,7 @@ std::string CLevelParserParam::AsPath(const std::string defaultDir, std::string if(m_empty) return InjectLevelDir(def, defaultDir); - return InjectLevelDir(AsString(def), defaultDir); + return ToPath(AsString(def), defaultDir); } diff --git a/src/object/level/parserparam.h b/src/object/level/parserparam.h index 9d5ba99..93865a2 100644 --- a/src/object/level/parserparam.h +++ b/src/object/level/parserparam.h @@ -103,14 +103,15 @@ public: std::string GetValue(); bool IsDefined(); + static std::string InjectLevelDir(std::string path, const std::string defaultDir); + private: void ParseArray(); template T Cast(std::string value, std::string requestedType); template T Cast(std::string requestedType); - std::string InjectLevelDir(std::string path, const std::string defaultDir); - + std::string ToPath(std::string path, const std::string defaultDir); ObjectType ToObjectType(std::string value); DriveType ToDriveType(std::string value); ToolType ToToolType(std::string value); -- cgit v1.2.3-1-g7c22