fix: fix Modrinth query when Quilt is in use
This commit is contained in:
parent
56ce7f5dcd
commit
fcdc7a1a35
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "modplatform/ModAPI.h"
|
||||
#include "modplatform/helpers/NetworkModAPI.h"
|
||||
|
||||
#include <QDebug>
|
||||
@ -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<Version> 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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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<ModFilterWidget::Filter> { return m_filter; }
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user