mirror of https://github.com/OpenRCT2/OpenRCT2.git
Merge pull request #1197 from ThomasdenH/develop
Sprite tool now can export all sprites in a file
This commit is contained in:
commit
9144080ef7
|
@ -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)
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <lodepng/lodepng.h>
|
||||
#include <math.h>
|
||||
#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 <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;
|
||||
|
@ -879,4 +943,4 @@ static rct_sprite_file_palette_entry _standardPalette[256] = {
|
|||
|
||||
// 255 (unused?)
|
||||
{ 0, 0, 0, 255 }
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue