Filtering per mod loader & mc version

This commit is contained in:
timoreo 2022-01-15 08:51:47 +01:00
parent 2896f70cd8
commit 4b37c46889
No known key found for this signature in database
GPG Key ID: 121A72C3512BA288
6 changed files with 37 additions and 16 deletions

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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();

View File

@ -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));
}

View File

@ -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;
};