2022-05-15 16:50:05 +05:30
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
/*
|
|
|
|
* PolyMC - Minecraft Launcher
|
2022-05-15 16:55:58 +05:30
|
|
|
* Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
|
2022-05-15 16:50:05 +05:30
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, version 3.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2022-03-03 07:31:23 +05:30
|
|
|
#pragma once
|
|
|
|
|
2022-05-15 16:13:02 +05:30
|
|
|
#include "BuildConfig.h"
|
2022-04-18 16:42:42 +05:30
|
|
|
#include "modplatform/ModAPI.h"
|
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
|
|
|
|
2022-05-19 12:10:28 +05:30
|
|
|
static auto getModLoaderStrings(const ModLoaderTypes types) -> const QStringList
|
2022-04-18 16:42:42 +05:30
|
|
|
{
|
|
|
|
QStringList l;
|
2022-05-19 12:10:28 +05:30
|
|
|
for (auto loader : {Forge, Fabric, Quilt})
|
2022-04-18 16:42:42 +05:30
|
|
|
{
|
2022-05-19 16:05:44 +05:30
|
|
|
if ((types & loader) || types == Unspecified)
|
2022-05-19 12:10:28 +05:30
|
|
|
{
|
|
|
|
l << ModAPI::getModLoaderString(loader);
|
|
|
|
}
|
2022-04-18 16:42:42 +05:30
|
|
|
}
|
2022-05-19 16:05:44 +05:30
|
|
|
if ((types & Quilt) && (~types & Fabric)) // Add Fabric if Quilt is in use, if Fabric isn't already there
|
2022-05-19 12:10:28 +05:30
|
|
|
l << ModAPI::getModLoaderString(Fabric);
|
2022-04-18 16:42:42 +05:30
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2022-05-19 12:10:28 +05:30
|
|
|
static auto getModLoaderFilters(ModLoaderTypes types) -> const QString
|
2022-04-18 16:42:42 +05:30
|
|
|
{
|
|
|
|
QStringList l;
|
2022-05-19 12:10:28 +05:30
|
|
|
for (auto loader : getModLoaderStrings(types))
|
2022-04-18 16:42:42 +05:30
|
|
|
{
|
|
|
|
l << QString("\"categories:%1\"").arg(loader);
|
|
|
|
}
|
|
|
|
return l.join(',');
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2022-05-19 12:10:28 +05:30
|
|
|
if (!validateModLoaders(args.loaders)) {
|
2022-03-07 01:15:39 +05:30
|
|
|
qWarning() << "Modrinth only have Forge and Fabric-compatible mods!";
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2022-05-15 16:13:02 +05:30
|
|
|
return QString(BuildConfig.MODRINTH_PROD_URL +
|
|
|
|
"/search?"
|
|
|
|
"offset=%1&"
|
|
|
|
"limit=25&"
|
|
|
|
"query=%2&"
|
|
|
|
"index=%3&"
|
|
|
|
"facets=[[%4],%5[\"project_type:mod\"]]")
|
2022-03-08 00:52:57 +05:30
|
|
|
.arg(args.offset)
|
|
|
|
.arg(args.search)
|
|
|
|
.arg(args.sorting)
|
2022-05-19 12:10:28 +05:30
|
|
|
.arg(getModLoaderFilters(args.loaders))
|
2022-04-03 03:51:02 +05:30
|
|
|
.arg(getGameVersionsArray(args.versions));
|
2022-03-03 07:31:23 +05:30
|
|
|
};
|
|
|
|
|
2022-05-24 18:08:48 +05:30
|
|
|
inline auto getModInfoURL(QString& id) const -> QString override
|
|
|
|
{
|
|
|
|
return BuildConfig.MODRINTH_PROD_URL + "/project/" + id;
|
|
|
|
};
|
|
|
|
|
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-05-15 16:13:02 +05:30
|
|
|
return QString(BuildConfig.MODRINTH_PROD_URL +
|
|
|
|
"/project/%1/version?"
|
|
|
|
"game_versions=[%2]"
|
|
|
|
"loaders=[\"%3\"]")
|
2022-03-25 03:09:53 +05:30
|
|
|
.arg(args.addonId)
|
|
|
|
.arg(getGameVersionsString(args.mcVersions))
|
2022-05-19 12:10:28 +05:30
|
|
|
.arg(getModLoaderStrings(args.loaders).join("\",\""));
|
2022-03-03 07:31:23 +05:30
|
|
|
};
|
|
|
|
|
2022-04-03 03:51:02 +05:30
|
|
|
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 04:38:37 +05:30
|
|
|
return s.isEmpty() ? QString() : QString("[%1],").arg(s);
|
2022-04-03 03:51:02 +05:30
|
|
|
}
|
|
|
|
|
2022-05-19 12:10:28 +05:30
|
|
|
inline auto validateModLoaders(ModLoaderTypes loaders) const -> bool
|
2022-03-08 01:16:08 +05:30
|
|
|
{
|
2022-05-19 16:05:44 +05:30
|
|
|
return (loaders == Unspecified) || (loaders & (Forge | Fabric | Quilt));
|
2022-03-08 01:16:08 +05:30
|
|
|
}
|
|
|
|
|
2022-03-03 07:31:23 +05:30
|
|
|
};
|