Skip to content

Commit 7846a2b

Browse files
committed
Refactor with jasmine-tools
1 parent f159945 commit 7846a2b

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ endif()
2323

2424
add_subdirectory($ENV{GEODE_SDK} ${CMAKE_CURRENT_BINARY_DIR}/geode)
2525

26+
CPMAddPackage("gh:hiimjasmine00/[email protected]")
27+
target_link_libraries(${PROJECT_NAME} jasmine-tools)
28+
2629
setup_geode_mod(${PROJECT_NAME})

src/DeveloperBadges.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
#include <Geode/binding/FLAlertLayer.hpp>
33
#include <Geode/loader/GameEvent.hpp>
44
#include <Geode/loader/Mod.hpp>
5-
#include <Geode/utils/web.hpp>
65
#include <hiimjasmine00.optional_settings/include/OptionalColor3BSetting.hpp>
6+
#include <jasmine/setting.hpp>
7+
#include <jasmine/web.hpp>
78

89
using namespace geode::prelude;
910
using namespace optional_settings;
@@ -22,12 +23,13 @@ constexpr std::array settings = {
2223
auto& data = mod->getSavedSettingsData();
2324
if (!mod->setSavedValue("migrated-colors", true)) {
2425
for (auto [key, toggle] : settings) {
25-
auto oldColorValue = data.get<ccColor3B>(key);
26-
auto oldColorEnabled = data.get<bool>(toggle);
27-
if (oldColorValue.isOk() && oldColorEnabled.isOk()) {
28-
auto setting = std::static_pointer_cast<OptionalColor3BSetting>(mod->getSetting(key));
29-
setting->setStoredValue(oldColorValue.unwrap());
30-
setting->setEnabled(oldColorEnabled.unwrap());
26+
if (auto setting = jasmine::setting::get<std::optional<ccColor3B>>(key)) {
27+
auto oldColorValue = data.get<ccColor3B>(key);
28+
auto oldColorEnabled = data.get<bool>(toggle);
29+
if (oldColorValue.isOk() && oldColorEnabled.isOk()) {
30+
setting->setStoredValue(oldColorValue.unwrap());
31+
setting->setEnabled(oldColorEnabled.unwrap());
32+
}
3133
}
3234
}
3335
}
@@ -36,12 +38,7 @@ constexpr std::array settings = {
3638
web::WebRequest().get("https://badges.hiimjasmine00.com/developer").listen([](web::WebResponse* res) {
3739
if (!res->ok()) return;
3840

39-
Result<std::vector<matjson::Value>> json = res->json().andThen([](matjson::Value&& v) {
40-
return std::move(v).asArray();
41-
});
42-
if (!json.isOk()) return;
43-
44-
for (auto& value : json.unwrap()) {
41+
for (auto& value : jasmine::web::getArray(res)) {
4542
auto id = value.get<int>("id");
4643
if (!id.isOkAnd([](int id) { return id > 0; })) continue;
4744

src/hooks/CommentCell.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <Geode/binding/TextArea.hpp>
66
#include <Geode/modify/CommentCell.hpp>
77
#include <hiimjasmine00.optional_settings/include/OptionalColor3BSetting.hpp>
8+
#include <jasmine/setting.hpp>
89

910
using namespace geode::prelude;
1011

@@ -52,8 +53,8 @@ class $modify(DBCommentCell, CommentCell) {
5253

5354
if (badgeType < 1 || badgeType > colors.size()) return;
5455

55-
if (auto commentColor = Mod::get()->getSettingValue<std::optional<cocos2d::ccColor3B>>(colors[badgeType - 1])) {
56-
auto color = *commentColor;
56+
if (auto commentColor = jasmine::setting::getValue<std::optional<cocos2d::ccColor3B>>(colors[badgeType - 1])) {
57+
auto color = commentColor.value();
5758

5859
if (auto commentTextLabel = static_cast<CCLabelBMFont*>(m_mainLayer->getChildByID("comment-text-label"))) {
5960
commentTextLabel->setColor(color);

0 commit comments

Comments
 (0)