1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-14 10:12:59 +02:00

cleanup logic

This commit is contained in:
Laserlicht 2024-11-09 14:02:09 +01:00
parent ac31a946e6
commit 35e198078b
2 changed files with 5 additions and 7 deletions

View File

@ -55,17 +55,15 @@ std::shared_ptr<CDefFile> RenderHandler::getAnimationFile(const AnimationPath &
return result;
}
std::optional<ResourcePath> RenderHandler::getPath(ResourcePath path, std::string factor)
std::optional<ResourcePath> RenderHandler::getPathForScaleFactor(ResourcePath path, std::string factor)
{
if(CResourceHandler::get()->existsResource(path))
return path;
if(path.getType() == EResType::IMAGE)
{
auto p = ImagePath::builtin(path.getName());
if(CResourceHandler::get()->existsResource(p.addPrefix("DATA" + factor + "X/")))
return std::optional<ResourcePath>(p.addPrefix("DATA" + factor + "X/"));
if(CResourceHandler::get()->existsResource(p.addPrefix("SPRITES" + factor + "X/")))
return std::optional<ResourcePath>(p.addPrefix("SPRITES" + factor + "X/"));
if(CResourceHandler::get()->existsResource(p.addPrefix("DATA" + factor + "X/")))
return std::optional<ResourcePath>(p.addPrefix("DATA" + factor + "X/"));
}
else
{
@ -97,7 +95,7 @@ std::pair<ResourcePath, int> RenderHandler::getScalePath(ResourcePath p)
ResourcePath scaledPath = ImagePath::builtin(name);
if(p.getType() != EResType::IMAGE)
scaledPath = AnimationPath::builtin(name);
auto tmpPath = getPath(scaledPath, std::to_string(factorToCheck));
auto tmpPath = getPathForScaleFactor(scaledPath, std::to_string(factorToCheck));
if(tmpPath)
{
path = *tmpPath;

View File

@ -29,7 +29,7 @@ class RenderHandler : public IRenderHandler
std::map<EFonts, std::shared_ptr<const IFont>> fonts;
std::shared_ptr<CDefFile> getAnimationFile(const AnimationPath & path);
std::optional<ResourcePath> getPath(ResourcePath path, std::string factor);
std::optional<ResourcePath> getPathForScaleFactor(ResourcePath path, std::string factor);
std::pair<ResourcePath, int> getScalePath(ResourcePath p);
AnimationLayoutMap & getAnimationLayout(const AnimationPath & path);
void initFromJson(AnimationLayoutMap & layout, const JsonNode & config);