Skip to content

Commit f159945

Browse files
committed
Refactor 2025-10-22
1 parent fd910b6 commit f159945

File tree

6 files changed

+29
-38
lines changed

6 files changed

+29
-38
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
workflow_dispatch:
55
push:
66
branches:
7-
- "master"
7+
- "**"
88

99
jobs:
1010
build:

README.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@ Badges for every* Geode mod developer.\
44

55
## Features
66
- Clickable badges displayed on a user's profile and comments
7-
- Comment coloring based on a user's badges
7+
- Toggleable comment coloring based on a user's badges:
8+
- Mod Developer
9+
- Verified Developer
10+
- Index Staff
11+
- Lead Developer
812

913
## Credits
1014
- [Brift](https://gdbrowser.com/u/14114548) - Designer of the mod's textures
1115
- [hiimjasmine00](https://gdbrowser.com/u/7466002) - Creator of the mod
1216

13-
## Badges
14-
- Mod Developer
15-
- Verified Developer
16-
- Index Staff
17-
- Lead Developer
18-
19-
# License
20-
This mod is licensed under the [MIT License](./LICENSE).
17+
## License
18+
This mod is licensed under the [MIT License](https://github.com/hiimjasmine00/DeveloperBadges/blob/master/LICENSE).

about.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ Badges for every* Geode mod developer.\
44

55
## Features
66
- Clickable badges displayed on a user's profile and comments
7-
- Comment coloring based on a user's badges
7+
- Toggleable comment coloring based on a user's badges:
8+
- Mod Developer
9+
- Verified Developer
10+
- Index Staff
11+
- Lead Developer
812

913
## Credits
1014
- [Brift](user:14114548) - Designer of the mod's textures
1115
- [hiimjasmine00](user:7466002) - Creator of the mod
1216

13-
## Badges
14-
- Mod Developer
15-
- Verified Developer
16-
- Index Staff
17-
- Lead Developer
17+
## License
18+
This mod is licensed under the [MIT License](https://github.com/hiimjasmine00/DeveloperBadges/blob/master/LICENSE).

changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@
4040
- Fixed a bug where reloading the page would add duplicate badges to a user's profile
4141

4242
## v1.0.0 (2024-10-01)
43-
- Initial release
43+
- Initial release

src/DeveloperBadges.cpp

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
using namespace geode::prelude;
99
using namespace optional_settings;
1010

11+
std::map<int, DeveloperBadge> DeveloperBadges::developerBadges;
12+
1113
constexpr std::array settings = {
1214
std::make_pair("mod-developer-color", "mod-developer-color-toggle"),
1315
std::make_pair("verified-developer-color", "verified-developer-color-toggle"),
@@ -20,12 +22,8 @@ constexpr std::array settings = {
2022
auto& data = mod->getSavedSettingsData();
2123
if (!mod->setSavedValue("migrated-colors", true)) {
2224
for (auto [key, toggle] : settings) {
23-
Result<ccColor3B> oldColorValue = data.get(key).andThen([](const matjson::Value& v) {
24-
return v.as<ccColor3B>();
25-
});
26-
Result<bool> oldColorEnabled = data.get(toggle).andThen([](const matjson::Value& v) {
27-
return v.asBool();
28-
});
25+
auto oldColorValue = data.get<ccColor3B>(key);
26+
auto oldColorEnabled = data.get<bool>(toggle);
2927
if (oldColorValue.isOk() && oldColorEnabled.isOk()) {
3028
auto setting = std::static_pointer_cast<OptionalColor3BSetting>(mod->getSetting(key));
3129
setting->setStoredValue(oldColorValue.unwrap());
@@ -44,32 +42,25 @@ constexpr std::array settings = {
4442
if (!json.isOk()) return;
4543

4644
for (auto& value : json.unwrap()) {
47-
Result<int> id = value.get("id").andThen([](const matjson::Value& v) {
48-
return v.as<int>();
49-
});
45+
auto id = value.get<int>("id");
5046
if (!id.isOkAnd([](int id) { return id > 0; })) continue;
5147

52-
Result<int> type = value.get("badge").andThen([](const matjson::Value& v) {
53-
return v.as<int>();
54-
});
48+
auto type = value.get<int>("badge");
5549
if (!type.isOkAnd([](int type) { return type > 0 && type < 5; })) continue;
5650

57-
Result<std::string> name = value.get("name").andThen([](const matjson::Value& v) {
58-
return v.asString();
59-
});
51+
auto name = value.get<std::string>("name");
6052
if (!name.isOk()) continue;
6153

62-
DeveloperBadges::developerBadges.emplace_back(id.unwrap(), type.unwrap(), name.unwrap());
54+
DeveloperBadge badge(id.unwrap(), type.unwrap(), std::move(name).unwrap());
55+
DeveloperBadges::developerBadges.emplace(badge.id, std::move(badge));
6356
}
6457
});
6558
}, GameEventFilter(GameEventType::Loaded));
6659
}
6760

6861
DeveloperBadge* DeveloperBadges::badgeForUser(int id) {
69-
auto badge = std::ranges::find_if(developerBadges, [id](const DeveloperBadge& badge) {
70-
return badge.id == id;
71-
});
72-
return badge != developerBadges.end() ? std::to_address(badge) : nullptr;
62+
auto badge = developerBadges.find(id);
63+
return badge != developerBadges.end() ? &badge->second : nullptr;
7364
}
7465

7566
constexpr std::array names = {

src/DeveloperBadges.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <ccTypes.h>
2+
23
struct DeveloperBadge {
34
int id;
45
int type;
@@ -7,7 +8,7 @@ struct DeveloperBadge {
78

89
class DeveloperBadges {
910
public:
10-
static inline std::vector<DeveloperBadge> developerBadges;
11+
static std::map<int, DeveloperBadge> developerBadges;
1112

1213
static DeveloperBadge* badgeForUser(int);
1314
static void showBadgeInfo(const std::string&, int);

0 commit comments

Comments
 (0)