aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--launcher/modplatform/modrinth/ModrinthPackIndex.cpp9
-rw-r--r--launcher/modplatform/modrinth/ModrinthPackIndex.h3
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp19
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthModel.h6
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp13
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthPage.h3
6 files changed, 37 insertions, 16 deletions
diff --git a/launcher/modplatform/modrinth/ModrinthPackIndex.cpp b/launcher/modplatform/modrinth/ModrinthPackIndex.cpp
index 89e827b4..ce408ca0 100644
--- a/launcher/modplatform/modrinth/ModrinthPackIndex.cpp
+++ b/launcher/modplatform/modrinth/ModrinthPackIndex.cpp
@@ -34,12 +34,19 @@ void Modrinth::loadIndexedPackVersions(Modrinth::IndexedPack & pack, QJsonArray
continue;
}
// pick the latest version supported
- file.mcVersion = versionArray[0].toString();
+ for(auto mcVer : versionArray){
+ file.mcVersion.append(mcVer.toString());
+ }
+ auto loaders = Json::requireArray(obj,"loaders");
+ for(auto loader : loaders){
+ file.loaders.append(loader.toString());
+ }
file.version = Json::requireString(obj, "name");
//TODO show all the files ?
auto parent = Json::requireArray(obj, "files")[0].toObject();
file.downloadUrl = Json::requireString(parent, "url");
file.fileName = Json::requireString(parent, "filename");
+
unsortedVersions.append(file);
}
auto orderSortPredicate = [](const IndexedVersion & a, const IndexedVersion & b) -> bool
diff --git a/launcher/modplatform/modrinth/ModrinthPackIndex.h b/launcher/modplatform/modrinth/ModrinthPackIndex.h
index e39b69ab..b3cffc40 100644
--- a/launcher/modplatform/modrinth/ModrinthPackIndex.h
+++ b/launcher/modplatform/modrinth/ModrinthPackIndex.h
@@ -19,10 +19,11 @@ struct IndexedVersion {
QString addonId;
QString fileId;
QString version;
- QString mcVersion;
+ QVector<QString> mcVersion;
QString downloadUrl;
QString date;
QString fileName;
+ QVector<QString> loaders;
};
struct IndexedPack
diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp
index 0242465b..e7f66768 100644
--- a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp
+++ b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp
@@ -1,18 +1,19 @@
#include "ModrinthModel.h"
#include "Application.h"
+#include "minecraft/MinecraftInstance.h"
+#include "minecraft/PackProfile.h"
+#include "ModrinthPage.h"
#include <Json.h>
#include <MMCStrings.h>
#include <Version.h>
#include <QtMath>
-#include <QLabel>
-#include <RWStorage.h>
namespace Modrinth {
-ListModel::ListModel(QObject *parent) : QAbstractListModel(parent)
+ListModel::ListModel(ModrinthPage *parent) : QAbstractListModel(parent)
{
}
@@ -158,14 +159,18 @@ const char* sorts[4]{"relevance","downloads","updated","newest"};
void ListModel::performPaginatedSearch()
{
- NetJob *netJob = new NetJob("Modrinth::Search", APPLICATION->network());
+
+ QString mcVersion = ((MinecraftInstance *)((ModrinthPage *)parent())->m_instance)->getPackProfile()->getComponentVersion("net.minecraft");
+ bool hasFabric = !((MinecraftInstance *)((ModrinthPage *)parent())->m_instance)->getPackProfile()->getComponentVersion("net.fabricmc.fabric-loader").isEmpty();
+ auto netJob = new NetJob("Modrinth::Search", APPLICATION->network());
auto searchUrl = QString(
"https://api.modrinth.com/api/v1/mod?"
"offset=%1&"
"limit=25&"
"query=%2&"
- "index=%3"
- ).arg(nextSearchOffset).arg(currentSearchTerm).arg(sorts[currentSort]);
+ "index=%3&"
+ "filters=categories=\"%4\" AND versions=\"%5\""
+ ).arg(nextSearchOffset).arg(currentSearchTerm).arg(sorts[currentSort]).arg(hasFabric ? "fabric" : "forge").arg(mcVersion);
netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), &response));
jobPtr = netJob;
jobPtr->start();
@@ -173,7 +178,7 @@ void ListModel::performPaginatedSearch()
QObject::connect(netJob, &NetJob::failed, this, &ListModel::searchRequestFailed);
}
-void ListModel::searchWithTerm(const QString& term, int sort)
+void ListModel::searchWithTerm(const QString &term, const int sort)
{
if(currentSearchTerm == term && currentSearchTerm.isNull() == term.isNull() && currentSort == sort) {
return;
diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h
index 7bd06f6a..53f1f134 100644
--- a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h
+++ b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h
@@ -17,6 +17,8 @@
#include <modplatform/flame/FlamePackIndex.h>
#include "modplatform/modrinth/ModrinthPackIndex.h"
+#include "BaseInstance.h"
+#include "ModrinthPage.h"
namespace Modrinth {
@@ -29,7 +31,7 @@ class ListModel : public QAbstractListModel
Q_OBJECT
public:
- ListModel(QObject *parent);
+ ListModel(ModrinthPage *parent);
virtual ~ListModel();
int rowCount(const QModelIndex &parent) const override;
@@ -40,7 +42,7 @@ public:
void fetchMore(const QModelIndex & parent) override;
void getLogo(const QString &logo, const QString &logoUrl, LogoCallback callback);
- void searchWithTerm(const QString & term, const int sort);
+ void searchWithTerm(const QString &term, const int sort);
private slots:
void performPaginatedSearch();
diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp
index e72a57f6..96797062 100644
--- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp
+++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp
@@ -9,11 +9,11 @@
#include "InstanceImportTask.h"
#include "ModrinthModel.h"
#include "ModDownloadTask.h"
-#include "ui/pages/instance/ModFolderPage.h"
+#include "minecraft/MinecraftInstance.h"
#include "minecraft/PackProfile.h"
ModrinthPage::ModrinthPage(ModDownloadDialog *dialog, BaseInstance *instance)
- : QWidget(dialog), ui(new Ui::ModrinthPage), dialog(dialog), m_instance(instance)
+ : QWidget(dialog), m_instance(instance), ui(new Ui::ModrinthPage), dialog(dialog)
{
ui->setupUi(this);
connect(ui->searchButton, &QPushButton::clicked, this, &ModrinthPage::triggerSearch);
@@ -135,8 +135,13 @@ void ModrinthPage::onSelectionChanged(QModelIndex first, QModelIndex second)
qDebug() << *response;
qWarning() << "Error while reading Modrinth mod version: " << e.cause();
}
-
- for(auto version : current.versions) {
+ auto packProfile = ((MinecraftInstance *)m_instance)->getPackProfile();
+ QString mcVersion = packProfile->getComponentVersion("net.minecraft");
+ QString loaderString = (packProfile->getComponentVersion("net.minecraftforge").isEmpty()) ? "fabric" : "forge";
+ for(const auto& version : current.versions) {
+ if(!version.mcVersion.contains(mcVersion) || !version.loaders.contains(loaderString)){
+ continue;
+ }
ui->versionSelectionBox->addItem(version.version, QVariant(version.downloadUrl));
}
diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h
index 8ff5cbe4..3748d836 100644
--- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h
+++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.h
@@ -47,6 +47,8 @@ public:
bool eventFilter(QObject * watched, QEvent * event) override;
+ BaseInstance *m_instance;
+
private:
void suggestCurrent();
@@ -62,5 +64,4 @@ private:
Modrinth::IndexedPack current;
QString selectedVersion;
- BaseInstance *m_instance;
};