about summary refs log tree commit diff
path: root/dump.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-03-28 18:53:21 -0400
committerJune McEnroe <june@causal.agency>2019-03-28 18:53:21 -0400
commitc5b75b347ecaca4f62280e04508d6362cd8fa093 (patch)
tree761dcf00b6c94120c9daa139e177cc12df55d7f6 /dump.c
parentRefactor EXE/DLL loading to be more general (diff)
downloadcards-c5b75b347ecaca4f62280e04508d6362cd8fa093.tar.gz
cards-c5b75b347ecaca4f62280e04508d6362cd8fa093.zip
Simplify (sort of) Cards API and add FreeCell loading
Diffstat (limited to 'dump.c')
-rw-r--r--dump.c39
1 files changed, 25 insertions, 14 deletions
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);
 }