From 58f6c28ebcc177445c0760aac2066745b7bfb58c Mon Sep 17 00:00:00 2001 From: Justin Pridgen Date: Fri, 1 Nov 2024 17:34:21 -0400 Subject: [PATCH] Reported by @availax --- CMakeLists.txt | 2 +- changelog.md | 5 ++++- mod.json | 2 +- src/IntegratedDemonlist.cpp | 20 +++++++++++++------- src/IntegratedDemonlist.hpp | 2 +- src/classes/IDListLayer.cpp | 8 +++++--- src/classes/IDPackLayer.cpp | 8 +++++--- 7 files changed, 30 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a3d8d6..ae3e3b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/changelog.md b/changelog.md index cbf97eb..ee76182 100644 --- a/changelog.md +++ b/changelog.md @@ -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 @@ -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) diff --git a/mod.json b/mod.json index 1ebd530..53ddaee 100644 --- a/mod.json +++ b/mod.json @@ -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", diff --git a/src/IntegratedDemonlist.cpp b/src/IntegratedDemonlist.cpp index 1cdd5f6..e78d3a2 100644 --- a/src/IntegratedDemonlist.cpp +++ b/src/IntegratedDemonlist.cpp @@ -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&& listenerRef, std::function const& callback) { +void IntegratedDemonlist::isOk(std::string const& url, EventListener&& listenerRef, bool head, std::function 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( @@ -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(); @@ -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 levels; for (auto const& level : pack["levels"].as_array()) levels.push_back(level["level_id"].as_int()); AREDL_PACKS.push_back({ @@ -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(); @@ -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; @@ -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(); diff --git a/src/IntegratedDemonlist.hpp b/src/IntegratedDemonlist.hpp index 91a3d12..31a313d 100644 --- a/src/IntegratedDemonlist.hpp +++ b/src/IntegratedDemonlist.hpp @@ -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&&, std::function const&); + static void isOk(std::string const&, geode::EventListener&&, bool, std::function const&); static void loadAREDL( geode::EventListener&&, geode::EventListener&&, diff --git a/src/classes/IDListLayer.cpp b/src/classes/IDListLayer.cpp index 4393d34..88093c8 100644 --- a/src/classes/IDListLayer.cpp +++ b/src/classes/IDListLayer.cpp @@ -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); @@ -185,6 +187,7 @@ bool IDListLayer::init() { m_loadingCircle->show(); showLoading(); + setKeypadEnabled(true); setKeyboardEnabled(true); if (PEMONLIST) { @@ -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); diff --git a/src/classes/IDPackLayer.cpp b/src/classes/IDPackLayer.cpp index 8e53332..3356319 100644 --- a/src/classes/IDPackLayer.cpp +++ b/src/classes/IDPackLayer.cpp @@ -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); @@ -142,6 +144,7 @@ bool IDPackLayer::init() { m_loadingCircle->show(); showLoading(); + setKeypadEnabled(true); setKeyboardEnabled(true); if (!IntegratedDemonlist::AREDL_PACKS.empty()) populateList(""); @@ -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);