Skip to content

Commit fb4b5e6

Browse files
committed
update(main): Correct some parts of the code
1 parent 9c41e8b commit fb4b5e6

1 file changed

Lines changed: 5 additions & 38 deletions

File tree

src/main.cpp

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
#include <Geode/modify/ProfilePage.hpp>
33
#include <Geode/modify/CommentCell.hpp>
44
#include <Geode/modify/CCMenu.hpp>
5+
#include <Geode/loader/Log.hpp>
56

67
// Badges API
78
// Mod API made by Jouca
89

9-
#include <Geode/loader/Log.hpp>
1010
#include <string>
1111
#include "badges/BadgeMenu.h"
12-
1312
#include "RescalingNode.hpp"
1413

1514
// Helper: Extracts priority from badge ID (format: ...-badge:{number}), returns 9999 if not found
@@ -56,46 +55,14 @@ class $modify(CustomCommentCell, CommentCell) {
5655
(void)self.setHookPriority("CommentCell::loadFromComment", INT_MIN);
5756
}
5857

59-
60-
// Helper: Extracts priority from badge ID (format: ...-badge:{number}), returns 9999 if not found
61-
static int getBadgePriority(CCNode* badge) {
62-
std::string id = badge->getID();
63-
std::transform(id.begin(), id.end(), id.begin(), [](unsigned char c){ return std::tolower(c); });
64-
size_t pos = id.find("-badge:");
65-
if (pos != std::string::npos) {
66-
size_t start = pos + 7;
67-
size_t end = id.find_first_not_of("0123456789", start);
68-
std::string num = id.substr(start, end == std::string::npos ? end : end - start);
69-
try {
70-
int val = std::stoi(num);
71-
return val > 0 ? val : 9999;
72-
} catch (...) {}
73-
}
74-
return 9999;
75-
}
76-
77-
// Helper: Sorts a CCArray* of badges by priority (lowest first)
78-
static CCArray* sortBadgesByPriority(CCArray* badges) {
79-
std::vector<CCNode*> badgeVec;
80-
for (int i = 0; i < badges->count(); ++i) {
81-
badgeVec.push_back(static_cast<CCNode*>(badges->objectAtIndex(i)));
82-
}
83-
std::sort(badgeVec.begin(), badgeVec.end(), [](CCNode* a, CCNode* b) {
84-
return getBadgePriority(a) < getBadgePriority(b);
85-
});
86-
CCArray* sorted = CCArray::create();
87-
for (auto* b : badgeVec) sorted->addObject(b);
88-
return sorted;
89-
}
90-
9158
void updateBadges(CCArray* childsToRemove, CCMenu* username_menu, CCArray* badges) {
9259
// Remove all badges from the layer
9360
CCObject* childObj;
9461
CommentCell* cell = this;
9562
CCARRAY_FOREACH(childsToRemove, childObj) static_cast<CCNode*>(childObj)->removeFromParent();
9663

9764
// Sort badges by priority before displaying
98-
CCArray* sortedBadges = sortBadgesByPriority(badges);
65+
CCArray* sortedBadges = sortBadgesByPriority(badges);
9966
m_fields->badgeCount = sortedBadges->count();
10067

10168
// If there is only one badge, let it on the layer
@@ -228,7 +195,7 @@ static CCArray* sortBadgesByPriority(CCArray* badges) {
228195
void onBadgePlus(CCObject* pSender) {
229196
auto childs = static_cast<CCArray*>(static_cast<CCNode*>(pSender)->getUserObject());
230197
// Sort by priority before showing in menu
231-
CCArray* sortedBadges = sortBadgesByPriority(childs);
198+
CCArray* sortedBadges = sortBadgesByPriority(childs);
232199
// rescale the badges
233200
CCArray* childsRescaled = CCArray::create();
234201
for (int i = 0; i < sortedBadges->count(); i++) {
@@ -296,7 +263,7 @@ class $modify(CustomProfilePage, ProfilePage) {
296263
CCARRAY_FOREACH(childsToRemove, childObj) static_cast<CCNode*>(childObj)->removeFromParent();
297264

298265
// Sort badges by priority before displaying
299-
CCArray* sortedBadges = sortBadgesByPriority(badges);
266+
CCArray* sortedBadges = sortBadgesByPriority(badges);
300267
m_fields->badgeCount = sortedBadges->count();
301268

302269
// If there is only one badge, let it on the layer
@@ -425,7 +392,7 @@ class $modify(CustomProfilePage, ProfilePage) {
425392
void onBadgePlus(CCObject* pSender) {
426393
auto childs = static_cast<CCArray*>(static_cast<CCNode*>(pSender)->getUserObject());
427394
// Sort by priority before showing in menu
428-
CCArray* sortedBadges = sortBadgesByPriority(childs);
395+
CCArray* sortedBadges = sortBadgesByPriority(childs);
429396
m_fields->badgeMenu = BadgeMenu::scene(sortedBadges);
430397
}
431398

0 commit comments

Comments
 (0)