From 77c7c811a6d9bfcfdd31d8148f3a67ac4e3b45e8 Mon Sep 17 00:00:00 2001 From: wutno Date: Thu, 11 Jan 2024 09:14:26 -0500 Subject: [PATCH] Card images! --- Includes/Printer.h | 36 ++++++++++++++++++++++++++++++++---- readme.md | 6 +++--- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/Includes/Printer.h b/Includes/Printer.h index 1909b71..2aaef01 100644 --- a/Includes/Printer.h +++ b/Includes/Printer.h @@ -23,6 +23,7 @@ #define PRINTER_H #include +#include #include #include @@ -100,7 +101,6 @@ class Printer std::string temp = cardName; temp.append(".png"); - // FIXME: Allow a pool of images to be randomly chosen if (ghc::filesystem::exists(temp)) { m_cardImage = IMG_Load(temp.c_str()); if (m_cardImage != nullptr) @@ -108,11 +108,39 @@ class Printer g_logger->warn("Printer::LoadCardImage: Found card image but IMG_Load couldn't create the surface, generating a transparent surface"); } - // FIXME: Hard coded size + std::string cwd = ghc::filesystem::current_path().string(); +#ifdef _WIN32 + if (cwd.back() != '\\') + cwd.append("\\images\\"); +#else + if (cwd.back() != '/') + cwd.append("/images/"); +#endif + + g_logger->warn("{}", cwd); + std::vector images = {}; + + for (const auto& entry : ghc::filesystem::directory_iterator(cwd)) { + if (entry.path().string().find(".png") != std::string::npos) + images.emplace_back(entry.path().string()); + } + + if (!images.empty()) { + std::random_device dev; + std::mt19937 twist(dev()); + std::uniform_int_distribution rng(0, static_cast(images.size())); + + m_cardImage = IMG_Load(images.at(rng(twist)).c_str()); + if (m_cardImage != nullptr) + return; + g_logger->warn("Printer::LoadCardImage: IMG_Load failed to load the random base card image"); + } + + // Everything else failed, we *need* a surface... So let's generate a transparent one m_cardImage = SDL_CreateRGBSurface( 0, - 640, - 1019, + (m_horizontalCard ? 1019 : 640), + (m_horizontalCard ? 640 : 1019), 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 ); } diff --git a/readme.md b/readme.md index 8d354d1..791a451 100644 --- a/readme.md +++ b/readme.md @@ -5,9 +5,9 @@ YACardEmu (*YetAnother*CardEmu) is a software emulator to emulate a range of mag **Checkout some gameplay videos [here!](https://www.youtube.com/channel/UCle6xQNwROzwYfYMyrnIcBQ)** -Breaking Changes.... +Card images! --------- -We've recently remodeled how cards are stored. If your card ends with `.track_n` then you must convert this to a single file. If your `.track_1` or `.track_2` files are empty (aka all zeros) then do **not** add the zero'ed track to the file. The resulting file should have either 69, 138, or 207 bytes in it. +Card images are now working! Place base images in a folder called `images` in the same folder as `YACardEmu.exe`, and the application will randomly choose one when the game calls to save. You'll see afterwards that a image will be placed in the same folder as your cards with your card name. The UI will also display this when picking a card. Enjoy. Building --------- @@ -16,7 +16,7 @@ Building Ubuntu / Debian / Raspbian ```sh -sudo apt install build-essential cmake pkg-config libserialport-dev +sudo apt install build-essential cmake pkg-config libserialport-dev libsdl2-2.0-0 libsdl2-image-2.0-0 libsdl2-ttf-2.0-0 ``` Windows