2024-06-17 11:30:16 +02:00
|
|
|
/*
|
|
|
|
* ImageLocator.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "StdInc.h"
|
|
|
|
#include "ImageLocator.h"
|
|
|
|
|
2024-07-25 12:38:48 +02:00
|
|
|
#include "../gui/CGuiHandler.h"
|
|
|
|
#include "IScreenHandler.h"
|
|
|
|
|
2024-06-17 11:30:16 +02:00
|
|
|
#include "../../lib/json/JsonNode.h"
|
|
|
|
|
|
|
|
|
|
|
|
ImageLocator::ImageLocator(const JsonNode & config)
|
|
|
|
: image(ImagePath::fromJson(config["file"]))
|
|
|
|
, defFile(AnimationPath::fromJson(config["defFile"]))
|
|
|
|
, defFrame(config["defFrame"].Integer())
|
|
|
|
, defGroup(config["defGroup"].Integer())
|
|
|
|
, verticalFlip(config["verticalFlip"].Bool())
|
|
|
|
, horizontalFlip(config["horizontalFlip"].Bool())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ImageLocator::ImageLocator(const ImagePath & path)
|
|
|
|
: image(path)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ImageLocator::ImageLocator(const AnimationPath & path, int frame, int group)
|
|
|
|
: defFile(path)
|
|
|
|
, defFrame(frame)
|
|
|
|
, defGroup(group)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ImageLocator::operator<(const ImageLocator & other) const
|
|
|
|
{
|
|
|
|
if(image != other.image)
|
|
|
|
return image < other.image;
|
|
|
|
if(defFile != other.defFile)
|
|
|
|
return defFile < other.defFile;
|
|
|
|
if(defGroup != other.defGroup)
|
|
|
|
return defGroup < other.defGroup;
|
|
|
|
if(defFrame != other.defFrame)
|
|
|
|
return defFrame < other.defFrame;
|
|
|
|
if(verticalFlip != other.verticalFlip)
|
|
|
|
return verticalFlip < other.verticalFlip;
|
2024-07-25 12:38:48 +02:00
|
|
|
if(horizontalFlip != other.horizontalFlip)
|
|
|
|
return horizontalFlip < other.horizontalFlip;
|
|
|
|
if(scalingFactor != other.scalingFactor)
|
|
|
|
return scalingFactor < other.scalingFactor;
|
|
|
|
if(playerColored != other.playerColored)
|
|
|
|
return playerColored < other.playerColored;
|
2024-08-27 21:44:11 +02:00
|
|
|
if(layer != other.layer)
|
|
|
|
return layer < other.layer;
|
2024-07-25 12:38:48 +02:00
|
|
|
|
|
|
|
return false;
|
2024-06-17 11:30:16 +02:00
|
|
|
}
|
2024-07-16 21:51:00 +02:00
|
|
|
|
|
|
|
bool ImageLocator::empty() const
|
|
|
|
{
|
|
|
|
return !image.has_value() && !defFile.has_value();
|
|
|
|
}
|
2024-07-25 12:38:48 +02:00
|
|
|
|
|
|
|
ImageLocator ImageLocator::copyFile() const
|
|
|
|
{
|
|
|
|
ImageLocator result;
|
2024-09-12 16:26:05 +02:00
|
|
|
result.scalingFactor = 1;
|
2024-11-03 14:38:15 +02:00
|
|
|
result.preScaledFactor = preScaledFactor;
|
2024-07-25 12:38:48 +02:00
|
|
|
result.image = image;
|
|
|
|
result.defFile = defFile;
|
|
|
|
result.defFrame = defFrame;
|
|
|
|
result.defGroup = defGroup;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImageLocator ImageLocator::copyFileTransform() const
|
|
|
|
{
|
|
|
|
ImageLocator result = copyFile();
|
|
|
|
result.horizontalFlip = horizontalFlip;
|
|
|
|
result.verticalFlip = verticalFlip;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImageLocator ImageLocator::copyFileTransformScale() const
|
|
|
|
{
|
|
|
|
return *this; // full copy
|
|
|
|
}
|
2024-09-12 22:26:40 +02:00
|
|
|
|
|
|
|
std::string ImageLocator::toString() const
|
|
|
|
{
|
|
|
|
std::string result;
|
|
|
|
if (empty())
|
|
|
|
return "invalid";
|
|
|
|
|
|
|
|
if (image)
|
2024-09-13 14:26:31 +02:00
|
|
|
{
|
2024-09-12 22:26:40 +02:00
|
|
|
result += image->getOriginalName();
|
2024-09-13 14:26:31 +02:00
|
|
|
assert(!result.empty());
|
|
|
|
}
|
2024-09-12 22:26:40 +02:00
|
|
|
|
|
|
|
if (defFile)
|
|
|
|
{
|
|
|
|
result += defFile->getOriginalName();
|
2024-09-13 14:26:31 +02:00
|
|
|
assert(!result.empty());
|
2024-09-12 22:26:40 +02:00
|
|
|
result += "-" + std::to_string(defGroup);
|
|
|
|
result += "-" + std::to_string(defFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (verticalFlip)
|
|
|
|
result += "-vflip";
|
|
|
|
|
|
|
|
if (horizontalFlip)
|
|
|
|
result += "-hflip";
|
|
|
|
|
|
|
|
if (scalingFactor > 1)
|
|
|
|
result += "-scale" + std::to_string(scalingFactor);
|
|
|
|
|
|
|
|
if (playerColored.isValidPlayer())
|
|
|
|
result += "-player" + playerColored.toString();
|
|
|
|
|
2024-11-17 19:54:55 +02:00
|
|
|
if (layer == EImageBlitMode::ONLY_OVERLAY)
|
|
|
|
result += "-overlay";
|
|
|
|
|
|
|
|
if (layer == EImageBlitMode::ONLY_SHADOW)
|
|
|
|
result += "-shadow";
|
|
|
|
|
2024-09-12 22:26:40 +02:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|