diff options
Diffstat (limited to 'src/object')
-rw-r--r-- | src/object/level/parser.cpp | 31 | ||||
-rw-r--r-- | src/object/level/parserparam.cpp | 15 | ||||
-rw-r--r-- | src/object/level/parserparam.h | 5 | ||||
-rw-r--r-- | src/object/robotmain.cpp | 14 | ||||
-rw-r--r-- | src/object/robotmain.h | 2 |
5 files changed, 41 insertions, 26 deletions
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 <string> #include <exception> #include <sstream> @@ -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<typename T> T Cast(std::string value, std::string requestedType); template<typename T> 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); diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp index ce7f8d0..315ffe1 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -3874,7 +3874,6 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject) int rank = m_dialog->GetSceneRank(); const char* read = m_dialog->GetSceneRead().c_str(); const char* stack = m_dialog->GetStackRead().c_str(); - m_dialog->SetUserDir(base, rank); m_fixScene = fixScene; @@ -7137,16 +7136,7 @@ void CRobotMain::DisplayError(Error err, Math::Vector goal, float height, float m_displayText->DisplayError(err, goal, height, dist, time); } -void CRobotMain::InjectLevelDir(std::string& path, const std::string defaultDir) +std::string& CRobotMain::GetUserLevelName(int id) { - std::string oldPath = path; - std::string lvlDir; - CRobotMain::GetInstancePointer()->BuildSceneName(lvlDir, CRobotMain::GetInstancePointer()->GetSceneName(), CRobotMain::GetInstancePointer()->GetSceneRank(), false); - boost::replace_all(path, "%lvl%", lvlDir); - if(path == oldPath) - { - path = defaultDir + "/" + path; - } - std::string langStr(1, CApplication::GetInstancePointer()->GetLanguageChar()); - boost::replace_all(path, "%lng%", langStr); + return m_dialog->GetUserLevelName(id); } diff --git a/src/object/robotmain.h b/src/object/robotmain.h index f9bf131..466c47d 100644 --- a/src/object/robotmain.h +++ b/src/object/robotmain.h @@ -390,7 +390,7 @@ public: void DisplayError(Error err, CObject* pObj, float time=10.0f); void DisplayError(Error err, Math::Vector goal, float height=15.0f, float dist=60.0f, float time=10.0f); - static void InjectLevelDir(std::string& path, const std::string defaultDir = ""); + std::string& GetUserLevelName(int id); protected: bool EventFrame(const Event &event); |