refactor: use Enum instead of raw int for ModLoaderType

This commit is contained in:
flow
2022-03-06 16:45:39 -03:00
parent d755174bee
commit 39bd04f06f
4 changed files with 42 additions and 6 deletions

View File

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