From 4c7e3644bb0d19bb7166e32966b529cda95732f9 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sat, 30 Nov 2024 03:45:15 +0100 Subject: [PATCH] gen sprites --- client/render/AssetGenerator.cpp | 76 ++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/client/render/AssetGenerator.cpp b/client/render/AssetGenerator.cpp index 5aeb5f734..149cc6728 100644 --- a/client/render/AssetGenerator.cpp +++ b/client/render/AssetGenerator.cpp @@ -16,12 +16,16 @@ #include "../render/Canvas.h" #include "../render/ColorFilter.h" #include "../render/IRenderHandler.h" +#include "../render/CAnimation.h" #include "../lib/filesystem/Filesystem.h" #include "../lib/GameSettings.h" #include "../lib/IGameSettings.h" #include "../lib/json/JsonNode.h" #include "../lib/VCMI_Lib.h" +#include "../lib/RiverHandler.h" +#include "../lib/RoadHandler.h" +#include "../lib/TerrainHandler.h" void AssetGenerator::generateAll() { @@ -32,6 +36,7 @@ void AssetGenerator::generateAll() createCombatUnitNumberWindow(); createCampaignBackground(); createChroniclesCampaignImages(); + createPaletteShiftedSprites(); } void AssetGenerator::createAdventureOptionsCleanBackground() @@ -326,3 +331,74 @@ void AssetGenerator::createChroniclesCampaignImages() image->exportBitmap(*CResourceHandler::get("local")->getResourceName(savePath)); } } + +void AssetGenerator::createPaletteShiftedSprites() +{ + std::vector tiles; + std::vector>> paletteAnimations; + VLC->terrainTypeHandler->forEach([&](const TerrainType *entity, bool &stop){ + if(entity->paletteAnimation.size()) + { + tiles.push_back(entity->tilesFilename.getName()); + std::vector> tmpAnim; + for(auto & animEntity : entity->paletteAnimation) + tmpAnim.push_back(animEntity); + paletteAnimations.push_back(tmpAnim); + } + }); + VLC->riverTypeHandler->forEach([&](const RiverType *entity, bool &stop){ + if(entity->paletteAnimation.size()) + { + tiles.push_back(entity->tilesFilename.getName()); + std::vector> tmpAnim; + for(auto & animEntity : entity->paletteAnimation) + tmpAnim.push_back(animEntity); + paletteAnimations.push_back(tmpAnim); + } + }); + + for(int i = 0; i < tiles.size(); i++) + { + auto sprite = tiles[i]; + auto filename = AnimationPath::builtin(sprite).addPrefix("SPRITES/"); + auto filenameNew = AnimationPath::builtin(sprite + "_Shifted").addPrefix("SPRITES/"); + + if(CResourceHandler::get()->existsResource(ResourcePath(filenameNew))) // overridden by mod, no generation + return; + + auto anim = GH.renderHandler().loadAnimation(filename, EImageBlitMode::COLORKEY); + for(int j = 0; j < anim->size(); j++) + { + int counter = 0; + for(int k = 0; k < paletteAnimations[i].size(); k++) + { + auto element = paletteAnimations[i][k]; + int length = std::holds_alternative(element) ? std::get(element).length : std::get(element).length; + for(int l = 0; l < length; l++) + { + std::string filenameNew = "sprites/" + sprite + "_Shifted" + "/" + sprite + boost::str(boost::format("%02d") % j) + "_" + std::to_string(counter) + ".png"; + ResourcePath savePath(filenameNew, EResType::IMAGE); + + if(!CResourceHandler::get("local")->createResource(filenameNew)) + return; + + auto img = anim->getImage(j); + if(std::holds_alternative(element)) + { + auto tmp = std::get(element); + img->shiftPalette(tmp.start, tmp.length, l); + } + else + { + auto tmp = std::get(element); + img->shiftPalette(tmp.start, tmp.length, l); + } + + img->exportBitmap(*CResourceHandler::get("local")->getResourceName(savePath)); + + counter++; + } + } + } + } +}