1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-14 10:12:59 +02:00
This commit is contained in:
Laserlicht 2024-11-05 23:12:02 +01:00 committed by GitHub
parent 52aa4aeb82
commit 7c3afde7ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -148,7 +148,9 @@ void RenderHandler::initFromJson(AnimationLayoutMap & source, const JsonNode & c
RenderHandler::AnimationLayoutMap & RenderHandler::getAnimationLayout(const AnimationPath & path)
{
AnimationPath actualPath = boost::starts_with(path.getName(), "SPRITES") ? path : path.addPrefix("SPRITES/");
auto tmp = getScalePath(path);
auto animPath = AnimationPath::builtin(tmp.first.getName());
AnimationPath actualPath = boost::starts_with(animPath.getName(), "SPRITES") ? animPath : animPath.addPrefix("SPRITES/");
auto it = animationLayouts.find(actualPath);
@ -175,11 +177,15 @@ RenderHandler::AnimationLayoutMap & RenderHandler::getAnimationLayout(const Anim
std::unique_ptr<ui8[]> textData(new ui8[stream->getSize()]);
stream->read(textData.get(), stream->getSize());
const JsonNode config(reinterpret_cast<const std::byte*>(textData.get()), stream->getSize(), path.getOriginalName());
const JsonNode config(reinterpret_cast<const std::byte*>(textData.get()), stream->getSize(), animPath.getOriginalName());
initFromJson(result, config);
}
for(auto & g : result)
for(auto & i : g.second)
i.preScaledFactor = tmp.second;
animationLayouts[actualPath] = result;
return animationLayouts[actualPath];
}
@ -235,7 +241,17 @@ std::shared_ptr<ISharedImage> RenderHandler::loadImageFromFileUncached(const Ima
if (locator.defFile)
{
auto defFile = getAnimationFile(*locator.defFile);
return std::make_shared<SDLImageShared>(defFile.get(), locator.defFrame, locator.defGroup, locator.preScaledFactor);
int preScaledFactor = locator.preScaledFactor;
if(!defFile) // no presscale for this frame
{
auto tmpPath = (*locator.defFile).getName();
boost::algorithm::replace_all(tmpPath, "$2", "");
boost::algorithm::replace_all(tmpPath, "$3", "");
boost::algorithm::replace_all(tmpPath, "$4", "");
preScaledFactor = 1;
defFile = getAnimationFile(AnimationPath::builtin(tmpPath));
}
return std::make_shared<SDLImageShared>(defFile.get(), locator.defFrame, locator.defGroup, preScaledFactor);
}
throw std::runtime_error("Invalid image locator received!");
@ -369,14 +385,7 @@ std::shared_ptr<IImage> RenderHandler::createImage(SDL_Surface * source)
std::shared_ptr<CAnimation> RenderHandler::loadAnimation(const AnimationPath & path, EImageBlitMode mode)
{
auto tmp = getScalePath(path);
auto animPath = AnimationPath::builtin(tmp.first.getName());
auto layout = getAnimationLayout(animPath);
for(auto & g : layout)
for(auto & i : g.second)
i.preScaledFactor = tmp.second;
return std::make_shared<CAnimation>(animPath, layout, mode);
return std::make_shared<CAnimation>(path, getAnimationLayout(path), mode);
}
void RenderHandler::addImageListEntries(const EntityService * service)