Skip to content

Commit

Permalink
add important notices
Browse files Browse the repository at this point in the history
  • Loading branch information
Cvolton committed Oct 4, 2023
1 parent 38d4875 commit 1dff5b9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/hooks/CreatorLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class $modify(BICreatorLayer, CreatorLayer) {
this->addChild(menu);

showQuestExclamationMark();
BetterInfo::loadImportantNotices(this);

/*auto alert = CM->updateCompleteDialog();
if(alert) {
Expand Down
23 changes: 23 additions & 0 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <Geode/cocos/support/base64.h>
#include <Geode/cocos/support/zip_support/ZipUtils.h>
#include <Geode/utils/web.hpp>

CCSprite* BetterInfo::createWithBISpriteFrameName(const char* name){
return createBISprite(name);
Expand Down Expand Up @@ -579,4 +580,26 @@ bool BetterInfo::controllerConnected() {
#else
return CCApplication::sharedApplication()->getControllerConnected();
#endif
}

void BetterInfo::loadImportantNotices(CCLayer* layer) {
static bool hasBeenCalled = false;
if(hasBeenCalled) return;
hasBeenCalled = true;

layer->retain();

web::AsyncWebRequest().fetch(fmt::format("https://geometrydash.eu/mods/betterinfo/_api/importantNotices/?platform={}&version={}", GEODE_PLATFORM_NAME, Mod::get()->getVersion().toString(false))).json().then([layer](const json::Value& info){
auto notice = info.try_get("notice");
if(notice == std::nullopt) return;

if(info["notice"].is_string()) {
auto alert = FLAlertLayer::create("BetterInfo", info["notice"].as_string(), "OK");
alert->m_scene = layer;
alert->show();
layer->release();
}
}).expect([](const std::string& error){
log::warn("Fetching important notices failed: {}", error);
});
}
2 changes: 2 additions & 0 deletions src/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,6 @@ namespace BetterInfo {
float timeForLevelString(const std::string& levelString);

bool controllerConnected();

void loadImportantNotices(CCLayer* layer);
}

0 comments on commit 1dff5b9

Please sign in to comment.