make universal resource type

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97
2025-03-24 23:06:53 +02:00
parent d63dba43d6
commit 9a51cd55df
23 changed files with 143 additions and 81 deletions

View File

@@ -43,8 +43,6 @@ QList<ModLoaderType> modLoaderTypesToList(ModLoaderTypes flags);
enum class ResourceProvider { MODRINTH, FLAME };
enum class ResourceType { MOD, RESOURCE_PACK, SHADER_PACK, MODPACK, DATA_PACK };
enum class DependencyType { REQUIRED, OPTIONAL, INCOMPATIBLE, EMBEDDED, TOOL, INCLUDE, UNKNOWN };
enum class Side { NoSide = 0, ClientSide = 1 << 0, ServerSide = 1 << 1, UniversalSide = ClientSide | ServerSide };

View File

@@ -48,6 +48,7 @@
#include "../Version.h"
#include "modplatform/ModIndex.h"
#include "modplatform/ResourceType.h"
#include "tasks/Task.h"
/* Simple class with a common interface for interacting with APIs */

View File

@@ -0,0 +1,41 @@
// SPDX-FileCopyrightText: 2022 Rachel Powers <508861+Ryex@users.noreply.github.com>
//
// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Rachel Powers <508861+Ryex@users.noreply.github.com>
*
* 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/>.
*/
#include "ResourceType.h"
namespace ModPlatform {
static const QMap<ResourceType, QString> s_packedTypeNames = { { ResourceType::ResourcePack, QObject::tr("resource pack") },
{ ResourceType::TexturePack, QObject::tr("texture pack") },
{ ResourceType::DataPack, QObject::tr("data pack") },
{ ResourceType::ShaderPack, QObject::tr("shader pack") },
{ ResourceType::World, QObject::tr("world save") },
{ ResourceType::Mod, QObject::tr("mod") },
{ ResourceType::Unknown, QObject::tr("unknown") } };
namespace ResourceTypeUtils {
QString getName(ResourceType type)
{
return s_packedTypeNames.constFind(type).value();
}
} // namespace ResourceTypeUtils
} // namespace ModPlatform

View File

@@ -0,0 +1,39 @@
// SPDX-FileCopyrightText: 2022 Rachel Powers <508861+Ryex@users.noreply.github.com>
//
// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 Rachel Powers <508861+Ryex@users.noreply.github.com>
*
* 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/>.
*/
#pragma once
#include <set>
#include <QDebug>
#include <QFileInfo>
#include <QObject>
namespace ModPlatform {
enum class ResourceType { Mod, ResourcePack, ShaderPack, Modpack, DataPack, World, Screenshots, TexturePack, Unknown };
namespace ResourceTypeUtils {
static const std::set<ResourceType> ValidResources = { ResourceType::DataPack, ResourceType::ResourcePack, ResourceType::TexturePack,
ResourceType::ShaderPack, ResourceType::World, ResourceType::Mod };
QString getName(ResourceType type);
} // namespace ResourceTypeUtils
} // namespace ModPlatform

View File

@@ -84,18 +84,18 @@ void Flame::FileResolvingTask::executeTask()
m_task->start();
}
PackedResourceType getResourceType(int classId)
ModPlatform::ResourceType getResourceType(int classId)
{
switch (classId) {
case 17: // Worlds
return PackedResourceType::WorldSave;
return ModPlatform::ResourceType::World;
case 6: // Mods
return PackedResourceType::Mod;
return ModPlatform::ResourceType::Mod;
case 12: // Resource Packs
// return PackedResourceType::ResourcePack; // not really a resourcepack
// return ModPlatform::ResourceType::ResourcePack; // not really a resourcepack
/* fallthrough */
case 4546: // Customization
// return PackedResourceType::ShaderPack; // not really a shaderPack
// return ModPlatform::ResourceType::ShaderPack; // not really a shaderPack
/* fallthrough */
case 4471: // Modpacks
/* fallthrough */
@@ -104,7 +104,7 @@ PackedResourceType getResourceType(int classId)
case 4559: // Addons
/* fallthrough */
default:
return PackedResourceType::UNKNOWN;
return ModPlatform::ResourceType::Unknown;
}
}
@@ -256,7 +256,7 @@ void Flame::FileResolvingTask::getFlameProjects()
setStatus(tr("Parsing API response from CurseForge for '%1'...").arg(file->version.fileName));
FlameMod::loadIndexedPack(file->pack, entry_obj);
file->resourceType = getResourceType(Json::requireInteger(entry_obj, "classId", "modClassId"));
if (file->resourceType == PackedResourceType::WorldSave) {
if (file->resourceType == ModPlatform::ResourceType::World) {
file->targetFolder = "saves";
}
}

View File

@@ -182,7 +182,7 @@ Task::Ptr FlameAPI::getCategories(std::shared_ptr<QByteArray> response, ModPlatf
Task::Ptr FlameAPI::getModCategories(std::shared_ptr<QByteArray> response)
{
return getCategories(response, ModPlatform::ResourceType::MOD);
return getCategories(response, ModPlatform::ResourceType::Mod);
}
QList<ModPlatform::Category> FlameAPI::loadModCategories(std::shared_ptr<QByteArray> response)

View File

@@ -41,15 +41,15 @@ class FlameAPI : public NetworkResourceAPI {
{
switch (type) {
default:
case ModPlatform::ResourceType::MOD:
case ModPlatform::ResourceType::Mod:
return 6;
case ModPlatform::ResourceType::RESOURCE_PACK:
case ModPlatform::ResourceType::ResourcePack:
return 12;
case ModPlatform::ResourceType::SHADER_PACK:
case ModPlatform::ResourceType::ShaderPack:
return 6552;
case ModPlatform::ResourceType::MODPACK:
case ModPlatform::ResourceType::Modpack:
return 4471;
case ModPlatform::ResourceType::DATA_PACK:
case ModPlatform::ResourceType::DataPack:
return 6945;
}
}

View File

@@ -517,7 +517,7 @@ void FlameCreationTask::idResolverSucceeded(QEventLoop& loop)
QList<BlockedMod> blocked_mods;
auto anyBlocked = false;
for (const auto& result : results.values()) {
if (result.resourceType != PackedResourceType::Mod) {
if (result.resourceType != ModPlatform::ResourceType::Mod) {
m_otherResources.append(std::make_pair(result.version.fileName, result.targetFolder));
}
@@ -687,29 +687,29 @@ void FlameCreationTask::validateOtherResources(QEventLoop& loop)
QString worldPath;
switch (type) {
case PackedResourceType::Mod:
case ModPlatform::ResourceType::Mod:
validatePath(fileName, targetFolder, "mods");
zipMods.push_back(fileName);
break;
case PackedResourceType::ResourcePack:
case ModPlatform::ResourceType::ResourcePack:
validatePath(fileName, targetFolder, "resourcepacks");
break;
case PackedResourceType::TexturePack:
case ModPlatform::ResourceType::TexturePack:
validatePath(fileName, targetFolder, "texturepacks");
break;
case PackedResourceType::DataPack:
case ModPlatform::ResourceType::DataPack:
validatePath(fileName, targetFolder, "datapacks");
break;
case PackedResourceType::ShaderPack:
case ModPlatform::ResourceType::ShaderPack:
// in theory flame API can't do this but who knows, that *may* change ?
// better to handle it if it *does* occur in the future
validatePath(fileName, targetFolder, "shaderpacks");
break;
case PackedResourceType::WorldSave:
case ModPlatform::ResourceType::World:
worldPath = validatePath(fileName, targetFolder, "saves");
installWorld(worldPath);
break;
case PackedResourceType::UNKNOWN:
case ModPlatform::ResourceType::Unknown:
/* fallthrough */
default:
qDebug() << "Can't Identify" << fileName << "at" << localPath << ", leaving it where it is.";

View File

@@ -40,8 +40,8 @@
#include <QMap>
#include <QString>
#include <QUrl>
#include "minecraft/mod/tasks/LocalResourceParse.h"
#include "modplatform/ModIndex.h"
#include "modplatform/ResourceType.h"
namespace Flame {
struct File {
@@ -55,7 +55,7 @@ struct File {
// our
QString targetFolder = QStringLiteral("mods");
PackedResourceType resourceType;
ModPlatform::ResourceType resourceType;
};
struct Modloader {

View File

@@ -104,15 +104,15 @@ class ModrinthAPI : public NetworkResourceAPI {
[[nodiscard]] static QString resourceTypeParameter(ModPlatform::ResourceType type)
{
switch (type) {
case ModPlatform::ResourceType::MOD:
case ModPlatform::ResourceType::Mod:
return "mod";
case ModPlatform::ResourceType::RESOURCE_PACK:
case ModPlatform::ResourceType::ResourcePack:
return "resourcepack";
case ModPlatform::ResourceType::SHADER_PACK:
case ModPlatform::ResourceType::ShaderPack:
return "shader";
case ModPlatform::ResourceType::DATA_PACK:
case ModPlatform::ResourceType::DataPack:
return "datapack";
case ModPlatform::ResourceType::MODPACK:
case ModPlatform::ResourceType::Modpack:
return "modpack";
default:
qWarning() << "Invalid resource type for Modrinth API!";