From 39bd04f06ff42623f7349096d707c4a877fc7cd7 Mon Sep 17 00:00:00 2001 From: flow Date: Sun, 6 Mar 2022 16:45:39 -0300 Subject: refactor: use Enum instead of raw int for ModLoaderType --- launcher/modplatform/modrinth/ModrinthAPI.h | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'launcher/modplatform/modrinth') 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 + 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 ""; + } + } }; -- cgit