MCPcopy Create free account
hub / github.com/Open-GD/OpenGD / onHttpRequestCompleted

Method onHttpRequestCompleted

Source/LevelBrowserLayer.cpp:192–263  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

190}
191
192void LevelBrowserLayer::onHttpRequestCompleted(ax::network::HttpClient* sender, ax::network::HttpResponse* response)
193{
194 if (this)
195 {
196 listView->removeAllItems();
197 _loading->setVisible(false);
198 if (auto str = GameToolbox::getResponse(response))
199 {
200 GameToolbox::log("{}", *str);
201 //error codes -1, -2 etc
202 if((*str).length() < 5)
203 return;
204
205 auto splits = GameToolbox::splitByDelimStringView((*str), '#');
206 auto levels = GameToolbox::splitByDelimStringView(splits[0], '|');
207 auto authorsStrings = GameToolbox::splitByDelimStringView(splits[1], '|');
208 auto songsStrings = GameToolbox::splitByDelimStringView(splits[2], ':');
209
210 std::vector<std::vector<std::string_view>> authors, songs;
211 authors.reserve(authorsStrings.size()); //pre-allocate enough memory
212 songs.reserve(songsStrings.size());
213 // songs.reserve(songsStrings.size());
214 for(const std::string_view aStr : authorsStrings) {
215 authors.push_back(std::move(GameToolbox::splitByDelimStringView(aStr, ':')));
216 }
217
218 for(const std::string_view aStr : songsStrings) {
219 songs.push_back(std::move(GameToolbox::splitByDelimStringView(aStr, '|')));
220 }
221
222 auto getAuthor = [&](GJGameLevel* gjlevel) -> std::string_view
223 {
224 for(const auto& author : authors)
225 {
226 if(GameToolbox::stoi(author[0]) == gjlevel->_playerID)
227 return author[1];
228 }
229 return "-";
230 };
231
232 auto getSong = [&](GJGameLevel* gjlevel) -> std::string_view
233 {
234 // for(const auto& song : songs)
235 // {
236 // // for(auto s : song) GameToolbox::log("\n{}", s);
237 // // if(GameToolbox::stoi(song[0]) == gjlevel->_playerID)
238 // // return song[1];
239 // }
240 return "Cool catchy song";
241 };
242
243 std::vector<GJGameLevel*> toInsert;
244 toInsert.reserve(levels.size()); //pre-allocate enough memory
245
246 for (size_t i = 0; i < levels.size(); i++)
247 {
248 auto gjlevel = GJGameLevel::createWithResponse(levels[i]);
249 gjlevel->_levelCreator = getAuthor(gjlevel);

Callers

nothing calls this directly

Calls 2

logFunction · 0.85
sizeMethod · 0.80

Tested by

no test coverage detected