Skip to content

Commit

Permalink
fix #15
Browse files Browse the repository at this point in the history
  • Loading branch information
PoloNX committed Jun 27, 2023
1 parent 51ff906 commit e7714e9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
4 changes: 2 additions & 2 deletions include/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace utils {
nlohmann::json getInstalledGames();
nlohmann::json searchGames(std::string gameTitle);
std::string replaceSpacesWithPlus(const std::string& str);
nlohmann::json getMods(const int& gameID, const int& page = 1);
nlohmann::json getMods(const int& gameID, const std::string& search, const int& page = 1);
nlohmann::json getMods(const int& gameID, int& page);
nlohmann::json getMods(const int& gameID, const std::string& search, int& page);
nlohmann::json getDownloadLinks(const std::string& ModelName, const int& idRow);
uint8_t* getIconFromTitleId(const std::string& titleId);
std::vector<brls::Image*> getModsImages(const nlohmann::json& mod_json, const int& bigImage, size_t& sizeOfArray);
Expand Down
15 changes: 6 additions & 9 deletions source/mods_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@
#include "SimpleIniParser.hpp"
#include <filesystem>
#include <regex>
#include <iostream>

namespace i18n = brls::i18n;
using namespace i18n::literals;

ModsList::ModsList(Game game, int page) : AppletFrame(true, true), currentGame(game), page(page) {
ModsList::ModsList(Game game, int page_f) : AppletFrame(true, true), currentGame(game), page(page_f) {
//Create a json with all the 1 page of mods we can do a loop to fetch a number of pages
mods = utils::getMods(currentGame.gamebananaID, page);
this->setTitle("menu/mods/mods_list_title"_i18n);
//We create a list
createList();
}

ModsList::ModsList(Game game, const std::string& search, int page) : AppletFrame(true, true), currentGame(game), search(search), page(page) {
ModsList::ModsList(Game game, const std::string& search, int page_f) : AppletFrame(true, true), currentGame(game), search(search), page(page_f) {
//Create a json with all the 1 page of mods we can do a loop to fetch a number of pages
mods = utils::getMods(currentGame.gamebananaID, search, page);
this->setTitle("menu/mods/mods_list_title"_i18n);
Expand All @@ -32,12 +33,9 @@ ModsList::ModsList(Game game, const std::string& search, int page) : AppletFrame
void ModsList::createList(){
list = new brls::List();

if(mods.at("_aRecords").empty()) {
if (search != "")
brls::Application::pushView(new ModsList(this->currentGame, this->search, this->page-1));
else
brls::Application::pushView(new ModsList(this->currentGame, this->page-1));
}
brls::Logger::debug("json : {}", mods.dump(4));



for (auto i : mods.at("_aRecords")) {
//Check if the mod can be downloaded or no
Expand Down Expand Up @@ -103,7 +101,6 @@ void ModsList::createList(){
this->registerAction("", brls::Key::B, [] { brls::Application::pushView(new MainFrame()); return 0;});

this->setFooterText(fmt::format("{} : {}", "menu/mods/page"_i18n, this->page));

}

ModsPage::ModsPage(Mod &mod, Game& game, const std::string& search, const int& page) : AppletFrame(true, true), currentMod(mod), currentGame(game), page(page) {
Expand Down
19 changes: 15 additions & 4 deletions source/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,32 @@ namespace utils {
return resultString;
}

nlohmann::json getMods(const int& gameID, const int& page) {
const std::string api_url = fmt::format("https://gamebanana.com/apiv11/Game/{}/Subfeed?_nPage={}?_nPerpage=50", std::to_string(gameID), std::to_string(page));
nlohmann::json getMods(const int& gameID, int& page) {
std::string api_url = fmt::format("https://gamebanana.com/apiv11/Game/{}/Subfeed?_nPage={}?_nPerpage=50&_csvModelInclusions=Mod", std::to_string(gameID), std::to_string(page));
nlohmann::json mods = net::downloadRequest(api_url);

if(mods.at("_aRecords").empty()) {
api_url = fmt::format("https://gamebanana.com/apiv11/Game/{}/Subfeed?_nPage={}&_nPerpage=50&_csvModelInclusions=Mod", std::to_string(gameID),std::to_string(page-1));
mods = net::downloadRequest(api_url);
page -= 1;
}

return mods;
}

nlohmann::json getMods(const int& gameID, const std::string&search, const int& page) {
nlohmann::json getMods(const int& gameID, const std::string&search, int& page) {
if (search.size() < 3) {
brls::Application::notify("menu/notify/string_to_short"_i18n);
return getMods(gameID, page);
}
std::string search_term = replaceSpacesWithPlus(search);
const std::string api_url = fmt::format("https://gamebanana.com/apiv11/Game/{}/Subfeed?_nPage={}&_nPerpage=50&_sName={}&_csvModelInclusions=Mod", std::to_string(gameID),std::to_string(page), search_term);
std::string api_url = fmt::format("https://gamebanana.com/apiv11/Game/{}/Subfeed?_nPage={}&_nPerpage=50&_sName={}&_csvModelInclusions=Mod", std::to_string(gameID),std::to_string(page), search_term);
nlohmann::json mods = net::downloadRequest(api_url);
if(mods.at("_aRecords").empty()) {
api_url = fmt::format("https://gamebanana.com/apiv11/Game/{}/Subfeed?_nPage={}&_nPerpage=50&_sName={}&_csvModelInclusions=Mod", std::to_string(gameID),std::to_string(page-1), search_term);
mods = net::downloadRequest(api_url);
page -= 1;
}
std::cout<< api_url << std::endl;
std::cout << mods << std::endl;
return mods;
Expand Down

0 comments on commit e7714e9

Please sign in to comment.