2022-03-03 02:01:23 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-03-07 19:46:08 +00:00
|
|
|
#include "modplatform/helpers/NetworkModAPI.h"
|
2022-03-03 02:01:23 +00:00
|
|
|
|
2022-03-06 19:45:39 +00:00
|
|
|
#include <QDebug>
|
|
|
|
|
2022-03-07 19:46:08 +00:00
|
|
|
class ModrinthAPI : public NetworkModAPI {
|
2022-03-03 02:01:23 +00:00
|
|
|
public:
|
2022-03-08 14:12:35 +00:00
|
|
|
inline auto getAuthorURL(const QString& name) const -> QString { return "https://modrinth.com/user/" + name; };
|
2022-03-07 19:22:57 +00:00
|
|
|
|
|
|
|
private:
|
2022-03-08 14:12:35 +00:00
|
|
|
inline auto getModSearchURL(SearchArgs& args) const -> QString override
|
2022-03-07 19:22:57 +00:00
|
|
|
{
|
|
|
|
if (!validateModLoader(args.mod_loader)) {
|
2022-03-06 19:45:39 +00:00
|
|
|
qWarning() << "Modrinth only have Forge and Fabric-compatible mods!";
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2022-03-07 19:22:57 +00:00
|
|
|
return QString(
|
|
|
|
"https://api.modrinth.com/v2/search?"
|
|
|
|
"offset=%1&"
|
|
|
|
"limit=25&"
|
|
|
|
"query=%2&"
|
|
|
|
"index=%3&"
|
2022-04-03 00:08:37 +01:00
|
|
|
"facets=[[\"categories:%4\"],%5[\"project_type:mod\"]]")
|
2022-03-07 19:22:57 +00:00
|
|
|
.arg(args.offset)
|
|
|
|
.arg(args.search)
|
|
|
|
.arg(args.sorting)
|
|
|
|
.arg(getModLoaderString(args.mod_loader))
|
2022-04-02 23:21:02 +01:00
|
|
|
.arg(getGameVersionsArray(args.versions));
|
2022-03-03 02:01:23 +00:00
|
|
|
};
|
|
|
|
|
2022-03-24 21:39:53 +00:00
|
|
|
inline auto getVersionsURL(VersionSearchArgs& args) const -> QString override
|
2022-03-03 02:01:23 +00:00
|
|
|
{
|
2022-03-24 21:39:53 +00:00
|
|
|
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 02:01:23 +00:00
|
|
|
};
|
|
|
|
|
2022-04-02 23:21:02 +01:00
|
|
|
auto getGameVersionsArray(std::list<Version> mcVersions) const -> QString
|
|
|
|
{
|
|
|
|
QString s;
|
|
|
|
for(auto& ver : mcVersions){
|
|
|
|
s += QString("\"versions:%1\",").arg(ver.toString());
|
|
|
|
}
|
|
|
|
s.remove(s.length() - 1, 1); //remove last comma
|
2022-04-03 00:08:37 +01:00
|
|
|
return s.isEmpty() ? QString() : QString("[%1],").arg(s);
|
2022-04-02 23:21:02 +01:00
|
|
|
}
|
|
|
|
|
2022-04-14 20:55:03 +01:00
|
|
|
static auto getModLoaderString(ModLoaderType type) -> const QString
|
2022-03-07 19:22:57 +00:00
|
|
|
{
|
2022-04-14 20:55:03 +01:00
|
|
|
if (type == Unspecified)
|
|
|
|
return "fabric, forge, quilt";
|
2022-04-15 11:38:27 +01:00
|
|
|
// TODO: remove this once Quilt drops official Fabric support
|
|
|
|
if (type == Quilt) // NOTE: Most if not all Fabric mods should work *currently*
|
|
|
|
return "fabric, quilt";
|
2022-04-14 20:55:03 +01:00
|
|
|
return ModAPI::getModLoaderString(type);
|
2022-03-06 19:45:39 +00:00
|
|
|
}
|
2022-03-07 19:46:08 +00:00
|
|
|
|
2022-03-08 14:12:35 +00:00
|
|
|
inline auto validateModLoader(ModLoaderType modLoader) const -> bool
|
2022-03-07 19:46:08 +00:00
|
|
|
{
|
2022-04-14 20:55:03 +01:00
|
|
|
return modLoader == Unspecified || modLoader == Forge || modLoader == Fabric || modLoader == Quilt;
|
2022-03-07 19:46:08 +00:00
|
|
|
}
|
|
|
|
|
2022-03-03 02:01:23 +00:00
|
|
|
};
|