Track dependencies in Mods page (#3738)

This commit is contained in:
Alexandru Ionut Tripon 2026-01-31 20:28:01 +02:00 committed by GitHub
commit ef1e35d585
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 577 additions and 18 deletions

View file

@ -178,4 +178,40 @@ Side SideUtils::fromString(QString side)
return Side::UniversalSide;
return Side::UniversalSide;
}
QString DependencyTypeUtils::toString(DependencyType type)
{
switch (type) {
case DependencyType::REQUIRED:
return "REQUIRED";
case DependencyType::OPTIONAL:
return "OPTIONAL";
case DependencyType::INCOMPATIBLE:
return "INCOMPATIBLE";
case DependencyType::EMBEDDED:
return "EMBEDDED";
case DependencyType::TOOL:
return "TOOL";
case DependencyType::INCLUDE:
return "INCLUDE";
case DependencyType::UNKNOWN:
return "UNKNOWN";
}
return "UNKNOWN";
}
DependencyType DependencyTypeUtils::fromString(const QString& str)
{
static const QHash<QString, DependencyType> map = {
{ "REQUIRED", DependencyType::REQUIRED },
{ "OPTIONAL", DependencyType::OPTIONAL },
{ "INCOMPATIBLE", DependencyType::INCOMPATIBLE },
{ "EMBEDDED", DependencyType::EMBEDDED },
{ "TOOL", DependencyType::TOOL },
{ "INCLUDE", DependencyType::INCLUDE },
{ "UNKNOWN", DependencyType::UNKNOWN },
};
return map.value(str.toUpper(), DependencyType::UNKNOWN);
}
} // namespace ModPlatform

View file

@ -58,6 +58,11 @@ QString toString(Side side);
Side fromString(QString side);
} // namespace SideUtils
namespace DependencyTypeUtils {
QString toString(DependencyType type);
DependencyType fromString(const QString& str);
} // namespace DependencyTypeUtils
namespace ProviderCapabilities {
const char* name(ResourceProvider);
QString readableName(ResourceProvider);

View file

@ -122,6 +122,7 @@ auto V1::createModFormat([[maybe_unused]] const QDir& index_dir,
if (mod.version_number.isNull()) // on CurseForge, there is only a version name - not a version number
mod.version_number = mod_version.version;
mod.dependencies = mod_version.dependencies;
return mod;
}
@ -190,6 +191,16 @@ void V1::updateModIndex(const QDir& index_dir, Mod& mod)
return;
}
toml::array deps;
for (auto dep : mod.dependencies) {
auto tbl = toml::table{ { "addonId", dep.addonId.toString().toStdString() },
{ "type", ModPlatform::DependencyTypeUtils::toString(dep.type).toStdString() } };
if (!dep.version.isEmpty()) {
tbl.emplace("version", dep.version.toStdString());
}
deps.push_back(tbl);
}
// Put TOML data into the file
QTextStream in_stream(&index_file);
{
@ -200,6 +211,7 @@ void V1::updateModIndex(const QDir& index_dir, Mod& mod)
{ "x-prismlauncher-mc-versions", mcVersions },
{ "x-prismlauncher-release-type", mod.releaseType.toString().toStdString() },
{ "x-prismlauncher-version-number", mod.version_number.toStdString() },
{ "x-prismlauncher-dependencies", deps },
{ "download",
toml::table{
{ "mode", mod.mode.toStdString() },
@ -330,6 +342,23 @@ auto V1::getIndexForMod(const QDir& index_dir, QString slug) -> Mod
return {};
}
}
{ // dependencies
auto deps = table["x-prismlauncher-dependencies"].as_array();
if (deps) {
for (auto&& depNode : *deps) {
auto dep = depNode.as_table();
if (dep) {
ModPlatform::Dependency d;
d.addonId = stringEntry(*dep, "addonId");
if (dep->contains("version")) {
d.version = stringEntry(*dep, "version");
}
d.type = ModPlatform::DependencyTypeUtils::fromString(stringEntry(*dep, "type"));
mod.dependencies << d;
}
}
}
}
return mod;
}

View file

@ -55,6 +55,8 @@ class V1 {
QVariant project_id{};
QString version_number{};
QList<ModPlatform::Dependency> dependencies;
public:
// This is a totally heuristic, but should work for now.
auto isValid() const -> bool { return !slug.isEmpty() && !project_id.isNull(); }