From c5b75b347ecaca4f62280e04508d6362cd8fa093 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Thu, 28 Mar 2019 18:53:21 -0400 Subject: Simplify (sort of) Cards API and add FreeCell loading --- dump.c | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) (limited to 'dump.c') diff --git a/dump.c b/dump.c index f9f636f..127d6b1 100644 --- a/dump.c +++ b/dump.c @@ -28,14 +28,16 @@ #include "cards.h" int main(int argc, char *argv[]) { - enum Cards_Flags flags = 0; + bool freecell = false; + enum Cards_Flag flags = 0; bool invert = false; int opt; - while (0 < (opt = getopt(argc, argv, "abik"))) { + while (0 < (opt = getopt(argc, argv, "abfik"))) { switch (opt) { break; case 'a': flags |= Cards_AlphaCorners; break; case 'b': flags |= Cards_BlackBorders; + break; case 'f': freecell = true; break; case 'i': invert = true; break; case 'k': flags |= Cards_ColorKey; break; default: return EX_USAGE; @@ -50,22 +52,31 @@ int main(int argc, char *argv[]) { } if (!rw) errx(EX_NOINPUT, "SDL_RWFromFile: %s", SDL_GetError()); - struct Cards *cards = Cards_Load(rw, flags); - if (!cards) errx(EX_DATAERR, "Cards_Load: %s", SDL_GetError()); + SDL_Surface *surfaces[Cards_CardCount]; + if (freecell) { + int error = Cards_LoadFreeCell( + surfaces, Cards_CardCount, rw, flags + ); + if (error) errx(EX_DATAERR, "Cards_LoadFreeCell: %s", SDL_GetError()); + } else { + int error = Cards_LoadCards(surfaces, Cards_CardCount, rw, flags); + if (error) errx(EX_DATAERR, "Cards_LoadCards: %s", SDL_GetError()); + } SDL_RWclose(rw); - if (invert) { - int error = Cards_Invert(cards); - if (error) errx(EX_DATAERR, "Cards_Invert: %s", SDL_GetError()); - } + for (size_t i = 0; i < Cards_CardCount; ++i) { + if (!surfaces[i]) continue; + + if (invert) { + int error = Cards_InvertSurface(surfaces[i]); + if (error) { + errx(EX_DATAERR, "Cards_InvertSurface: %s", SDL_GetError()); + } + } - for (int i = 0; i < Cards_Count; ++i) { - if (!cards->surfaces[i]) continue; char name[sizeof("00.bmp")]; - snprintf(name, sizeof(name), "%02d.bmp", i); - int error = SDL_SaveBMP(cards->surfaces[i], name); + snprintf(name, sizeof(name), "%02zu.bmp", i); + int error = SDL_SaveBMP(surfaces[i], name); if (error) errx(EX_CANTCREAT, "SDL_SaveBMP: %s", SDL_GetError()); } - - Cards_Free(cards); } -- cgit 1.4.1