From 3967c70bf2e85459ff1922ca71163bb7879aad01 Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sat, 30 Nov 2024 15:03:58 +0100 Subject: [PATCH] fix image creation --- client/mapView/MapRenderer.cpp | 12 ++++++------ client/render/AssetGenerator.cpp | 13 ++++++++----- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/client/mapView/MapRenderer.cpp b/client/mapView/MapRenderer.cpp index aa4e4221d..32762304f 100644 --- a/client/mapView/MapRenderer.cpp +++ b/client/mapView/MapRenderer.cpp @@ -135,7 +135,7 @@ MapRendererTerrain::MapRendererTerrain() { logGlobal->debug("Loading map terrains"); for(const auto & terrain : VLC->terrainTypeHandler->objects) - storage.load(terrain->getIndex(), terrain->tilesFilename, EImageBlitMode::OPAQUE); + storage.load(terrain->getIndex(), AnimationPath::builtin(terrain->tilesFilename.getName() + (terrain->paletteAnimation.size() ? "_Shifted": "")), EImageBlitMode::OPAQUE); logGlobal->debug("Done loading map terrains"); } @@ -156,8 +156,8 @@ void MapRendererTerrain::renderTile(IMapRendererContext & context, Canvas & targ return; } -// for( auto const & element : mapTile.getTerrain()->paletteAnimation) -// image->shiftPalette(element.start, element.length, context.terrainImageIndex(element.length)); + for( auto const & element : mapTile.getTerrain()->paletteAnimation) + image->shiftPalette(element.start, element.length, context.terrainImageIndex(element.length)); target.draw(image, Point(0, 0)); } @@ -176,7 +176,7 @@ MapRendererRiver::MapRendererRiver() { logGlobal->debug("Loading map rivers"); for(const auto & river : VLC->riverTypeHandler->objects) - storage.load(river->getIndex(), river->tilesFilename, EImageBlitMode::COLORKEY); + storage.load(river->getIndex(), AnimationPath::builtin(river->tilesFilename.getName() + (river->paletteAnimation.size() ? "_Shifted": "")), EImageBlitMode::COLORKEY); logGlobal->debug("Done loading map rivers"); } @@ -193,8 +193,8 @@ void MapRendererRiver::renderTile(IMapRendererContext & context, Canvas & target const auto & image = storage.find(terrainIndex, rotationIndex, imageIndex); - //for( auto const & element : mapTile.getRiver()->paletteAnimation) - // image->shiftPalette(element.start, element.length, context.terrainImageIndex(element.length)); + for( auto const & element : mapTile.getRiver()->paletteAnimation) + image->shiftPalette(element.start, element.length, context.terrainImageIndex(element.length)); target.draw(image, Point(0, 0)); } diff --git a/client/render/AssetGenerator.cpp b/client/render/AssetGenerator.cpp index 5215887d0..1fa5f83a2 100644 --- a/client/render/AssetGenerator.cpp +++ b/client/render/AssetGenerator.cpp @@ -368,7 +368,7 @@ void AssetGenerator::createPaletteShiftedSprites() 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 + if(CResourceHandler::get()->existsResource(ResourcePath(filenameNew.getName(), EResType::JSON))) // overridden by mod, no generation return; auto anim = GH.renderHandler().loadAnimation(filename, EImageBlitMode::COLORKEY); @@ -409,12 +409,15 @@ void AssetGenerator::createPaletteShiftedSprites() img->shiftPalette(tmp.start, tmp.length, l % tmp.length); } } - img->exportBitmap(*CResourceHandler::get("local")->getResourceName(savePath)); + Canvas canvas = Canvas(Point(32, 32), CanvasScalingPolicy::IGNORE); + canvas.draw(img, Point((32 - img->dimensions().x) / 2, (32 - img->dimensions().y) / 2)); + std::shared_ptr image = GH.renderHandler().createImage(canvas.getInternalSurface()); + image->exportBitmap(*CResourceHandler::get("local")->getResourceName(savePath)); JsonNode node; node.Struct() = { - { "group", JsonNode(std::to_string(l)) }, - { "frame", JsonNode(std::to_string(j)) }, + { "group", JsonNode(l) }, + { "frame", JsonNode(j) }, { "file", JsonNode(spriteName) } }; config["images"].Vector().push_back(node); @@ -425,7 +428,7 @@ void AssetGenerator::createPaletteShiftedSprites() if(!CResourceHandler::get("local")->createResource(filenameNew.getOriginalName() + ".json")) return; - std::fstream file(CResourceHandler::get()->getResourceName(savePath)->c_str(), std::ofstream::out | std::ofstream::trunc); + std::fstream file(CResourceHandler::get("local")->getResourceName(savePath)->c_str(), std::ofstream::out | std::ofstream::trunc); file << config.toString(); } }