MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / exportAll

Function exportAll

src/openrct2/command_line/sprite/SpriteExportAll.cpp:25–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23namespace OpenRCT2::CommandLine::Sprite
24{
25 ExitCode exportAll(const char** argv, int32_t argc)
26 {
27 if (argc < 3)
28 {
29 fprintf(stdout, "usage: sprite exportall <spritefile> <output directory>\n");
30 return ExitCode::fail;
31 }
32
33 const utf8* spriteFilePath = argv[1];
34 const utf8* outputPath = argv[2];
35
36 auto spriteFile = SpriteFile::Open(spriteFilePath);
37 if (!spriteFile.has_value())
38 {
39 fprintf(stderr, "Unable to open input sprite file.\n");
40 return ExitCode::fail;
41 }
42
43 if (!Path::CreateDirectory(outputPath))
44 {
45 fprintf(stderr, "Unable to create directory.\n");
46 return ExitCode::fail;
47 }
48
49 const uint32_t maxIndex = spriteFile->Header.numEntries;
50 const int32_t numbers = static_cast<int32_t>(std::floor(std::log10(maxIndex) + 1));
51
52 std::ostringstream oss; // TODO: Remove when C++20 is enabled and std::format can be used
53 for (uint32_t spriteIndex = 0; spriteIndex < maxIndex; spriteIndex++)
54 {
55 // Status indicator
56 printf("\r%u / %u, %u%%", spriteIndex + 1, maxIndex, ((spriteIndex + 1) * 100) / maxIndex);
57
58 oss << std::setw(numbers) << std::setfill('0') << spriteIndex << ".png";
59
60 const auto& spriteHeader = spriteFile->Entries[spriteIndex];
61 if (!SpriteImageExport(spriteHeader, Path::Combine(outputPath, PopStr(oss))))
62 {
63 fprintf(stderr, "Could not export\n");
64 return ExitCode::fail;
65 }
66 }
67 return ExitCode::ok;
68 }
69} // namespace OpenRCT2::CommandLine::Sprite

Callers 1

HandleSpriteFunction · 0.85

Calls 5

CreateDirectoryFunction · 0.85
SpriteImageExportFunction · 0.85
PopStrFunction · 0.85
OpenFunction · 0.50
CombineFunction · 0.50

Tested by

no test coverage detected