mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-14 10:12:59 +02:00
use path instead of different filename
This commit is contained in:
parent
1f7cec3ae3
commit
ac31a946e6
@ -55,28 +55,28 @@ std::shared_ptr<CDefFile> RenderHandler::getAnimationFile(const AnimationPath &
|
||||
return result;
|
||||
}
|
||||
|
||||
std::optional<ResourcePath> RenderHandler::getPath(ResourcePath path)
|
||||
std::optional<ResourcePath> 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<ResourcePath>(p.addPrefix("DATA/"));
|
||||
if(CResourceHandler::get()->existsResource(p.addPrefix("SPRITES/")))
|
||||
return std::optional<ResourcePath>(p.addPrefix("SPRITES/"));
|
||||
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/"));
|
||||
}
|
||||
else
|
||||
{
|
||||
auto p = AnimationPath::builtin(path.getName());
|
||||
auto pJson = p.toType<EResType::JSON>();
|
||||
if(CResourceHandler::get()->existsResource(p.addPrefix("SPRITES/")))
|
||||
return std::optional<ResourcePath>(p.addPrefix("SPRITES/"));
|
||||
if(CResourceHandler::get()->existsResource(p.addPrefix("SPRITES" + factor + "X/")))
|
||||
return std::optional<ResourcePath>(p.addPrefix("SPRITES" + factor + "X/"));
|
||||
if(CResourceHandler::get()->existsResource(pJson))
|
||||
return std::optional<ResourcePath>(p);
|
||||
if(CResourceHandler::get()->existsResource(pJson.addPrefix("SPRITES/")))
|
||||
return std::optional<ResourcePath>(p.addPrefix("SPRITES/"));
|
||||
if(CResourceHandler::get()->existsResource(pJson.addPrefix("SPRITES" + factor + "X/")))
|
||||
return std::optional<ResourcePath>(p.addPrefix("SPRITES" + factor + "X/"));
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
@ -85,19 +85,22 @@ std::optional<ResourcePath> RenderHandler::getPath(ResourcePath path)
|
||||
std::pair<ResourcePath, int> RenderHandler::getScalePath(ResourcePath p)
|
||||
{
|
||||
auto path = p;
|
||||
auto name = p.getName();
|
||||
int scaleFactor = 1;
|
||||
if(getScalingFactor() > 1)
|
||||
{
|
||||
std::vector<int> 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<ISharedImage> 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));
|
||||
}
|
||||
|
@ -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::optional<ResourcePath> getPath(ResourcePath path, std::string factor);
|
||||
std::pair<ResourcePath, int> getScalePath(ResourcePath p);
|
||||
AnimationLayoutMap & getAnimationLayout(const AnimationPath & path);
|
||||
void initFromJson(AnimationLayoutMap & layout, const JsonNode & config);
|
||||
|
Loading…
Reference in New Issue
Block a user