Merge pull request #450 from Scrumplex/fix-quilt-mod-dl

This commit is contained in:
Sefa Eyeoglu 2022-04-19 20:36:37 +02:00 committed by GitHub
commit 027c666265
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 57 additions and 25 deletions

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include "modplatform/ModAPI.h"
#include "modplatform/helpers/NetworkModAPI.h" #include "modplatform/helpers/NetworkModAPI.h"
#include <QDebug> #include <QDebug>
@ -8,6 +9,36 @@ class ModrinthAPI : public NetworkModAPI {
public: public:
inline auto getAuthorURL(const QString& name) const -> QString { return "https://modrinth.com/user/" + name; }; 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: private:
inline auto getModSearchURL(SearchArgs& args) const -> QString override inline auto getModSearchURL(SearchArgs& args) const -> QString override
{ {
@ -22,11 +53,11 @@ class ModrinthAPI : public NetworkModAPI {
"limit=25&" "limit=25&"
"query=%2&" "query=%2&"
"index=%3&" "index=%3&"
"facets=[[\"categories:%4\"],%5[\"project_type:mod\"]]") "facets=[[%4],%5[\"project_type:mod\"]]")
.arg(args.offset) .arg(args.offset)
.arg(args.search) .arg(args.search)
.arg(args.sorting) .arg(args.sorting)
.arg(getModLoaderString(args.mod_loader)) .arg(getModLoaderFilters(args.mod_loader))
.arg(getGameVersionsArray(args.versions)); .arg(getGameVersionsArray(args.versions));
}; };
@ -34,10 +65,10 @@ class ModrinthAPI : public NetworkModAPI {
{ {
return QString("https://api.modrinth.com/v2/project/%1/version?" return QString("https://api.modrinth.com/v2/project/%1/version?"
"game_versions=[%2]" "game_versions=[%2]"
"loaders=[%3]") "loaders=[\"%3\"]")
.arg(args.addonId) .arg(args.addonId)
.arg(getGameVersionsString(args.mcVersions)) .arg(getGameVersionsString(args.mcVersions))
.arg(getModLoaderString(args.loader)); .arg(getModLoaderStrings(args.loader).join("\",\""));
}; };
auto getGameVersionsArray(std::list<Version> mcVersions) const -> QString auto getGameVersionsArray(std::list<Version> mcVersions) const -> QString
@ -50,16 +81,6 @@ class ModrinthAPI : public NetworkModAPI {
return s.isEmpty() ? QString() : QString("[%1],").arg(s); 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 inline auto validateModLoader(ModLoaderType modLoader) const -> bool
{ {
return modLoader == Unspecified || modLoader == Forge || modLoader == Fabric || modLoader == Quilt; return modLoader == Unspecified || modLoader == Forge || modLoader == Fabric || modLoader == Quilt;

View File

@ -170,14 +170,12 @@ void ModPage::updateModVersions(int prev_count)
QString mcVersion = packProfile->getComponentVersion("net.minecraft"); QString mcVersion = packProfile->getComponentVersion("net.minecraft");
QString loaderString = ModAPI::getModLoaderString(packProfile->getModLoader());
for (int i = 0; i < current.versions.size(); i++) { for (int i = 0; i < current.versions.size(); i++) {
auto version = current.versions[i]; auto version = current.versions[i];
bool valid = false; bool valid = false;
for(auto& mcVer : m_filter->versions){ for(auto& mcVer : m_filter->versions){
//NOTE: Flame doesn't care about loaderString, so passing it changes nothing. //NOTE: Flame doesn't care about loader, so passing it changes nothing.
if (validateVersion(version, mcVer.toString(), loaderString)) { if (validateVersion(version, mcVer.toString(), packProfile->getModLoader())) {
valid = true; valid = true;
break; break;
} }

View File

@ -37,7 +37,7 @@ class ModPage : public QWidget, public BasePage {
void retranslate() override; void retranslate() override;
auto shouldDisplay() const -> bool override = 0; 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 apiProvider() const -> const ModAPI* { return api.get(); };
auto getFilter() const -> const std::shared_ptr<ModFilterWidget::Filter> { return m_filter; } auto getFilter() const -> const std::shared_ptr<ModFilterWidget::Filter> { return m_filter; }

View File

@ -61,9 +61,9 @@ FlameModPage::FlameModPage(ModDownloadDialog* dialog, BaseInstance* instance)
connect(ui->modSelectionButton, &QPushButton::clicked, this, &FlameModPage::onModSelected); 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); return ver.mcVersion.contains(mineVer);
} }

View File

@ -35,6 +35,7 @@
#pragma once #pragma once
#include "modplatform/ModAPI.h"
#include "ui/pages/modplatform/ModPage.h" #include "ui/pages/modplatform/ModPage.h"
#include "modplatform/flame/FlameAPI.h" #include "modplatform/flame/FlameAPI.h"
@ -54,7 +55,7 @@ class FlameModPage : public ModPage {
inline auto debugName() const -> QString override { return "Flame"; } inline auto debugName() const -> QString override { return "Flame"; }
inline auto metaEntryBase() const -> QString override { return "FlameMods"; }; 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; auto shouldDisplay() const -> bool override;
}; };

View File

@ -34,6 +34,7 @@
*/ */
#include "ModrinthPage.h" #include "ModrinthPage.h"
#include "modplatform/modrinth/ModrinthAPI.h"
#include "ui_ModPage.h" #include "ui_ModPage.h"
#include "ModrinthModel.h" #include "ModrinthModel.h"
@ -60,9 +61,19 @@ ModrinthPage::ModrinthPage(ModDownloadDialog* dialog, BaseInstance* instance)
connect(ui->modSelectionButton, &QPushButton::clicked, this, &ModrinthPage::onModSelected); 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 // I don't know why, but doing this on the parent class makes it so that

View File

@ -35,6 +35,7 @@
#pragma once #pragma once
#include "modplatform/ModAPI.h"
#include "ui/pages/modplatform/ModPage.h" #include "ui/pages/modplatform/ModPage.h"
#include "modplatform/modrinth/ModrinthAPI.h" #include "modplatform/modrinth/ModrinthAPI.h"
@ -54,7 +55,7 @@ class ModrinthPage : public ModPage {
inline auto debugName() const -> QString override { return "Modrinth"; } inline auto debugName() const -> QString override { return "Modrinth"; }
inline auto metaEntryBase() const -> QString override { return "ModrinthPacks"; }; 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; auto shouldDisplay() const -> bool override;
}; };