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) diff --git a/src/cmdline_sprite.c b/src/cmdline_sprite.c index e6e1cf14b3..2e5ba292d4 100644 --- a/src/cmdline_sprite.c +++ b/src/cmdline_sprite.c @@ -1,6 +1,8 @@ #include +#include #include "cmdline.h" #include "drawing/drawing.h" +#include "platform/platform.h" #include "util/util.h" #define MODE_DEFAULT 0 @@ -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; @@ -879,4 +943,4 @@ static rct_sprite_file_palette_entry _standardPalette[256] = { // 255 (unused?) { 0, 0, 0, 255 } -}; \ No newline at end of file +};