refactor: use Enum instead of raw int for ModLoaderType
This commit is contained in:
parent
d755174bee
commit
39bd04f06f
@ -6,7 +6,16 @@ class ModAPI {
|
||||
public:
|
||||
virtual ~ModAPI() = default;
|
||||
|
||||
inline virtual QString getModSearchURL(int, QString, QString, bool, QString) const { return ""; };
|
||||
// https://docs.curseforge.com/?http#tocS_ModLoaderType
|
||||
enum ModLoaderType {
|
||||
Any = 0,
|
||||
Forge = 1,
|
||||
Cauldron = 2,
|
||||
LiteLoader = 3,
|
||||
Fabric = 4
|
||||
};
|
||||
|
||||
inline virtual QString getModSearchURL(int, QString, QString, ModLoaderType, QString) const { return ""; };
|
||||
inline virtual QString getVersionsURL(const QString& addonId) const { return ""; };
|
||||
inline virtual QString getAuthorURL(const QString& name) const { return ""; };
|
||||
};
|
||||
|
@ -4,7 +4,8 @@
|
||||
|
||||
class FlameAPI : public ModAPI {
|
||||
public:
|
||||
inline QString getModSearchURL(int index, QString searchFilter, QString sort, bool fabricCompatible, QString version) const override
|
||||
|
||||
inline QString getModSearchURL(int index, QString searchFilter, QString sort, ModLoaderType modLoader, QString version) const override
|
||||
{
|
||||
return QString("https://addons-ecs.forgesvc.net/api/v2/addon/search?"
|
||||
"gameId=432&" "categoryId=0&" "sectionId=6&"
|
||||
@ -14,7 +15,7 @@ class FlameAPI : public ModAPI {
|
||||
.arg(index)
|
||||
.arg(searchFilter)
|
||||
.arg(sort)
|
||||
.arg(fabricCompatible ? 4 : 1) // Enum: https://docs.curseforge.com/?http#tocS_ModLoaderType
|
||||
.arg(modLoader)
|
||||
.arg(version);
|
||||
};
|
||||
|
||||
|
@ -2,17 +2,24 @@
|
||||
|
||||
#include "modplatform/ModAPI.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
class ModrinthAPI : public ModAPI {
|
||||
public:
|
||||
inline QString getModSearchURL(int offset, QString query, QString sort, bool fabricCompatible, QString version) const override
|
||||
inline QString getModSearchURL(int offset, QString query, QString sort, ModLoaderType modLoader, QString version) const override
|
||||
{
|
||||
if(!validateModLoader(modLoader)){
|
||||
qWarning() << "Modrinth only have Forge and Fabric-compatible mods!";
|
||||
return "";
|
||||
}
|
||||
|
||||
return QString("https://api.modrinth.com/v2/search?"
|
||||
"offset=%1&" "limit=25&" "query=%2&" "index=%3&"
|
||||
"facets=[[\"categories:%4\"],[\"versions:%5\"],[\"project_type:mod\"]]")
|
||||
.arg(offset)
|
||||
.arg(query)
|
||||
.arg(sort)
|
||||
.arg(fabricCompatible ? "fabric" : "forge")
|
||||
.arg(getModLoaderString(modLoader))
|
||||
.arg(version);
|
||||
};
|
||||
|
||||
@ -22,4 +29,22 @@ class ModrinthAPI : public ModAPI {
|
||||
};
|
||||
|
||||
inline QString getAuthorURL(const QString& name) const override { return "https://modrinth.com/user/" + name; };
|
||||
|
||||
private:
|
||||
inline bool validateModLoader(ModLoaderType modLoader) const{
|
||||
return modLoader == Any || modLoader == Forge || modLoader == Fabric;
|
||||
}
|
||||
|
||||
inline QString getModLoaderString(ModLoaderType modLoader) const{
|
||||
switch(modLoader){
|
||||
case Any:
|
||||
return "fabric, forge";
|
||||
case Forge:
|
||||
return "forge";
|
||||
case Fabric:
|
||||
return "fabric";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -125,7 +125,8 @@ void ListModel::performPaginatedSearch()
|
||||
->getComponentVersion("net.fabricmc.fabric-loader")
|
||||
.isEmpty();
|
||||
auto netJob = new NetJob(QString("%1::Search").arg(m_parent->debugName()), APPLICATION->network());
|
||||
auto searchUrl = m_parent->apiProvider()->getModSearchURL(nextSearchOffset, currentSearchTerm, getSorts()[currentSort], hasFabric, mcVersion);
|
||||
auto searchUrl = m_parent->apiProvider()->getModSearchURL(
|
||||
nextSearchOffset, currentSearchTerm, getSorts()[currentSort], hasFabric ? ModAPI::Fabric : ModAPI::Forge, mcVersion);
|
||||
|
||||
netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), &response));
|
||||
jobPtr = netJob;
|
||||
|
Loading…
Reference in New Issue
Block a user