diff --git a/client/renderSDL/RenderHandler.cpp b/client/renderSDL/RenderHandler.cpp index efc2c89e0..f67264745 100644 --- a/client/renderSDL/RenderHandler.cpp +++ b/client/renderSDL/RenderHandler.cpp @@ -55,28 +55,28 @@ std::shared_ptr RenderHandler::getAnimationFile(const AnimationPath & return result; } -std::optional RenderHandler::getPath(ResourcePath path) +std::optional RenderHandler::getPath(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/"))) - return std::optional(p.addPrefix("DATA/")); - if(CResourceHandler::get()->existsResource(p.addPrefix("SPRITES/"))) - return std::optional(p.addPrefix("SPRITES/")); + if(CResourceHandler::get()->existsResource(p.addPrefix("DATA" + factor + "X/"))) + return std::optional(p.addPrefix("DATA" + factor + "X/")); + if(CResourceHandler::get()->existsResource(p.addPrefix("SPRITES" + factor + "X/"))) + return std::optional(p.addPrefix("SPRITES" + factor + "X/")); } else { auto p = AnimationPath::builtin(path.getName()); auto pJson = p.toType(); - if(CResourceHandler::get()->existsResource(p.addPrefix("SPRITES/"))) - return std::optional(p.addPrefix("SPRITES/")); + if(CResourceHandler::get()->existsResource(p.addPrefix("SPRITES" + factor + "X/"))) + return std::optional(p.addPrefix("SPRITES" + factor + "X/")); if(CResourceHandler::get()->existsResource(pJson)) return std::optional(p); - if(CResourceHandler::get()->existsResource(pJson.addPrefix("SPRITES/"))) - return std::optional(p.addPrefix("SPRITES/")); + if(CResourceHandler::get()->existsResource(pJson.addPrefix("SPRITES" + factor + "X/"))) + return std::optional(p.addPrefix("SPRITES" + factor + "X/")); } return std::nullopt; @@ -85,19 +85,22 @@ std::optional RenderHandler::getPath(ResourcePath path) std::pair RenderHandler::getScalePath(ResourcePath p) { auto path = p; - auto name = p.getName(); int scaleFactor = 1; if(getScalingFactor() > 1) { std::vector factorsToCheck = {getScalingFactor(), 4, 3, 2}; for(auto factorToCheck : factorsToCheck) { - ResourcePath scaledPath = ImagePath::builtin(name + "$" + std::to_string(factorToCheck)); + std::string name = boost::algorithm::to_upper_copy(p.getName()); + boost::replace_all(name, "SPRITES/", std::string("SPRITES") + std::to_string(factorToCheck) + std::string("X/")); + boost::replace_all(name, "DATA/", std::string("DATA") + std::to_string(factorToCheck) + std::string("X/")); + ResourcePath scaledPath = ImagePath::builtin(name); if(p.getType() != EResType::IMAGE) - scaledPath = AnimationPath::builtin(name + "$" + std::to_string(factorToCheck)); - if(getPath(scaledPath)) + scaledPath = AnimationPath::builtin(name); + auto tmpPath = getPath(scaledPath, std::to_string(factorToCheck)); + if(tmpPath) { - path = scaledPath; + path = *tmpPath; scaleFactor = factorToCheck; break; } @@ -242,12 +245,12 @@ std::shared_ptr RenderHandler::loadImageFromFileUncached(const Ima { auto defFile = getAnimationFile(*locator.defFile); int preScaledFactor = locator.preScaledFactor; - if(!defFile) // no presscale for this frame + if(!defFile) // no prescale 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", ""); + boost::algorithm::replace_all(tmpPath, "2X/", "/"); + boost::algorithm::replace_all(tmpPath, "3X/", "/"); + boost::algorithm::replace_all(tmpPath, "4X/", "/"); preScaledFactor = 1; defFile = getAnimationFile(AnimationPath::builtin(tmpPath)); } diff --git a/client/renderSDL/RenderHandler.h b/client/renderSDL/RenderHandler.h index e30ccbf4d..59f70561b 100644 --- a/client/renderSDL/RenderHandler.h +++ b/client/renderSDL/RenderHandler.h @@ -29,7 +29,7 @@ class RenderHandler : public IRenderHandler std::map> fonts; std::shared_ptr getAnimationFile(const AnimationPath & path); - std::optional getPath(ResourcePath path); + std::optional getPath(ResourcePath path, std::string factor); std::pair getScalePath(ResourcePath p); AnimationLayoutMap & getAnimationLayout(const AnimationPath & path); void initFromJson(AnimationLayoutMap & layout, const JsonNode & config);