PrismLauncher/launcher/modplatform/flame/FlameAPI.h

69 lines
2.5 KiB
C
Raw Normal View History

#pragma once
#include "modplatform/helpers/NetworkModAPI.h"
class FlameAPI : public NetworkModAPI {
2022-05-08 08:22:50 +01:00
private:
inline auto getSortFieldInt(QString sortString) const -> int
{
return sortString == "Featured" ? 1
: sortString == "Popularity" ? 2
: sortString == "LastUpdated" ? 3
: sortString == "Name" ? 4
: sortString == "Author" ? 5
: sortString == "TotalDownloads" ? 6
: sortString == "Category" ? 7
: sortString == "GameVersion" ? 8
: 1;
}
private:
inline auto getModSearchURL(SearchArgs& args) const -> QString override
{
auto gameVersionStr = args.versions.size() != 0 ? QString("gameVersion=%1").arg(args.versions.front().toString()) : QString();
return QString(
2022-05-08 08:22:50 +01:00
"https://api.curseforge.com/v1/mods/search?"
"gameId=432&"
2022-05-08 08:22:50 +01:00
"classId=6&"
"index=%1&"
"pageSize=25&"
"searchFilter=%2&"
2022-05-08 08:22:50 +01:00
"sortField=%3&"
"sortOrder=desc&"
"modLoaderType=%4&"
"%5")
.arg(args.offset)
.arg(args.search)
2022-05-08 08:22:50 +01:00
.arg(getSortFieldInt(args.sorting))
.arg(getMappedModLoader(args.loaders))
.arg(gameVersionStr);
};
inline auto getVersionsURL(VersionSearchArgs& args) const -> QString override
{
2022-05-08 08:22:50 +01:00
QString gameVersionQuery = args.mcVersions.size() == 1 ? QString("gameVersion=%1&").arg(args.mcVersions.front().toString()) : "";
QString modLoaderQuery = QString("modLoaderType=%1&").arg(getMappedModLoader(args.loaders));
2022-05-08 08:22:50 +01:00
return QString("https://api.curseforge.com/v1/mods/%1/files?pageSize=10000&%2%3")
.arg(args.addonId)
.arg(gameVersionQuery)
.arg(modLoaderQuery);
};
public:
static auto getMappedModLoader(const ModLoaderTypes loaders) -> const int
{
// https://docs.curseforge.com/?http#tocS_ModLoaderType
if (loaders & Forge)
return 1;
if (loaders & Fabric)
return 4;
// TODO: remove this once Quilt drops official Fabric support
if (loaders & Quilt) // NOTE: Most if not all Fabric mods should work *currently*
return 4; // Quilt would probably be 5
return 0;
}
};