1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-27 22:49:25 +02:00

use path instead of different filename

This commit is contained in:
Laserlicht
2024-11-09 13:07:15 +01:00
committed by GitHub
parent 1f7cec3ae3
commit ac31a946e6
2 changed files with 22 additions and 19 deletions

View File

@@ -55,28 +55,28 @@ std::shared_ptr<CDefFile> RenderHandler::getAnimationFile(const AnimationPath &
return result; return result;
} }
std::optional<ResourcePath> RenderHandler::getPath(ResourcePath path) std::optional<ResourcePath> RenderHandler::getPath(ResourcePath path, std::string factor)
{ {
if(CResourceHandler::get()->existsResource(path)) if(CResourceHandler::get()->existsResource(path))
return path; return path;
if(path.getType() == EResType::IMAGE) if(path.getType() == EResType::IMAGE)
{ {
auto p = ImagePath::builtin(path.getName()); auto p = ImagePath::builtin(path.getName());
if(CResourceHandler::get()->existsResource(p.addPrefix("DATA/"))) if(CResourceHandler::get()->existsResource(p.addPrefix("DATA" + factor + "X/")))
return std::optional<ResourcePath>(p.addPrefix("DATA/")); return std::optional<ResourcePath>(p.addPrefix("DATA" + factor + "X/"));
if(CResourceHandler::get()->existsResource(p.addPrefix("SPRITES/"))) if(CResourceHandler::get()->existsResource(p.addPrefix("SPRITES" + factor + "X/")))
return std::optional<ResourcePath>(p.addPrefix("SPRITES/")); return std::optional<ResourcePath>(p.addPrefix("SPRITES" + factor + "X/"));
} }
else else
{ {
auto p = AnimationPath::builtin(path.getName()); auto p = AnimationPath::builtin(path.getName());
auto pJson = p.toType<EResType::JSON>(); auto pJson = p.toType<EResType::JSON>();
if(CResourceHandler::get()->existsResource(p.addPrefix("SPRITES/"))) if(CResourceHandler::get()->existsResource(p.addPrefix("SPRITES" + factor + "X/")))
return std::optional<ResourcePath>(p.addPrefix("SPRITES/")); return std::optional<ResourcePath>(p.addPrefix("SPRITES" + factor + "X/"));
if(CResourceHandler::get()->existsResource(pJson)) if(CResourceHandler::get()->existsResource(pJson))
return std::optional<ResourcePath>(p); return std::optional<ResourcePath>(p);
if(CResourceHandler::get()->existsResource(pJson.addPrefix("SPRITES/"))) if(CResourceHandler::get()->existsResource(pJson.addPrefix("SPRITES" + factor + "X/")))
return std::optional<ResourcePath>(p.addPrefix("SPRITES/")); return std::optional<ResourcePath>(p.addPrefix("SPRITES" + factor + "X/"));
} }
return std::nullopt; return std::nullopt;
@@ -85,19 +85,22 @@ std::optional<ResourcePath> RenderHandler::getPath(ResourcePath path)
std::pair<ResourcePath, int> RenderHandler::getScalePath(ResourcePath p) std::pair<ResourcePath, int> RenderHandler::getScalePath(ResourcePath p)
{ {
auto path = p; auto path = p;
auto name = p.getName();
int scaleFactor = 1; int scaleFactor = 1;
if(getScalingFactor() > 1) if(getScalingFactor() > 1)
{ {
std::vector<int> factorsToCheck = {getScalingFactor(), 4, 3, 2}; std::vector<int> factorsToCheck = {getScalingFactor(), 4, 3, 2};
for(auto factorToCheck : factorsToCheck) 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) if(p.getType() != EResType::IMAGE)
scaledPath = AnimationPath::builtin(name + "$" + std::to_string(factorToCheck)); scaledPath = AnimationPath::builtin(name);
if(getPath(scaledPath)) auto tmpPath = getPath(scaledPath, std::to_string(factorToCheck));
if(tmpPath)
{ {
path = scaledPath; path = *tmpPath;
scaleFactor = factorToCheck; scaleFactor = factorToCheck;
break; break;
} }
@@ -242,12 +245,12 @@ std::shared_ptr<ISharedImage> RenderHandler::loadImageFromFileUncached(const Ima
{ {
auto defFile = getAnimationFile(*locator.defFile); auto defFile = getAnimationFile(*locator.defFile);
int preScaledFactor = locator.preScaledFactor; int preScaledFactor = locator.preScaledFactor;
if(!defFile) // no presscale for this frame if(!defFile) // no prescale for this frame
{ {
auto tmpPath = (*locator.defFile).getName(); auto tmpPath = (*locator.defFile).getName();
boost::algorithm::replace_all(tmpPath, "$2", ""); boost::algorithm::replace_all(tmpPath, "2X/", "/");
boost::algorithm::replace_all(tmpPath, "$3", ""); boost::algorithm::replace_all(tmpPath, "3X/", "/");
boost::algorithm::replace_all(tmpPath, "$4", ""); boost::algorithm::replace_all(tmpPath, "4X/", "/");
preScaledFactor = 1; preScaledFactor = 1;
defFile = getAnimationFile(AnimationPath::builtin(tmpPath)); defFile = getAnimationFile(AnimationPath::builtin(tmpPath));
} }

View File

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