1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 19:13:07 +01:00

Use hash map of images in cli sprite build command instead of reload

This commit is contained in:
mix
2025-12-17 23:28:47 +00:00
parent 70c7a223d2
commit 3e7880f260

View File

@@ -62,6 +62,8 @@ namespace OpenRCT2::CommandLine::Sprite
uint32_t numSuccessful = 0;
std::unordered_map<u8string, Image> images{};
// Note: jsonSprite is deliberately left non-const: json_t behaviour changes when const
for (auto& [jsonKey, jsonSprite] : jsonSprites.items())
{
@@ -84,17 +86,28 @@ namespace OpenRCT2::CommandLine::Sprite
auto imagePath = Path::GetAbsolute(Path::Combine(directoryPath, strPath));
const auto image = SpriteImageLoad(imagePath, meta);
if (image == std::nullopt)
const auto image_iter = images.find(imagePath);
if (image_iter != images.end())
{
fprintf(stderr, "Could not read image file: %s\nCanceling\n", imagePath.c_str());
return -1;
ImageImporter importer;
auto importResult = importer.Import(image_iter->second, meta);
spriteFile.AddImage(importResult);
}
else
{
const auto image = SpriteImageLoad(imagePath, meta);
if (image == std::nullopt)
{
fprintf(stderr, "Could not read image file: %s\nCanceling\n", imagePath.c_str());
return -1;
}
images[imagePath] = image.value();
ImageImporter importer;
auto importResult = importer.Import(image.value(), meta);
ImageImporter importer;
auto importResult = importer.Import(image.value(), meta);
spriteFile.AddImage(importResult);
spriteFile.AddImage(importResult);
}
if (!silent)
fprintf(stdout, "Added: %s\n", imagePath.c_str());