Add command 'exportall' to sprite tool

This commit is contained in:
Thomas 2015-06-02 12:50:16 +02:00
parent bf39fc36b1
commit df25e7a15a
1 changed files with 66 additions and 2 deletions

View File

@ -2,6 +2,8 @@
#include "cmdline.h"
#include "drawing/drawing.h"
#include "util/util.h"
#include <math.h>
#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 <spritefile> <output directory>\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 <spritefile>\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 <spritefile> <resourcedir> [silent]\n");
return -1;