aboutsummaryrefslogtreecommitdiff
path: root/launcher/modplatform/modrinth
diff options
context:
space:
mode:
authorflow <thiagodonato300@gmail.com>2022-03-06 16:45:39 -0300
committerflow <thiagodonato300@gmail.com>2022-03-06 16:45:39 -0300
commit39bd04f06ff42623f7349096d707c4a877fc7cd7 (patch)
tree8e3b6dd4da7e843f26afece1a1991ed6410bce71 /launcher/modplatform/modrinth
parentd755174bee1b1c5ba507d1d407236190501c7940 (diff)
downloadPrismLauncher-39bd04f06ff42623f7349096d707c4a877fc7cd7.tar.gz
PrismLauncher-39bd04f06ff42623f7349096d707c4a877fc7cd7.tar.bz2
PrismLauncher-39bd04f06ff42623f7349096d707c4a877fc7cd7.zip
refactor: use Enum instead of raw int for ModLoaderType
Diffstat (limited to 'launcher/modplatform/modrinth')
-rw-r--r--launcher/modplatform/modrinth/ModrinthAPI.h29
1 files changed, 27 insertions, 2 deletions
diff --git a/launcher/modplatform/modrinth/ModrinthAPI.h b/launcher/modplatform/modrinth/ModrinthAPI.h
index 4ae8b8f9..44a362c8 100644
--- a/launcher/modplatform/modrinth/ModrinthAPI.h
+++ b/launcher/modplatform/modrinth/ModrinthAPI.h
@@ -2,17 +2,24 @@
#include "modplatform/ModAPI.h"
+#include <QDebug>
+
class ModrinthAPI : public ModAPI {
public:
- inline QString getModSearchURL(int offset, QString query, QString sort, bool fabricCompatible, QString version) const override
+ inline QString getModSearchURL(int offset, QString query, QString sort, ModLoaderType modLoader, QString version) const override
{
+ if(!validateModLoader(modLoader)){
+ qWarning() << "Modrinth only have Forge and Fabric-compatible mods!";
+ return "";
+ }
+
return QString("https://api.modrinth.com/v2/search?"
"offset=%1&" "limit=25&" "query=%2&" "index=%3&"
"facets=[[\"categories:%4\"],[\"versions:%5\"],[\"project_type:mod\"]]")
.arg(offset)
.arg(query)
.arg(sort)
- .arg(fabricCompatible ? "fabric" : "forge")
+ .arg(getModLoaderString(modLoader))
.arg(version);
};
@@ -22,4 +29,22 @@ class ModrinthAPI : public ModAPI {
};
inline QString getAuthorURL(const QString& name) const override { return "https://modrinth.com/user/" + name; };
+
+ private:
+ inline bool validateModLoader(ModLoaderType modLoader) const{
+ return modLoader == Any || modLoader == Forge || modLoader == Fabric;
+ }
+
+ inline QString getModLoaderString(ModLoaderType modLoader) const{
+ switch(modLoader){
+ case Any:
+ return "fabric, forge";
+ case Forge:
+ return "forge";
+ case Fabric:
+ return "fabric";
+ default:
+ return "";
+ }
+ }
};