Skip to content

Commit

Permalink
Reported by @availax
Browse files Browse the repository at this point in the history
  • Loading branch information
hiimjasmine00 committed Nov 1, 2024
1 parent ef2b4e1 commit 58f6c28
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 17 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64")
set(CMAKE_CXX_VISIBILITY_PRESET hidden)

project(IntegratedDemonlist VERSION 1.7.0)
project(IntegratedDemonlist VERSION 1.7.1)

add_library(${PROJECT_NAME} SHARED
src/classes/IDListLayer.cpp
Expand Down
5 changes: 4 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Integrated Demonlist Changelog
## v1.7.1 (2024-11-01)
- Fixed a bug where the demonlist would not close when the escape key was pressed

## v1.7.0 (2024-11-01)
- Changed ranking text to load individually on cell load rather than all at once in the main menu

Expand Down Expand Up @@ -83,7 +86,7 @@

## v1.4.7 (2024-05-15)
- Fixed a bug where two-player demons would appear twice in the demonlist
- Fixed a few bugs with the demonlist search
- Fixed a few bugs with the demonlist search
- Changed the logo to be more in line with Geode's logo style

## v1.4.6 (2024-04-30)
Expand Down
2 changes: 1 addition & 1 deletion mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"win": "2.206",
"mac": "2.206"
},
"version": "v1.7.0",
"version": "v1.7.1",
"id": "hiimjustin000.integrated_demonlist",
"name": "Integrated Demonlist",
"developer": "hiimjustin000",
Expand Down
20 changes: 13 additions & 7 deletions src/IntegratedDemonlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ using namespace geode::prelude;
#define PEMONLIST_UPTIME_URL "https://pemonlist.com/api/uptime?version=2"
#define PEMONLIST_URL "https://pemonlist.com/api/list?limit=500&version=2"

void IntegratedDemonlist::isOk(std::string const& url, EventListener<web::WebTask>&& listenerRef, std::function<void(bool, int)> const& callback) {
void IntegratedDemonlist::isOk(std::string const& url, EventListener<web::WebTask>&& listenerRef, bool head, std::function<void(bool, int)> const& callback) {
auto&& listener = std::move(listenerRef);
listener.bind([callback](web::WebTask::Event* e) {
if (auto res = e->getValue()) callback(res->ok(), res->code());
});
listenerRef.setFilter(web::WebRequest().downloadRange({ 0, 0 }).get(url));
listenerRef.setFilter(head ? web::WebRequest().send("HEAD", url) : web::WebRequest().downloadRange({ 0, 0 }).get(url));
}

void IntegratedDemonlist::loadAREDL(
Expand Down Expand Up @@ -51,7 +51,8 @@ void IntegratedDemonlist::loadAREDL(
callback();
}
});
isOk(AREDL_URL, std::move(okListener), [&listener, circle](bool ok, int code) {

isOk(AREDL_URL, std::move(okListener), true, [&listener, circle](bool ok, int code) {
if (ok) listener.setFilter(web::WebRequest().get(AREDL_URL));
else queueInMainThread([circle, code] {
FLAlertLayer::create(fmt::format("Load Failed ({})", code).c_str(), "Failed to load AREDL. Please try again later.", "OK")->show();
Expand All @@ -76,7 +77,11 @@ void IntegratedDemonlist::loadAREDLPacks(
}

AREDL_PACKS.clear();
for (auto const& pack : res->json().value().as_array()) {
auto str = res->string().value();
std::string error;
auto json = matjson::parse(str, error).value_or(matjson::Array());
if (!error.empty()) log::error("Failed to parse AREDL packs: {}", error);
if (json.is_array()) for (auto const& pack : json.as_array()) {
std::vector<int> levels;
for (auto const& level : pack["levels"].as_array()) levels.push_back(level["level_id"].as_int());
AREDL_PACKS.push_back({
Expand All @@ -91,7 +96,8 @@ void IntegratedDemonlist::loadAREDLPacks(
callback();
}
});
isOk(AREDL_PACKS_URL, std::move(okListener), [&listener, circle](bool ok, int code) {

isOk(AREDL_PACKS_URL, std::move(okListener), true, [&listener, circle](bool ok, int code) {
if (ok) listener.setFilter(web::WebRequest().get(AREDL_PACKS_URL));
else queueInMainThread([circle, code] {
FLAlertLayer::create(fmt::format("Load Failed ({})", code).c_str(), "Failed to load AREDL packs. Please try again later.", "OK")->show();
Expand Down Expand Up @@ -119,7 +125,7 @@ void IntegratedDemonlist::loadPemonlist(
PEMONLIST.clear();
auto str = res->string().value();
std::string error;
auto json = matjson::parse(str, error).value_or(matjson::Object { { "data", matjson::Array() } });
auto json = matjson::parse(str, error).value_or(matjson::Object());
if (!error.empty()) log::error("Failed to parse Pemonlist: {}", error);
if (json.is_object() && json.contains("data") && json["data"].is_array()) for (auto const& level : json["data"].as_array()) {
if (!level.contains("level_id") || !level["level_id"].is_number()) continue;
Expand All @@ -136,7 +142,7 @@ void IntegratedDemonlist::loadPemonlist(
}
});

isOk(PEMONLIST_UPTIME_URL, std::move(okListener), [&listener, circle](bool ok, int code) {
isOk(PEMONLIST_UPTIME_URL, std::move(okListener), false, [&listener, circle](bool ok, int code) {
if (ok) listener.setFilter(web::WebRequest().get(PEMONLIST_URL));
else queueInMainThread([circle, code] {
FLAlertLayer::create(fmt::format("Load Failed ({})", code).c_str(), "Failed to load Pemonlist. Please try again later.", "OK")->show();
Expand Down
2 changes: 1 addition & 1 deletion src/IntegratedDemonlist.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class IntegratedDemonlist {
inline static bool AREDL_LOADED = false;
inline static bool PEMONLIST_LOADED = false;

static void isOk(std::string const&, geode::EventListener<geode::utils::web::WebTask>&&, std::function<void(bool, int)> const&);
static void isOk(std::string const&, geode::EventListener<geode::utils::web::WebTask>&&, bool, std::function<void(bool, int)> const&);
static void loadAREDL(
geode::EventListener<geode::utils::web::WebTask>&&,
geode::EventListener<geode::utils::web::WebTask>&&,
Expand Down
8 changes: 5 additions & 3 deletions src/classes/IDListLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ bool IDListLayer::init() {
menu->setPosition(0.0f, 0.0f);
addChild(menu);

m_backButton = CCMenuItemExt::createSpriteExtraWithFrameName("GJ_arrow_01_001.png", 1.0f, [this](auto) { keyBackClicked(); });
m_backButton = CCMenuItemExt::createSpriteExtraWithFrameName("GJ_arrow_01_001.png", 1.0f, [this](auto) {
CCDirector::sharedDirector()->popSceneWithTransition(0.5f, kPopTransitionFade);
});
m_backButton->setPosition(25.0f, winSize.height - 25.0f);
menu->addChild(m_backButton);

Expand Down Expand Up @@ -185,6 +187,7 @@ bool IDListLayer::init() {
m_loadingCircle->show();

showLoading();
setKeypadEnabled(true);
setKeyboardEnabled(true);

if (PEMONLIST) {
Expand Down Expand Up @@ -336,8 +339,7 @@ void IDListLayer::page(int page) {
}

void IDListLayer::keyDown(enumKeyCodes key) {
switch (key)
{
switch (key) {
case KEY_Left:
case CONTROLLER_Left:
if (m_leftButton->isVisible()) page(m_page - 1);
Expand Down
8 changes: 5 additions & 3 deletions src/classes/IDPackLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ bool IDPackLayer::init() {
menu->setPosition(0.0f, 0.0f);
addChild(menu);

m_backButton = CCMenuItemExt::createSpriteExtraWithFrameName("GJ_arrow_01_001.png", 1.0f, [this](auto) { keyBackClicked(); });
m_backButton = CCMenuItemExt::createSpriteExtraWithFrameName("GJ_arrow_01_001.png", 1.0f, [this](auto) {
CCDirector::sharedDirector()->popSceneWithTransition(0.5f, kPopTransitionFade);
});
m_backButton->setPosition(25.0f, winSize.height - 25.0f);
menu->addChild(m_backButton);

Expand Down Expand Up @@ -142,6 +144,7 @@ bool IDPackLayer::init() {
m_loadingCircle->show();

showLoading();
setKeypadEnabled(true);
setKeyboardEnabled(true);

if (!IntegratedDemonlist::AREDL_PACKS.empty()) populateList("");
Expand Down Expand Up @@ -259,8 +262,7 @@ void IDPackLayer::page(int page) {
}

void IDPackLayer::keyDown(enumKeyCodes key) {
switch (key)
{
switch (key) {
case KEY_Left:
case CONTROLLER_Left:
if (m_leftButton->isVisible()) page(m_page - 1);
Expand Down

0 comments on commit 58f6c28

Please sign in to comment.