Skip to content

Commit

Permalink
yeah
Browse files Browse the repository at this point in the history
  • Loading branch information
AdyaGMD authored Jun 15, 2024
1 parent fe5107d commit f5051a8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 40 deletions.
8 changes: 5 additions & 3 deletions mod.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"geode": "2.0.0-beta.25",
"version": "v1.1.6",
"gd": "2.204",
"geode": "3.0.0-beta.1",
"version": "v1.1.7",
"gd": {
"win": "2.206"
},
"id": "adyagd.ingamelistmod",
"name": "IngameListMod",
"developer": "AdyaGD",
Expand Down
75 changes: 38 additions & 37 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ bool requestfinished = false;
bool partitied = false;
int listtype;

EventListener<web::WebTask> webreq;

class DemonClass {
public:
void infobox(CCObject* sender);
Expand Down Expand Up @@ -106,45 +108,44 @@ void getRequest(CCLayer* self, GJGameLevel* level, CCLabelBMFont* thelabel, bool
std::string url = pointercrate ? "https://api.aredl.net/api/aredl/levels/" + std::string(lvlID) + "?two_player=false&records=false&creators=false&verification=false&packs=false" : "https://challengelist.gd/api/v2/demons/listed/?name=" + std::string(lvlname);
if (platformer) url = "https://www.demonlist.com/api/level/?level_id=" + std::string(lvlID);

web::AsyncWebRequest()
.fetch(url)
.text()
.then([self, thelabel, pointercrate, level, platformer](std::string const& resultat) mutable {
log::info("{}\n\n", resultat);
std::string result;

try {
(!platformer && !pointercrate) ? result = resultat : result = "[" + resultat + "]";
childJson = nlohmann::json::parse(result);

self->autorelease();

if (childJson.size() > 0 && childJson[0].contains("position")) {
int position = childJson[0]["position"];
std::string label = std::string(std::to_string(position));
thelabel->setString(label.c_str());
CCDictionary* pos = CCDictionary::create();
pos->setObject(CCInteger::create(position), "get");
pos->setObject(CCBool::create(pointercrate), "domain");
pos->setObject(CCBool::create(platformer), "platformer");
createButton(self, thelabel, pos, pointercrate, platformer);
cachedPositions.insert({ level->m_levelID, position });
}
else {
thelabel->setString("N/A");
infoButton(self, thelabel);
cachedPositions.insert({ level->m_levelID, -1 });
}
} catch (nlohmann::json::exception &e) { // refer to: https://github.com/nlohmann/json/discussions/2467#discussioncomment-127872
log::info("e.what(): {}", e.what()); // log for users to end to adya
thelabel->setString("???"); // distinguish from "N/A" rankings
infoButton(self, thelabel, true); // distinguish from "N/A" rankings
} catch (int a) {}
})
.expect([](std::string const& error) {
return;
webreq.bind([self, thelabel, pointercrate, level, platformer](web::WebTask::Event* e) mutable {
if (web::WebResponse* res = e->getValue()) {
std::string resultat = res->string().unwrap();
try {
std::string result;
log::info("{}\n\n", resultat);
(!platformer && !pointercrate) ? result = resultat : result = "[" + resultat + "]";
childJson = nlohmann::json::parse(result);

self->autorelease();

if (childJson.size() > 0 && childJson[0].contains("position")) {
int position = childJson[0]["position"];
std::string label = std::string(std::to_string(position));
thelabel->setString(label.c_str());
CCDictionary* pos = CCDictionary::create();
pos->setObject(CCInteger::create(position), "get");
pos->setObject(CCBool::create(pointercrate), "domain");
pos->setObject(CCBool::create(platformer), "platformer");
createButton(self, thelabel, pos, pointercrate, platformer);
cachedPositions.insert({ level->m_levelID, position });
}
else {
thelabel->setString("N/A");
infoButton(self, thelabel);
cachedPositions.insert({ level->m_levelID, -1 });
}
} catch (nlohmann::json::exception &e) { // refer to: https://github.com/nlohmann/json/discussions/2467#discussioncomment-127872
log::info("e.what(): {}", e.what()); // log for users to send to adya
thelabel->setString("???"); // distinguish from "N/A" rankings
infoButton(self, thelabel, true); // distinguish from "N/A" rankings
} catch (int a) {}
}
});

auto req = web::WebRequest();
webreq.setFilter(req.get(url));

return;
}

Expand Down

0 comments on commit f5051a8

Please sign in to comment.