Skip to content

Commit

Permalink
Card images!
Browse files Browse the repository at this point in the history
  • Loading branch information
GXTX committed Jan 11, 2024
1 parent bb4017c commit 77c7c81
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
36 changes: 32 additions & 4 deletions Includes/Printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define PRINTER_H

#include <vector>
#include <random>

#include <SDL2/SDL.h>
#include <SDL_ttf.h>
Expand Down Expand Up @@ -100,19 +101,46 @@ 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)
return;
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<std::string> 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<std::mt19937::result_type> rng(0, static_cast<uint8_t>(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
);
}
Expand Down
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------
Expand All @@ -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
Expand Down

0 comments on commit 77c7c81

Please sign in to comment.