forked from rosebudai/OpenRCT2-Web
Allow importing palettes in sprite build
This commit is contained in:
3 files changed
+47
-28
No files matched your search
@@ -64,6 +64,8 @@ namespace OpenRCT2::CommandLine::Sprite
|
||||
|
||||
std::unordered_map<u8string, Image> images{};
|
||||
|
||||
ImageImporter importer;
|
||||
|
||||
// Note: jsonSprite is deliberately left non-const: json_t behaviour changes when const
|
||||
for (auto& [jsonKey, jsonSprite] : jsonSprites.items())
|
||||
{
|
||||
@@ -73,45 +75,55 @@ namespace OpenRCT2::CommandLine::Sprite
|
||||
return -1;
|
||||
}
|
||||
|
||||
json_t path = jsonSprite["path"];
|
||||
if (!path.is_string())
|
||||
json_t colours = jsonSprite["colours"];
|
||||
if (colours.is_array())
|
||||
{
|
||||
fprintf(stderr, "Error: no path provided for sprite %s\n", jsonKey.c_str());
|
||||
return -1;
|
||||
}
|
||||
std::string strPath = Json::GetString(path);
|
||||
auto importResult = importer.importJSONPalette(jsonSprite);
|
||||
spriteFile.addPalette(importResult);
|
||||
|
||||
auto meta = createImageImportMetaFromJson(jsonSprite);
|
||||
meta.importMode = spriteMode;
|
||||
|
||||
auto imagePath = Path::GetAbsolute(Path::Combine(directoryPath, strPath));
|
||||
|
||||
const auto image_iter = images.find(imagePath);
|
||||
if (image_iter != images.end())
|
||||
{
|
||||
ImageImporter importer;
|
||||
auto importResult = importer.Import(image_iter->second, meta);
|
||||
spriteFile.AddImage(importResult);
|
||||
if (!silent)
|
||||
fprintf(stdout, "Added palette\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
const auto image = SpriteImageLoad(imagePath, meta);
|
||||
if (image == std::nullopt)
|
||||
json_t path = jsonSprite["path"];
|
||||
if (!path.is_string())
|
||||
{
|
||||
fprintf(stderr, "Could not read image file: %s\nCanceling\n", imagePath.c_str());
|
||||
fprintf(stderr, "Error: no path provided for sprite %s\n", jsonKey.c_str());
|
||||
return -1;
|
||||
}
|
||||
images[imagePath] = image.value();
|
||||
std::string strPath = Json::GetString(path);
|
||||
|
||||
ImageImporter importer;
|
||||
auto importResult = importer.Import(image.value(), meta);
|
||||
auto meta = createImageImportMetaFromJson(jsonSprite);
|
||||
meta.importMode = spriteMode;
|
||||
|
||||
spriteFile.AddImage(importResult);
|
||||
auto imagePath = Path::GetAbsolute(Path::Combine(directoryPath, strPath));
|
||||
|
||||
const auto image_iter = images.find(imagePath);
|
||||
if (image_iter != images.end())
|
||||
{
|
||||
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();
|
||||
|
||||
auto importResult = importer.Import(image.value(), meta);
|
||||
|
||||
spriteFile.AddImage(importResult);
|
||||
}
|
||||
|
||||
if (!silent)
|
||||
fprintf(stdout, "Added: %s\n", imagePath.c_str());
|
||||
}
|
||||
|
||||
if (!silent)
|
||||
fprintf(stdout, "Added: %s\n", imagePath.c_str());
|
||||
|
||||
numSuccessful++;
|
||||
}
|
||||
|
||||
|
||||
@@ -92,6 +92,11 @@ namespace OpenRCT2::CommandLine::Sprite
|
||||
}
|
||||
}
|
||||
|
||||
void SpriteFile::addPalette(Drawing::PaletteImportResult& palette)
|
||||
{
|
||||
AddImage(*reinterpret_cast<Drawing::ImageImportResult*>(&palette));
|
||||
}
|
||||
|
||||
bool SpriteFile::Save(const utf8* path)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
namespace OpenRCT2::Drawing
|
||||
{
|
||||
struct ImageImportResult;
|
||||
}
|
||||
struct PaletteImportResult;
|
||||
} // namespace OpenRCT2::Drawing
|
||||
|
||||
namespace OpenRCT2::CommandLine::Sprite
|
||||
{
|
||||
@@ -28,6 +29,7 @@ namespace OpenRCT2::CommandLine::Sprite
|
||||
std::vector<G1Element> Entries;
|
||||
std::vector<uint8_t> Data;
|
||||
void AddImage(Drawing::ImageImportResult& image);
|
||||
void addPalette(Drawing::PaletteImportResult& image);
|
||||
bool Save(const utf8* path);
|
||||
static std::optional<SpriteFile> Open(const utf8* path);
|
||||
|
||||
|
||||
Reference in new issue
Block a user