2022-03-03 07:31:23 +05:30
|
|
|
#pragma once
|
|
|
|
|
2022-03-08 01:16:08 +05:30
|
|
|
#include "modplatform/helpers/NetworkModAPI.h"
|
2022-03-03 07:31:23 +05:30
|
|
|
|
2022-03-07 01:15:39 +05:30
|
|
|
#include <QDebug>
|
|
|
|
|
2022-03-08 01:16:08 +05:30
|
|
|
class ModrinthAPI : public NetworkModAPI {
|
2022-03-03 07:31:23 +05:30
|
|
|
public:
|
2022-03-08 19:42:35 +05:30
|
|
|
inline auto getAuthorURL(const QString& name) const -> QString { return "https://modrinth.com/user/" + name; };
|
2022-03-08 00:52:57 +05:30
|
|
|
|
|
|
|
private:
|
2022-03-08 19:42:35 +05:30
|
|
|
inline auto getModSearchURL(SearchArgs& args) const -> QString override
|
2022-03-08 00:52:57 +05:30
|
|
|
{
|
|
|
|
if (!validateModLoader(args.mod_loader)) {
|
2022-03-07 01:15:39 +05:30
|
|
|
qWarning() << "Modrinth only have Forge and Fabric-compatible mods!";
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2022-03-08 00:52:57 +05:30
|
|
|
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(args.offset)
|
|
|
|
.arg(args.search)
|
|
|
|
.arg(args.sorting)
|
|
|
|
.arg(getModLoaderString(args.mod_loader))
|
|
|
|
.arg(args.version);
|
2022-03-03 07:31:23 +05:30
|
|
|
};
|
|
|
|
|
2022-03-25 03:09:53 +05:30
|
|
|
inline auto getVersionsURL(VersionSearchArgs& args) const -> QString override
|
2022-03-03 07:31:23 +05:30
|
|
|
{
|
2022-03-25 03:09:53 +05:30
|
|
|
return QString("https://api.modrinth.com/v2/project/%1/version?"
|
|
|
|
"game_versions=[%2]"
|
|
|
|
"loaders=[%3]")
|
|
|
|
.arg(args.addonId)
|
|
|
|
.arg(getGameVersionsString(args.mcVersions))
|
|
|
|
.arg(getModLoaderString(args.loader));
|
2022-03-03 07:31:23 +05:30
|
|
|
};
|
|
|
|
|
2022-03-25 03:09:53 +05:30
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-04-15 01:25:03 +05:30
|
|
|
static auto getModLoaderString(ModLoaderType type) -> const QString
|
2022-03-08 00:52:57 +05:30
|
|
|
{
|
2022-04-15 01:25:03 +05:30
|
|
|
if (type == Unspecified)
|
|
|
|
return "fabric, forge, quilt";
|
|
|
|
return ModAPI::getModLoaderString(type);
|
2022-03-07 01:15:39 +05:30
|
|
|
}
|
2022-03-08 01:16:08 +05:30
|
|
|
|
2022-03-08 19:42:35 +05:30
|
|
|
inline auto validateModLoader(ModLoaderType modLoader) const -> bool
|
2022-03-08 01:16:08 +05:30
|
|
|
{
|
2022-04-15 01:25:03 +05:30
|
|
|
return modLoader == Unspecified || modLoader == Forge || modLoader == Fabric || modLoader == Quilt;
|
2022-03-08 01:16:08 +05:30
|
|
|
}
|
|
|
|
|
2022-03-03 07:31:23 +05:30
|
|
|
};
|