diff --git a/launcher/modplatform/modrinth/ModrinthAPI.h b/launcher/modplatform/modrinth/ModrinthAPI.h index 84dd7d03..86852c94 100644 --- a/launcher/modplatform/modrinth/ModrinthAPI.h +++ b/launcher/modplatform/modrinth/ModrinthAPI.h @@ -1,5 +1,6 @@ #pragma once +#include "modplatform/ModAPI.h" #include "modplatform/helpers/NetworkModAPI.h" #include @@ -8,6 +9,36 @@ class ModrinthAPI : public NetworkModAPI { public: inline auto getAuthorURL(const QString& name) const -> QString { return "https://modrinth.com/user/" + name; }; + static auto getModLoaderStrings(ModLoaderType type) -> const QStringList + { + QStringList l; + switch (type) + { + case Unspecified: + for (auto loader : {Forge, Fabric, Quilt}) + { + l << ModAPI::getModLoaderString(loader); + } + break; + + case Quilt: + l << ModAPI::getModLoaderString(Fabric); + default: + l << ModAPI::getModLoaderString(type); + } + return l; + } + + static auto getModLoaderFilters(ModLoaderType type) -> const QString + { + QStringList l; + for (auto loader : getModLoaderStrings(type)) + { + l << QString("\"categories:%1\"").arg(loader); + } + return l.join(','); + } + private: inline auto getModSearchURL(SearchArgs& args) const -> QString override { @@ -22,11 +53,11 @@ class ModrinthAPI : public NetworkModAPI { "limit=25&" "query=%2&" "index=%3&" - "facets=[[\"categories:%4\"],%5[\"project_type:mod\"]]") + "facets=[[%4],%5[\"project_type:mod\"]]") .arg(args.offset) .arg(args.search) .arg(args.sorting) - .arg(getModLoaderString(args.mod_loader)) + .arg(getModLoaderFilters(args.mod_loader)) .arg(getGameVersionsArray(args.versions)); }; @@ -34,10 +65,10 @@ class ModrinthAPI : public NetworkModAPI { { return QString("https://api.modrinth.com/v2/project/%1/version?" "game_versions=[%2]" - "loaders=[%3]") + "loaders=[\"%3\"]") .arg(args.addonId) .arg(getGameVersionsString(args.mcVersions)) - .arg(getModLoaderString(args.loader)); + .arg(getModLoaderStrings(args.loader).join("\",\"")); }; auto getGameVersionsArray(std::list mcVersions) const -> QString @@ -50,16 +81,6 @@ class ModrinthAPI : public NetworkModAPI { return s.isEmpty() ? QString() : QString("[%1],").arg(s); } - static auto getModLoaderString(ModLoaderType type) -> const QString - { - if (type == Unspecified) - return "fabric, forge, quilt"; - // TODO: remove this once Quilt drops official Fabric support - if (type == Quilt) // NOTE: Most if not all Fabric mods should work *currently* - return "fabric, quilt"; - return ModAPI::getModLoaderString(type); - } - inline auto validateModLoader(ModLoaderType modLoader) const -> bool { return modLoader == Unspecified || modLoader == Forge || modLoader == Fabric || modLoader == Quilt; diff --git a/launcher/ui/pages/modplatform/ModPage.cpp b/launcher/ui/pages/modplatform/ModPage.cpp index 29f6b601..6dd3a453 100644 --- a/launcher/ui/pages/modplatform/ModPage.cpp +++ b/launcher/ui/pages/modplatform/ModPage.cpp @@ -170,14 +170,12 @@ void ModPage::updateModVersions(int prev_count) QString mcVersion = packProfile->getComponentVersion("net.minecraft"); - QString loaderString = ModAPI::getModLoaderString(packProfile->getModLoader()); - for (int i = 0; i < current.versions.size(); i++) { auto version = current.versions[i]; bool valid = false; for(auto& mcVer : m_filter->versions){ - //NOTE: Flame doesn't care about loaderString, so passing it changes nothing. - if (validateVersion(version, mcVer.toString(), loaderString)) { + //NOTE: Flame doesn't care about loader, so passing it changes nothing. + if (validateVersion(version, mcVer.toString(), packProfile->getModLoader())) { valid = true; break; } diff --git a/launcher/ui/pages/modplatform/ModPage.h b/launcher/ui/pages/modplatform/ModPage.h index 85aaede9..eb89b0e2 100644 --- a/launcher/ui/pages/modplatform/ModPage.h +++ b/launcher/ui/pages/modplatform/ModPage.h @@ -37,7 +37,7 @@ class ModPage : public QWidget, public BasePage { void retranslate() override; auto shouldDisplay() const -> bool override = 0; - virtual auto validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, QString loaderVer = "") const -> bool = 0; + virtual auto validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, ModAPI::ModLoaderType loader = ModAPI::Unspecified) const -> bool = 0; auto apiProvider() const -> const ModAPI* { return api.get(); }; auto getFilter() const -> const std::shared_ptr { return m_filter; } diff --git a/launcher/ui/pages/modplatform/flame/FlameModPage.cpp b/launcher/ui/pages/modplatform/flame/FlameModPage.cpp index 864ae8e6..9afbdb52 100644 --- a/launcher/ui/pages/modplatform/flame/FlameModPage.cpp +++ b/launcher/ui/pages/modplatform/flame/FlameModPage.cpp @@ -61,9 +61,9 @@ FlameModPage::FlameModPage(ModDownloadDialog* dialog, BaseInstance* instance) connect(ui->modSelectionButton, &QPushButton::clicked, this, &FlameModPage::onModSelected); } -auto FlameModPage::validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, QString loaderVer) const -> bool +auto FlameModPage::validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, ModAPI::ModLoaderType loader) const -> bool { - (void) loaderVer; + Q_UNUSED(loader); return ver.mcVersion.contains(mineVer); } diff --git a/launcher/ui/pages/modplatform/flame/FlameModPage.h b/launcher/ui/pages/modplatform/flame/FlameModPage.h index d96a0720..27cbdb8c 100644 --- a/launcher/ui/pages/modplatform/flame/FlameModPage.h +++ b/launcher/ui/pages/modplatform/flame/FlameModPage.h @@ -35,6 +35,7 @@ #pragma once +#include "modplatform/ModAPI.h" #include "ui/pages/modplatform/ModPage.h" #include "modplatform/flame/FlameAPI.h" @@ -54,7 +55,7 @@ class FlameModPage : public ModPage { inline auto debugName() const -> QString override { return "Flame"; } inline auto metaEntryBase() const -> QString override { return "FlameMods"; }; - auto validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, QString loaderVer = "") const -> bool override; + auto validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, ModAPI::ModLoaderType loader = ModAPI::Unspecified) const -> bool override; auto shouldDisplay() const -> bool override; }; diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp index ddaf96e2..f0e73c51 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp @@ -34,6 +34,7 @@ */ #include "ModrinthPage.h" +#include "modplatform/modrinth/ModrinthAPI.h" #include "ui_ModPage.h" #include "ModrinthModel.h" @@ -60,9 +61,19 @@ ModrinthPage::ModrinthPage(ModDownloadDialog* dialog, BaseInstance* instance) connect(ui->modSelectionButton, &QPushButton::clicked, this, &ModrinthPage::onModSelected); } -auto ModrinthPage::validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, QString loaderVer) const -> bool +auto ModrinthPage::validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, ModAPI::ModLoaderType loader) const -> bool { - return ver.mcVersion.contains(mineVer) && ver.loaders.contains(loaderVer); + auto loaderStrings = ModrinthAPI::getModLoaderStrings(loader); + + auto loaderCompatible = false; + for (auto remoteLoader : ver.loaders) + { + if (loaderStrings.contains(remoteLoader)) { + loaderCompatible = true; + break; + } + } + return ver.mcVersion.contains(mineVer) && loaderCompatible; } // I don't know why, but doing this on the parent class makes it so that diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h index 0bde43eb..e3a0e1f0 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h @@ -35,6 +35,7 @@ #pragma once +#include "modplatform/ModAPI.h" #include "ui/pages/modplatform/ModPage.h" #include "modplatform/modrinth/ModrinthAPI.h" @@ -54,7 +55,7 @@ class ModrinthPage : public ModPage { inline auto debugName() const -> QString override { return "Modrinth"; } inline auto metaEntryBase() const -> QString override { return "ModrinthPacks"; }; - auto validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, QString loaderVer = "") const -> bool override; + auto validateVersion(ModPlatform::IndexedVersion& ver, QString mineVer, ModAPI::ModLoaderType loader = ModAPI::Unspecified) const -> bool override; auto shouldDisplay() const -> bool override; };