| 48 | } |
| 49 | |
| 50 | void CAutoMapper::Load(const char *pTileName) |
| 51 | { |
| 52 | char aPath[IO_MAX_PATH_LENGTH]; |
| 53 | str_format(aPath, sizeof(aPath), "editor/automap/%s.rules", pTileName); |
| 54 | if(!Storage()->FileExists(aPath, IStorage::TYPE_ALL)) |
| 55 | { |
| 56 | return; // Avoid error message if no rules exist |
| 57 | } |
| 58 | |
| 59 | CLineReader LineReader; |
| 60 | if(!LineReader.OpenFile(Storage()->OpenFile(aPath, IOFLAG_READ, IStorage::TYPE_ALL))) |
| 61 | { |
| 62 | log_error("editor/automap", "Failed to load rules from '%s'", aPath); |
| 63 | return; |
| 64 | } |
| 65 | |
| 66 | CConfiguration *pCurrentConf = nullptr; |
| 67 | CRun *pCurrentRun = nullptr; |
| 68 | CIndexRule *pCurrentIndex = nullptr; |
| 69 | |
| 70 | // read each line |
| 71 | while(const char *pLine = LineReader.Get()) |
| 72 | { |
| 73 | // skip blank/empty lines as well as comments |
| 74 | if(str_length(pLine) > 0 && pLine[0] != '#' && pLine[0] != '\n' && pLine[0] != '\r' && pLine[0] != '\t' && pLine[0] != '\v' && pLine[0] != ' ') |
| 75 | { |
| 76 | if(pLine[0] == '[') |
| 77 | { |
| 78 | // new configuration, get the name |
| 79 | pLine++; |
| 80 | CConfiguration NewConf; |
| 81 | NewConf.m_aName[0] = '\0'; |
| 82 | NewConf.m_StartX = 0; |
| 83 | NewConf.m_StartY = 0; |
| 84 | NewConf.m_EndX = 0; |
| 85 | NewConf.m_EndY = 0; |
| 86 | m_vConfigs.push_back(NewConf); |
| 87 | int ConfigurationId = m_vConfigs.size() - 1; |
| 88 | pCurrentConf = &m_vConfigs[ConfigurationId]; |
| 89 | str_copy(pCurrentConf->m_aName, pLine, minimum<int>(sizeof(pCurrentConf->m_aName), str_length(pLine))); |
| 90 | |
| 91 | // add start run |
| 92 | CRun NewRun; |
| 93 | NewRun.m_AutomapCopy = true; |
| 94 | pCurrentConf->m_vRuns.push_back(NewRun); |
| 95 | int RunId = pCurrentConf->m_vRuns.size() - 1; |
| 96 | pCurrentRun = &pCurrentConf->m_vRuns[RunId]; |
| 97 | } |
| 98 | else if(str_startswith(pLine, "NewRun") && pCurrentConf) |
| 99 | { |
| 100 | // add new run |
| 101 | CRun NewRun; |
| 102 | NewRun.m_AutomapCopy = true; |
| 103 | pCurrentConf->m_vRuns.push_back(NewRun); |
| 104 | int RunId = pCurrentConf->m_vRuns.size() - 1; |
| 105 | pCurrentRun = &pCurrentConf->m_vRuns[RunId]; |
| 106 | } |
| 107 | else if(str_startswith(pLine, "Index") && pCurrentRun) |
nothing calls this directly
no test coverage detected