feat: Use version filter when searching mods

This commit is contained in:
flow 2022-04-02 18:34:26 -03:00
parent c2b97c3e3f
commit c730fd6e5f
5 changed files with 23 additions and 21 deletions

View File

@ -3,6 +3,8 @@
#include <QString>
#include <QList>
#include "Version.h"
namespace ModPlatform {
class ListModel;
}
@ -22,7 +24,7 @@ class ModAPI {
QString search;
QString sorting;
ModLoaderType mod_loader;
QString version;
std::list<Version> versions;
};
virtual void searchMods(CallerType* caller, SearchArgs&& args) const = 0;
@ -30,7 +32,7 @@ class ModAPI {
struct VersionSearchArgs {
QString addonId;
QList<QString> mcVersions;
std::list<Version> mcVersions;
ModLoaderType loader;
};
@ -53,4 +55,16 @@ class ModAPI {
}
return "";
}
protected:
inline auto getGameVersionsString(std::list<Version> mcVersions) const -> QString
{
QString s;
for(auto& ver : mcVersions){
s += ver.toString();
if(ver != mcVersions.back())
s += ",";
}
return s;
}
};

View File

@ -22,7 +22,7 @@ class FlameAPI : public NetworkModAPI {
.arg(args.search)
.arg(args.sorting)
.arg(args.mod_loader)
.arg(args.version);
.arg(getGameVersionsString(args.versions));
};
inline auto getVersionsURL(VersionSearchArgs& args) const -> QString override

View File

@ -27,7 +27,7 @@ class ModrinthAPI : public NetworkModAPI {
.arg(args.search)
.arg(args.sorting)
.arg(getModLoaderString(args.mod_loader))
.arg(args.version);
.arg(getGameVersionsString(args.versions));
};
inline auto getVersionsURL(VersionSearchArgs& args) const -> QString override
@ -40,17 +40,6 @@ class ModrinthAPI : public NetworkModAPI {
.arg(getModLoaderString(args.loader));
};
inline auto getGameVersionsString(QList<QString> mcVersions) const -> QString
{
QString s;
for(int i = 0; i < mcVersions.count(); i++){
s += mcVersions.at(i);
if(i < mcVersions.count() - 1)
s += ",";
}
return s;
}
static auto getModLoaderString(ModLoaderType type) -> const QString
{
if (type == Unspecified)

View File

@ -72,7 +72,7 @@ void ListModel::performPaginatedSearch()
auto profile = (dynamic_cast<MinecraftInstance*>((dynamic_cast<ModPage*>(parent()))->m_instance))->getPackProfile();
m_parent->apiProvider()->searchMods(this,
{ nextSearchOffset, currentSearchTerm, getSorts()[currentSort], profile->getModLoader(), getMineVersions().at(0) });
{ nextSearchOffset, currentSearchTerm, getSorts()[currentSort], profile->getModLoader(), getMineVersions() });
}
void ListModel::searchWithTerm(const QString& term, const int sort)
@ -223,9 +223,7 @@ void ListModel::versionRequestSucceeded(QJsonDocument doc, QString addonId)
/******** Helpers ********/
auto ModPlatform::ListModel::getMineVersions() const -> QList<QString>
auto ModPlatform::ListModel::getMineVersions() const -> std::list<Version>
{
return { (dynamic_cast<MinecraftInstance*>((dynamic_cast<ModPage*>(parent()))->m_instance))
->getPackProfile()
->getComponentVersion("net.minecraft") };
return m_parent->getFilter()->versions;
}

View File

@ -7,6 +7,7 @@
#include "net/NetJob.h"
class ModPage;
class Version;
namespace ModPlatform {
@ -62,7 +63,7 @@ class ListModel : public QAbstractListModel {
void requestLogo(QString file, QString url);
inline auto getMineVersions() const -> QList<QString>;
inline auto getMineVersions() const -> std::list<Version>;
protected:
ModPage* m_parent;