2022-05-26 22:18:54 +01:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
/*
|
|
|
|
* PolyMC - Minecraft Launcher
|
|
|
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following copyright and
|
|
|
|
* permission notice:
|
|
|
|
*
|
|
|
|
* Copyright 2013-2021 MultiMC Contributors
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-03-03 02:01:23 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QString>
|
2022-03-24 21:39:53 +00:00
|
|
|
#include <QList>
|
2022-05-02 20:34:55 +01:00
|
|
|
#include <list>
|
2022-03-03 02:01:23 +00:00
|
|
|
|
2022-10-26 01:44:29 +01:00
|
|
|
#include "../Version.h"
|
2022-06-19 18:29:21 +01:00
|
|
|
#include "net/NetJob.h"
|
2022-04-02 22:34:26 +01:00
|
|
|
|
2022-03-07 19:22:57 +00:00
|
|
|
namespace ModPlatform {
|
|
|
|
class ListModel;
|
2022-05-24 13:38:48 +01:00
|
|
|
struct IndexedPack;
|
2022-03-07 19:22:57 +00:00
|
|
|
}
|
|
|
|
|
2022-03-03 02:01:23 +00:00
|
|
|
class ModAPI {
|
2022-03-07 19:22:57 +00:00
|
|
|
protected:
|
|
|
|
using CallerType = ModPlatform::ListModel;
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~ModAPI() = default;
|
|
|
|
|
2022-05-19 07:40:28 +01:00
|
|
|
enum ModLoaderType {
|
|
|
|
Unspecified = 0,
|
|
|
|
Forge = 1 << 0,
|
|
|
|
Cauldron = 1 << 1,
|
|
|
|
LiteLoader = 1 << 2,
|
|
|
|
Fabric = 1 << 3,
|
|
|
|
Quilt = 1 << 4
|
|
|
|
};
|
|
|
|
Q_DECLARE_FLAGS(ModLoaderTypes, ModLoaderType)
|
2022-03-03 02:01:23 +00:00
|
|
|
|
2022-03-07 19:22:57 +00:00
|
|
|
struct SearchArgs {
|
|
|
|
int offset;
|
|
|
|
QString search;
|
|
|
|
QString sorting;
|
2022-05-19 07:40:28 +01:00
|
|
|
ModLoaderTypes loaders;
|
2022-04-02 22:34:26 +01:00
|
|
|
std::list<Version> versions;
|
2022-03-07 19:22:57 +00:00
|
|
|
};
|
2022-03-06 19:45:39 +00:00
|
|
|
|
2022-03-07 19:46:08 +00:00
|
|
|
virtual void searchMods(CallerType* caller, SearchArgs&& args) const = 0;
|
2022-07-18 23:15:02 +01:00
|
|
|
virtual void getModInfo(ModPlatform::IndexedPack& pack, std::function<void(QJsonDocument&, ModPlatform::IndexedPack&)> callback) = 0;
|
2022-06-19 18:29:21 +01:00
|
|
|
|
2022-06-28 11:09:58 +01:00
|
|
|
virtual auto getProject(QString addonId, QByteArray* response) const -> NetJob* = 0;
|
|
|
|
virtual auto getProjects(QStringList addonIds, QByteArray* response) const -> NetJob* = 0;
|
2022-03-24 21:39:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
struct VersionSearchArgs {
|
|
|
|
QString addonId;
|
2022-04-02 22:34:26 +01:00
|
|
|
std::list<Version> mcVersions;
|
2022-05-19 07:40:28 +01:00
|
|
|
ModLoaderTypes loaders;
|
2022-03-24 21:39:53 +00:00
|
|
|
};
|
|
|
|
|
2022-07-18 23:22:31 +01:00
|
|
|
virtual void getVersions(VersionSearchArgs&& args, std::function<void(QJsonDocument&, QString)> callback) const = 0;
|
2022-04-14 20:55:03 +01:00
|
|
|
|
|
|
|
static auto getModLoaderString(ModLoaderType type) -> const QString {
|
|
|
|
switch (type) {
|
|
|
|
case Unspecified:
|
|
|
|
break;
|
|
|
|
case Forge:
|
|
|
|
return "forge";
|
|
|
|
case Cauldron:
|
|
|
|
return "cauldron";
|
|
|
|
case LiteLoader:
|
|
|
|
return "liteloader";
|
|
|
|
case Fabric:
|
|
|
|
return "fabric";
|
|
|
|
case Quilt:
|
|
|
|
return "quilt";
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
2022-04-02 22:34:26 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
inline auto getGameVersionsString(std::list<Version> mcVersions) const -> QString
|
|
|
|
{
|
|
|
|
QString s;
|
|
|
|
for(auto& ver : mcVersions){
|
2022-05-29 17:23:34 +01:00
|
|
|
s += QString("\"%1\",").arg(ver.toString());
|
2022-04-02 22:34:26 +01:00
|
|
|
}
|
2022-04-02 23:21:02 +01:00
|
|
|
s.remove(s.length() - 1, 1); //remove last comma
|
2022-04-02 22:34:26 +01:00
|
|
|
return s;
|
|
|
|
}
|
2022-03-03 02:01:23 +00:00
|
|
|
};
|