Skip to content

Commit 625b10e

Browse files
committed
mod list parsing
1 parent b879777 commit 625b10e

File tree

2 files changed

+52
-12
lines changed

2 files changed

+52
-12
lines changed

src/Manager.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class Manager {
2626

2727
std::vector<std::string> loadedModMenus;
2828

29+
std::vector<std::string> formattedModsListVector;
30+
2931
std::vector<std::string> knownCLCTModesBesidesCombined = {"Images", "Oxygene One"};
3032

3133
std::vector<std::string> downwellStages = {"CAVERNS", "CATACOMBS", "AQUIFIER", "LIMBO", "ABYSS"};
@@ -57,6 +59,8 @@ class Manager {
5759
std::string sharedReplacementSprite = "";
5860
std::string chosenMode = "";
5961

62+
std::string modsListFormatted = "";
63+
6064
static Manager* getSharedInstance() {
6165
if (!instance) {
6266
instance = new Manager();

src/MenuLayer.cpp

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,52 @@
77
using namespace geode::prelude;
88

99
class $modify(MyMenuLayer, MenuLayer) {
10-
bool init() {
11-
bool result = MenuLayer::init();
12-
const auto mods = Loader::get()->getAllMods();
13-
Manager* manager = managerMacro;
14-
std::ranges::for_each(mods, [&](const Mod* mod) {
15-
std::string modID = mod->getID();
16-
if (manager->modIDToModMenu.contains(modID)) {
17-
manager->loadedModMenus.push_back(modID);
18-
}
19-
});
20-
return result;
21-
}
10+
bool init() {
11+
bool result = MenuLayer::init();
12+
const auto mods = Loader::get()->getAllMods();
13+
Manager* manager = managerMacro;
14+
std::ranges::for_each(mods, [&](const Mod* mod) {
15+
const std::string& modID = mod->getID();
16+
17+
if (manager->modIDToModMenu.contains(modID)) manager->loadedModMenus.push_back(modID);
18+
19+
std::string formattedByline = "by ";
20+
for (const std::string& developer : mod->getDevelopers()) {
21+
formattedByline = formattedByline.append(fmt::format("{}, ", developer));
22+
}
23+
if (!formattedByline.empty() && utils::string::endsWith(formattedByline, ", ")) {
24+
formattedByline.pop_back();
25+
formattedByline.pop_back();
26+
}
27+
28+
std::string formattedProblemsList = "";
29+
if (std::vector<LoadProblem> problems = mod->getAllProblems(); !problems.empty()) {
30+
formattedProblemsList = " {";
31+
for (const auto [type, cause, message] : problems) {
32+
if (type == LoadProblem::Type::Suggestion || type == LoadProblem::Type::Recommendation) continue;
33+
std::string colorTag = "<c-FF0000>";
34+
if (type == LoadProblem::Type::Conflict || type == LoadProblem::Type::Duplicate || type == LoadProblem::Type::DisabledDependency || type == LoadProblem::Type::MissingDependency) colorTag = "<cy>";
35+
else if (type == LoadProblem::Type::UnsupportedVersion || type == LoadProblem::Type::UnsupportedGeodeVersion || type == LoadProblem::Type::NeedsNewerGeodeVersion) colorTag = "<c-AAAAAA>";
36+
formattedProblemsList = formattedProblemsList.append(fmt::format("{}{}</c>, ", colorTag, message));
37+
}
38+
if (!formattedProblemsList.empty() && utils::string::endsWith(formattedProblemsList, ", ")) {
39+
formattedProblemsList.pop_back();
40+
formattedProblemsList.pop_back();
41+
}
42+
formattedProblemsList = formattedProblemsList.append("}");
43+
}
44+
45+
const std::string& formattedModListItem = fmt::format(
46+
"- {}{}</c> {} {} [{}]{}",
47+
mod->isEnabled() ? "<cg>" : "<c-FF0000>",
48+
mod->getName(), mod->getVersion().toVString(), formattedByline,
49+
modID, formattedProblemsList
50+
);
51+
52+
manager->formattedModsListVector.push_back(formattedModListItem);
53+
manager->modsListFormatted = manager->modsListFormatted.append(fmt::format("{}\n", formattedModListItem));
54+
});
55+
log::info("manager->modsListFormatted:\n{}", manager->modsListFormatted);
56+
return result;
57+
}
2258
};

0 commit comments

Comments
 (0)