Skip to content

Commit

Permalink
I love refactoring code
Browse files Browse the repository at this point in the history
  • Loading branch information
hiimjasmine00 committed Feb 6, 2025
1 parent 280f978 commit 219eddc
Show file tree
Hide file tree
Showing 18 changed files with 254 additions and 211 deletions.
18 changes: 4 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ jobs:
- uses: actions/checkout@v4

- name: Build the mod
uses: geode-sdk/build-geode-mod@main
uses: hiimjasmine00/build-geode-mod@main
with:
sdk: nightly
build-config: ${{ matrix.config.build-config || 'Release' }}
export-pdb: true
export-symbols: true
combine: true
target: ${{ matrix.config.target }}

Expand All @@ -47,22 +49,10 @@ jobs:
needs: ['build']

steps:
- uses: geode-sdk/build-geode-mod/combine@main
- uses: hiimjasmine00/build-geode-mod/combine@main
id: build

- uses: actions/upload-artifact@v4
with:
name: Build Output
path: ${{ steps.build.outputs.build-output }}

release:
name: Release the mod
runs-on: ubuntu-latest
needs: ['package']

steps:
- uses: actions/checkout@v4

- uses: hiimjustin000/release-geode-mod@main
with:
token: ${{ secrets.GITHUB_TOKEN }}
36 changes: 36 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Release Geode Mod

on:
workflow_dispatch:

jobs:
release:
name: Release mod
runs-on: ubuntu-latest
environment:
name: release
url: ${{ steps.mod-release.outputs.url }}

steps:
- uses: actions/checkout@v4

- uses: hiimjasmine00/release-geode-mod@main
id: mod-release
with:
token: ${{ secrets.GITHUB_TOKEN }}

publish:
name: Publish mod
runs-on: ubuntu-latest
needs: ['release']
environment:
name: publish
url: ${{ steps.mod-publish.outputs.url }}

steps:
- uses: actions/checkout@v4

- uses: hiimjasmine00/release-geode-mod/publish@main
id: mod-publish
with:
token: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64")
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(GEODE_DISABLE_PRECOMPILED_HEADERS ON)

project(IntegratedDemonlist VERSION 1.7.2)
project(IntegratedDemonlist VERSION 1.7.3)

add_library(${PROJECT_NAME} SHARED
src/classes/IDListLayer.cpp
Expand Down
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 hiimjustin000
Copyright (c) 2024-2025 hiimjasmine00

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
6 changes: 3 additions & 3 deletions about.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ A mod that integrates [aredl.net](https://aredl.net) and [pemonlist.com](https:/
- Text on a demon's search box that states its position on the list (If on the list and the text is enabled in the mod settings)

# Gallery
![AREDL](hiimjustin000.integrated_demonlist/aredl.png?scale=0.625)\
![Pemonlist](hiimjustin000.integrated_demonlist/pemonlist.png?scale=0.625)\
![AREDL Packs](hiimjustin000.integrated_demonlist/aredl-packs.png?scale=0.625)
![AREDL](hiimjustin000.integrated_demonlist/aredl.png?width=320)\
![Pemonlist](hiimjustin000.integrated_demonlist/pemonlist.png?width=320)\
![AREDL Packs](hiimjustin000.integrated_demonlist/aredl-packs.png?width=320)
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Integrated Demonlist Changelog
## v1.7.3 (2025-02-06)
- Reduced Pemonlist size to 150 demons

## v1.7.2 (2024-11-15)
- Ported to Geode v4.0.0-beta.1

Expand Down
19 changes: 8 additions & 11 deletions mod.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"geode": "4.0.0-beta.1",
"geode": "4.2.0",
"gd": {
"android": "2.2074",
"win": "2.2074",
"mac": "2.2074"
},
"version": "v1.7.2",
"version": "v1.7.3",
"id": "hiimjustin000.integrated_demonlist",
"name": "Integrated Demonlist",
"developer": "hiimjustin000",
"developer": "hiimjasmine00",
"description": "A mod that integrates aredl.net and pemonlist.com into Geometry Dash.",
"resources": {
"sprites": [
Expand All @@ -26,19 +26,16 @@
"name": "White Demon Ranking Text",
"description": "Whether or not to display the demon ranking text in white.",
"type": "bool",
"enable-if": "enable-rank",
"default": false
}
},
"dependencies": [
{
"id": "geode.node-ids",
"version": ">=v1.12.0",
"importance": "required"
}
],
"dependencies": {
"geode.node-ids": ">=v1.12.0"
},
"links": {
"community": "https://discord.gg/QVKmbvBXA7",
"source": "https://github.com/hiimjustin000/IntegratedDemonlist",
"source": "https://github.com/hiimjasmine00/IntegratedDemonlist",
"homepage": "https://www.hiimjustin000.com"
},
"tags": [
Expand Down
129 changes: 52 additions & 77 deletions src/IntegratedDemonlist.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#include "IntegratedDemonlist.hpp"
#include <Geode/utils/ranges.hpp>

using namespace geode::prelude;

#define AREDL_URL "https://api.aredl.net/api/aredl/levels"
#define AREDL_PACKS_URL "https://api.aredl.net/api/aredl/packs"
#define PEMONLIST_UPTIME_URL "https://pemonlist.com/api/uptime?version=2"
#define PEMONLIST_URL "https://pemonlist.com/api/list?limit=500&version=2"
#define PEMONLIST_URL "https://pemonlist.com/api/list?limit=150&version=2"

void IntegratedDemonlist::isOk(std::string const& url, EventListener<web::WebTask>&& listenerRef, bool head, std::function<void(bool, int)> const& callback) {
void isOk(const std::string& url, EventListener<web::WebTask>&& listenerRef, bool head, const std::function<void(bool, int)>& callback) {
auto&& listener = std::move(listenerRef);
listener.bind([callback](web::WebTask::Event* e) {
if (auto res = e->getValue()) callback(res->ok(), res->code());
Expand All @@ -17,134 +18,108 @@ void IntegratedDemonlist::isOk(std::string const& url, EventListener<web::WebTas

void IntegratedDemonlist::loadAREDL(
EventListener<web::WebTask>&& listenerRef, EventListener<web::WebTask>&& okListener,
LoadingCircle* circle, std::function<void()> const& callback
const std::function<void()>& success, const std::function<void(int)>& failure
) {
auto&& listener = std::move(listenerRef);
listener.bind([callback, circle](web::WebTask::Event* e) {
listener.bind([failure, success](web::WebTask::Event* e) {
if (auto res = e->getValue()) {
if (!res->ok()) {
queueInMainThread([circle, res] {
FLAlertLayer::create(fmt::format("Load Failed ({})", res->code()).c_str(), "Failed to load AREDL. Please try again later.", "OK")->show();
circle->setVisible(false);
});
return;
}
if (!res->ok()) return failure(res->code());

AREDL_LOADED = true;
AREDL.clear();
auto json = res->json().unwrapOr(matjson::Value());
if (json.isArray()) for (auto const& level : json.asArray().unwrap()) {
if (level.contains("legacy") && level["legacy"].isBool() && level["legacy"].asBool().unwrap()) continue;
if (!level.contains("level_id") || !level["level_id"].isNumber()) continue;
if (!level.contains("name") || !level["name"].isString()) continue;
if (!level.contains("position") || !level["position"].isNumber()) continue;
if (!json.isArray()) return success();

AREDL.push_back({
AREDL = ranges::map<std::vector<IDListDemon>>(ranges::filter(json.asArray().unwrap(), [](const matjson::Value& level) {
return (!level.contains("legacy") || !level["legacy"].isBool() || !level["legacy"].asBool().unwrap()) &&
level.contains("level_id") && level["level_id"].isNumber() &&
level.contains("name") && level["name"].isString() &&
level.contains("position") && level["position"].isNumber();
}), [](const matjson::Value& level) {
return IDListDemon {
(int)level["level_id"].asInt().unwrap(),
level["name"].asString().unwrap(),
(int)level["position"].asInt().unwrap()
});
}
callback();
};
});
success();
}
});

isOk(AREDL_URL, std::move(okListener), true, [&listener, circle](bool ok, int code) {
isOk(AREDL_URL, std::move(okListener), true, [&listener, failure](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();
circle->setVisible(false);
});
else failure(code);
});
}

void IntegratedDemonlist::loadAREDLPacks(
EventListener<web::WebTask>&& listenerRef, EventListener<web::WebTask>&& okListener,
LoadingCircle* circle, std::function<void()> const& callback
const std::function<void()>& success, const std::function<void(int)>& failure
) {
auto&& listener = std::move(listenerRef);
listener.bind([callback, circle](web::WebTask::Event* e) {
listener.bind([failure, success](web::WebTask::Event* e) {
if (auto res = e->getValue()) {
if (!res->ok()) {
queueInMainThread([circle, res] {
FLAlertLayer::create(fmt::format("Load Failed ({})", res->code()).c_str(), "Failed to load AREDL packs. Please try again later.", "OK")->show();
circle->setVisible(false);
});
return;
}
if (!res->ok()) return failure(res->code());

AREDL_PACKS.clear();
auto json = res->json().unwrapOr(matjson::Value());
if (json.isArray()) for (auto const& pack : json.asArray().unwrap()) {
if (!pack.contains("name") || !pack["name"].isString()) continue;
if (!pack.contains("points") || !pack["points"].isNumber()) continue;
if (!pack.contains("levels") || !pack["levels"].isArray()) continue;
if (!json.isArray()) return success();

std::vector<int> levels;
for (auto const& level : pack["levels"].asArray().unwrap()) {
if (!level.contains("level_id") || !level["level_id"].isNumber()) continue;
levels.push_back(level["level_id"].asInt().unwrap());
}
AREDL_PACKS.push_back({
AREDL_PACKS = ranges::map<std::vector<IDDemonPack>>(ranges::filter(json.asArray().unwrap(), [](const matjson::Value& pack) {
return pack.contains("name") && pack["name"].isString() &&
pack.contains("points") && pack["points"].isNumber() &&
pack.contains("levels") && pack["levels"].isArray();
}), [](const matjson::Value& pack) {
return IDDemonPack {
pack["name"].asString().unwrap(),
pack["points"].asDouble().unwrap(),
levels
});
}
std::sort(AREDL_PACKS.begin(), AREDL_PACKS.end(), [](auto const& a, auto const& b) {
return a.points < b.points;
ranges::map<std::vector<int>>(ranges::filter(pack["levels"].asArray().unwrap(), [](const matjson::Value& level) {
return level.contains("level_id") && level["level_id"].isNumber();
}), [](const matjson::Value& level) { return level["level_id"].asInt().unwrap(); })
};
});
callback();
std::sort(AREDL_PACKS.begin(), AREDL_PACKS.end(), [](const IDDemonPack& a, const IDDemonPack& b) { return a.points < b.points; });
success();
}
});

isOk(AREDL_PACKS_URL, std::move(okListener), true, [&listener, circle](bool ok, int code) {
isOk(AREDL_PACKS_URL, std::move(okListener), true, [&listener, failure](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();
circle->setVisible(false);
});
else failure(code);
});
}

void IntegratedDemonlist::loadPemonlist(
EventListener<web::WebTask>&& listenerRef, EventListener<web::WebTask>&& okListener,
LoadingCircle* circle, std::function<void()> const& callback
const std::function<void()>& success, const std::function<void(int)>& failure
) {
auto&& listener = std::move(listenerRef);
listener.bind([callback, circle](web::WebTask::Event* e) {
listener.bind([failure, success](web::WebTask::Event* e) {
if (auto res = e->getValue()) {
if (!res->ok()) {
queueInMainThread([circle, res] {
FLAlertLayer::create(fmt::format("Load Failed ({})", res->code()).c_str(), "Failed to load Pemonlist. Please try again later.", "OK")->show();
circle->setVisible(false);
});
return;
}
if (!res->ok()) return failure(res->code());

PEMONLIST_LOADED = true;
PEMONLIST.clear();
auto json = res->json().unwrapOr(matjson::Value());
if (json.isObject() && json.contains("data") && json["data"].isArray()) for (auto const& level : json["data"].asArray().unwrap()) {
if (!level.contains("level_id") || !level["level_id"].isNumber()) continue;
if (!level.contains("name") || !level["name"].isString()) continue;
if (!level.contains("placement") || !level["placement"].isNumber()) continue;
if (!json.isObject() || !json.contains("data") || !json["data"].isArray()) return success();

PEMONLIST.push_back({
PEMONLIST = ranges::map<std::vector<IDListDemon>>(ranges::filter(json["data"].asArray().unwrap(), [](const matjson::Value& level) {
return level.contains("level_id") && level["level_id"].isNumber() &&
level.contains("name") && level["name"].isString() &&
level.contains("placement") && level["placement"].isNumber();
}), [](const matjson::Value& level) {
return IDListDemon {
(int)level["level_id"].asInt().unwrap(),
level["name"].asString().unwrap(),
(int)level["placement"].asInt().unwrap()
});
}
callback();
};
});
success();
}
});

isOk(PEMONLIST_UPTIME_URL, std::move(okListener), false, [&listener, circle](bool ok, int code) {
isOk(PEMONLIST_UPTIME_URL, std::move(okListener), false, [&listener, failure](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();
circle->setVisible(false);
});
else failure(code);
});
}
13 changes: 6 additions & 7 deletions src/IntegratedDemonlist.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,22 @@ 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>&&, bool, std::function<void(bool, int)> const&);
static void loadAREDL(
geode::EventListener<geode::utils::web::WebTask>&&,
geode::EventListener<geode::utils::web::WebTask>&&,
LoadingCircle*,
std::function<void()> const&
const std::function<void()>&,
const std::function<void(int)>&
);
static void loadAREDLPacks(
geode::EventListener<geode::utils::web::WebTask>&&,
geode::EventListener<geode::utils::web::WebTask>&&,
LoadingCircle*,
std::function<void()> const&
const std::function<void()>&,
const std::function<void(int)>&
);
static void loadPemonlist(
geode::EventListener<geode::utils::web::WebTask>&&,
geode::EventListener<geode::utils::web::WebTask>&&,
LoadingCircle*,
std::function<void()> const&
const std::function<void()>&,
const std::function<void(int)>&
);
};
Loading

0 comments on commit 219eddc

Please sign in to comment.