From 2fca87cdbf2da7fcb95bc38e6b09692720a18baf Mon Sep 17 00:00:00 2001 From: Aotrix <9aotrix@protonmail.com> Date: Mon, 23 Feb 2026 22:25:38 +0100 Subject: Added DownloadMethod class --- battleNetApi/src/main.cpp | 69 ++++++++++++++++++++++++++++++++------------ battleNetApi/tests/tests.cpp | 2 +- gameView/main.cpp | 2 +- 3 files changed, 53 insertions(+), 20 deletions(-) diff --git a/battleNetApi/src/main.cpp b/battleNetApi/src/main.cpp index 43245d8..a1c64a3 100644 --- a/battleNetApi/src/main.cpp +++ b/battleNetApi/src/main.cpp @@ -3,30 +3,63 @@ #include #include -int main(int argc, char *argv[]) { - if (argc < 3) { - // Example of parameters: - // ./build/downloadCards tests/resources/credentials.json build/output.json - throw std::invalid_argument("/ "); +class DownloadMethod { + public: + virtual void download() = 0; +}; + +class DefaultDownloadMethod : public DownloadMethod { + public: + void download() { + std::cout << "OMG je suis une méthode de téléchargement !\n"; + // const std::string kContentType{"cards"}; + // const std::string kRegion{"eu"}; + // ApiUrl aApiUrl(kContentType, kRegion); + // aApiUrl.setLocale("fr_FR"); + // aApiUrl.setGameMode("constructed"); + // aApiUrl.setPageSize("100"); + // std::cout << "Downloading cards...\n"; + // aHearthstoneApi.downloadAllCards(aApiUrl, aOutputPath); + // std::cout << "Download done.\n"; + } +}; + +class DownloaderContext { + public: + DownloaderContext() = default; + DownloaderContext(std::unique_ptr iDownloader) : mDownloader(std::move(iDownloader)) {}; + void setDownloader(std::unique_ptr iDownloader) { mDownloader = std::move(iDownloader); } + void download() { + if (mDownloader) { + mDownloader->download(); + } else { + std::cerr << "No download method available in DownloaderContext\n"; + } } - std::string aCredentialsFilePath{argv[1]}; - Token aToken(aCredentialsFilePath); - HearthstoneApi aHearthstoneApi(aToken); - std::string aOutputPath{argv[2]}; + private: + std::unique_ptr mDownloader; +}; + +int main(int argc, char *argv[]) { + // if (argc < 3) { + // // Example of parameters: + // // ./build/downloadCards tests/resources/credentials.json build/output.json + // throw std::invalid_argument("/ + // "); + // } + // std::string aCredentialsFilePath{argv[1]}; + // Token aToken(aCredentialsFilePath); + // HearthstoneApi aHearthstoneApi(aToken); + // std::string aOutputPath{argv[2]}; + + DownloaderContext aDownloaderContext; if (argc < 4) { - const std::string kContentType{"cards"}; - const std::string kRegion{"eu"}; - ApiUrl aApiUrl(kContentType, kRegion); - aApiUrl.setLocale("fr_FR"); - aApiUrl.setGameMode("constructed"); - aApiUrl.setPageSize("100"); - std::cout << "Downloading cards...\n"; - aHearthstoneApi.downloadAllCards(aApiUrl, aOutputPath); - std::cout << "Download done.\n"; + aDownloaderContext.setDownloader(std::make_unique()); } else { // TODO: retrieve config from JSON file } + aDownloaderContext.download(); return 0; } diff --git a/battleNetApi/tests/tests.cpp b/battleNetApi/tests/tests.cpp index d3321d3..cfb22e4 100644 --- a/battleNetApi/tests/tests.cpp +++ b/battleNetApi/tests/tests.cpp @@ -36,7 +36,7 @@ TEST_CASE("Retrieve number of cards", "[countCards]") { REQUIRE(kResponse.size() > 0); REQUIRE(kResponse.contains("pageCount")); std::uint64_t kNumberOfCards{kResponse["pageCount"]}; - REQUIRE(kNumberOfCards == 6033); + REQUIRE(kNumberOfCards == 6048); } TEST_CASE("Retrieve page once", "[retrievePageOnce]") { diff --git a/gameView/main.cpp b/gameView/main.cpp index 6f4e145..5b3a1ae 100644 --- a/gameView/main.cpp +++ b/gameView/main.cpp @@ -31,7 +31,7 @@ void configureMainMenuBar(QMenuBar &iMenuBar) { int main(int argc, char *argv[]) { QApplication aApplication(argc, argv); QWidget aWindow; - aWindow.resize(500, 700); + aWindow.resize(440, 650); // Set Dialog flag for i3 users aWindow.setWindowFlag(Qt::WindowType::Dialog); -- cgit v1.2.3