| 136 | } |
| 137 | |
| 138 | bool loadGamesFromFile(const char* config) { |
| 139 | endCond = eTimedGame; |
| 140 | timeLimit = 30.0 * 60.0; |
| 141 | scoreCapLimit = 10; |
| 142 | |
| 143 | startTime = -1; |
| 144 | currentIndex = -1; |
| 145 | cycleMode = eLoopInf; |
| 146 | |
| 147 | std::vector<std::string> lines = getFileTextLines(config); |
| 148 | if (!lines.size()) { |
| 149 | return false; |
| 150 | } |
| 151 | |
| 152 | for (unsigned int i = 0; i < (unsigned int)lines.size(); i++) { |
| 153 | std::string line = lines[i]; |
| 154 | |
| 155 | std::vector<std::string> params = tokenize(line, std::string(","), 0, true); |
| 156 | |
| 157 | if (params.size()) { |
| 158 | if (compare_nocase(params[0], "mode") == 0) { |
| 159 | if (params.size() > 1) { |
| 160 | endCond = condFromString(params[1]); |
| 161 | } |
| 162 | if (params.size() > 2) { |
| 163 | if (endCond == eTimedGame) { |
| 164 | timeLimit = fabs(atof(params[2].c_str())) * 60.0; |
| 165 | } |
| 166 | else { |
| 167 | scoreCapLimit = atoi(params[2].c_str()); |
| 168 | } |
| 169 | |
| 170 | if (timeLimit == 0.0) { |
| 171 | timeLimit = 30; |
| 172 | } |
| 173 | |
| 174 | if (scoreCapLimit <= 0) { |
| 175 | scoreCapLimit = 10; |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | if (params.size() > 3) { |
| 180 | cycleMode = cycleFromString(params[3]); |
| 181 | } |
| 182 | } |
| 183 | else { |
| 184 | Game game; |
| 185 | game.mapFile = params[0]; |
| 186 | if (params.size() > 1) { |
| 187 | game.publicText = params[1]; |
| 188 | } |
| 189 | |
| 190 | gameList.push_back(game); |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | return gameList.size() > 0; |
| 195 | } |
no test coverage detected