From df25e7a15a841e9e6a19f03263325f335d114106 Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 2 Jun 2015 12:50:16 +0200 Subject: [PATCH 1/3] Add command 'exportall' to sprite tool --- src/cmdline_sprite.c | 68 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 2 deletions(-) diff --git a/src/cmdline_sprite.c b/src/cmdline_sprite.c index e6e1cf14b3..d7def95acf 100644 --- a/src/cmdline_sprite.c +++ b/src/cmdline_sprite.c @@ -2,6 +2,8 @@ #include "cmdline.h" #include "drawing/drawing.h" #include "util/util.h" +#include +#include "platform\platform.h" #define MODE_DEFAULT 0 #define MODE_CLOSEST 1 @@ -457,12 +459,75 @@ int cmdline_for_sprite(const char **argv, int argc) } if (!sprite_file_export(spriteIndex, outputPath)) { + fprintf(stderr, "Could not export\n"); sprite_file_close(); return -1; } sprite_file_close(); return 1; + } else if (_strcmpi(argv[0], "exportall") == 0) { + if (argc < 3) { + fprintf(stderr, "usage: sprite exportall \n"); + return -1; + } + + const char *spriteFilePath = argv[1]; + char outputPath[_MAX_PATH]; + + if (!sprite_file_open(spriteFilePath)) { + fprintf(stderr, "Unable to open input sprite file.\n"); + return -1; + } + + if (!platform_ensure_directory_exists(argv[2])){ + fprintf(stderr, "Unable to create directory.\n"); + return -1; + } + + + int maxIndex = (int)spriteFileHeader.num_entries; + int numbers = (int)floor(log(maxIndex)); + + strncpy(outputPath, argv[2], _MAX_PATH); + int pathLen = strlen(outputPath); + + if (pathLen >= _MAX_PATH - numbers - 5){ + fprintf(stderr, "Path too long.\n"); + return -1; + } + + for (int x = 0; x < numbers; x++){ + outputPath[pathLen + x] = '0'; + } + strncpy(outputPath + pathLen + numbers, ".png", _MAX_PATH); + + for (int spriteIndex = 0; spriteIndex < maxIndex; spriteIndex++){ + + if (spriteIndex % 100 == 99){ + // Status indicator + printf("\r%d / %d, %d%%", spriteIndex, maxIndex, spriteIndex / maxIndex); + } + + // Add to the index at the end of the file name + char *counter = outputPath + pathLen + numbers - 1; + (*counter)++; + while (*counter > '9'){ + *counter = '0'; + counter--; + (*counter)++; + } + + if (!sprite_file_export(spriteIndex, outputPath)) { + fprintf(stderr, "Could not export\n"); + sprite_file_close(); + return -1; + } + } + + sprite_file_close(); + return 1; + } else if (_strcmpi(argv[0], "create") == 0) { if (argc < 2) { fprintf(stderr, "usage: sprite create \n"); @@ -514,8 +579,7 @@ int cmdline_for_sprite(const char **argv, int argc) return -1; return 1; - } - else if (_strcmpi(argv[0], "build") == 0) { + } else if (_strcmpi(argv[0], "build") == 0) { if (argc < 3) { fprintf(stderr, "usage: sprite build [silent]\n"); return -1; From 5b8919480bfda987a703cfba64267248a24b6e72 Mon Sep 17 00:00:00 2001 From: Thomas den Hollander Date: Tue, 2 Jun 2015 12:54:37 +0200 Subject: [PATCH 2/3] Add name to contributors --- contributors.md | 1 + 1 file changed, 1 insertion(+) diff --git a/contributors.md b/contributors.md index 32588515ba..7ef94f24ca 100644 --- a/contributors.md +++ b/contributors.md @@ -40,6 +40,7 @@ Includes all git commit authors. Aliases are GitHub user names. * (KingHual) - Housecleaning * Alexander Overvoorde (Overv) - Misc. * (eezstreet) - Misc. +* Thomas den Hollander (ThomasdenH) - Misc. ## Bug fixes * (halfbro) From 2f6bff4def29301e5f88f6bb2c5ef883dfa5b549 Mon Sep 17 00:00:00 2001 From: Thomas den Hollander Date: Tue, 2 Jun 2015 13:37:18 +0200 Subject: [PATCH 3/3] #include fix --- src/cmdline_sprite.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cmdline_sprite.c b/src/cmdline_sprite.c index d7def95acf..2e5ba292d4 100644 --- a/src/cmdline_sprite.c +++ b/src/cmdline_sprite.c @@ -1,9 +1,9 @@ #include +#include #include "cmdline.h" #include "drawing/drawing.h" +#include "platform/platform.h" #include "util/util.h" -#include -#include "platform\platform.h" #define MODE_DEFAULT 0 #define MODE_CLOSEST 1 @@ -943,4 +943,4 @@ static rct_sprite_file_palette_entry _standardPalette[256] = { // 255 (unused?) { 0, 0, 0, 255 } -}; \ No newline at end of file +};