diff --git a/loader/src/server/Server.cpp b/loader/src/server/Server.cpp index 31ca8d30..949b298c 100644 --- a/loader/src/server/Server.cpp +++ b/loader/src/server/Server.cpp @@ -1,5 +1,7 @@ #include "Server.hpp" #include <Geode/utils/JsonValidation.hpp> +#include <Geode/utils/ranges.hpp> +#include <fmt/core.h> #include <loader/ModMetadataImpl.hpp> #include <fmt/chrono.h> @@ -418,6 +420,7 @@ Result<ServerModMetadata> ServerModMetadata::parse(matjson::Value const& raw) { auto dev = ServerDeveloper(); obj.needs("username").into(dev.username); obj.needs("display_name").into(dev.displayName); + obj.needs("is_owner").into(dev.isOwner); res.developers.push_back(dev); developerNames.push_back(dev.displayName); } @@ -454,6 +457,24 @@ Result<ServerModMetadata> ServerModMetadata::parse(matjson::Value const& raw) { return Ok(res); } +std::string ServerModMetadata::formatDevelopersToString() const { + std::optional<ServerDeveloper> owner = ranges::find(developers, [] (auto item) { + return item.isOwner; + }); + switch (developers.size()) { + case 0: return "Unknown"; break; + case 1: return developers.front().displayName; break; + case 2: return developers.front().displayName + " & " + developers.back().displayName; break; + default: { + if (owner) { + return fmt::format("{} + {} More", owner->displayName, developers.size() - 1); + } else { + return fmt::format("{} + {} More", developers.front().displayName, developers.size() - 1); + } + } break; + } +} + Result<ServerModsList> ServerModsList::parse(matjson::Value const& raw) { auto json = raw; JsonChecker checker(json); diff --git a/loader/src/server/Server.hpp b/loader/src/server/Server.hpp index c2309008..45b5c3dd 100644 --- a/loader/src/server/Server.hpp +++ b/loader/src/server/Server.hpp @@ -21,6 +21,7 @@ namespace server { struct ServerDeveloper final { std::string username; std::string displayName; + bool isOwner; }; struct ServerModVersion final { @@ -60,6 +61,7 @@ namespace server { static Result<ServerModMetadata> parse(matjson::Value const& json); ModMetadata latestVersion() const; + std::string formatDevelopersToString() const; bool hasUpdateForInstalledMod() const; }; diff --git a/loader/src/ui/mods/list/ModItem.cpp b/loader/src/ui/mods/list/ModItem.cpp index 3d728534..bc177b29 100644 --- a/loader/src/ui/mods/list/ModItem.cpp +++ b/loader/src/ui/mods/list/ModItem.cpp @@ -63,7 +63,7 @@ bool ModItem::init(ModSource&& source) { m_developers->ignoreAnchorPointForPosition(false); m_developers->setAnchorPoint({ .0f, .5f }); - auto by = "By " + ModMetadata::formatDeveloperDisplayString(m_source.getMetadata().getDevelopers()); + auto by = "By " + m_source.formatDevelopers(); m_developerLabel = CCLabelBMFont::create(by.c_str(), "goldFont.fnt"); m_developerLabel->setID("developers-label"); auto developersBtn = CCMenuItemSpriteExtra::create( diff --git a/loader/src/ui/mods/sources/ModSource.cpp b/loader/src/ui/mods/sources/ModSource.cpp index db0a49f5..33791ad9 100644 --- a/loader/src/ui/mods/sources/ModSource.cpp +++ b/loader/src/ui/mods/sources/ModSource.cpp @@ -1,4 +1,6 @@ #include "ModSource.hpp" + +#include <Geode/loader/ModMetadata.hpp> #include <Geode/ui/GeodeUI.hpp> #include <server/DownloadManager.hpp> #include <Geode/binding/GameObject.hpp> @@ -68,6 +70,22 @@ ModMetadata ModSource::getMetadata() const { }, }, m_value); } + +std::string ModSource::formatDevelopers() const { + return std::visit(makeVisitor { + [](Mod* mod) { + return ModMetadata::formatDeveloperDisplayString(mod->getMetadata().getDevelopers()); + }, + [](server::ServerModMetadata const& metadata) { + // Versions should be guaranteed to have at least one item + return metadata.formatDevelopersToString(); + }, + [](ModSuggestion const& suggestion) { + return ModMetadata::formatDeveloperDisplayString(suggestion.suggestion.getDevelopers()); + }, + }, m_value); +} + CCNode* ModSource::createModLogo() const { return std::visit(makeVisitor { [](Mod* mod) { diff --git a/loader/src/ui/mods/sources/ModSource.hpp b/loader/src/ui/mods/sources/ModSource.hpp index f0c02fa3..7698e1a5 100644 --- a/loader/src/ui/mods/sources/ModSource.hpp +++ b/loader/src/ui/mods/sources/ModSource.hpp @@ -44,6 +44,7 @@ public: server::ServerModMetadata const* asServer() const; ModSuggestion const* asSuggestion() const; + std::string formatDevelopers() const; server::ServerRequest<server::ServerModMetadata> fetchServerInfo() const; server::ServerRequest<std::optional<std::string>> fetchAbout() const; server::ServerRequest<std::optional<std::string>> fetchChangelog() const;