mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-29 23:07:48 +02:00
Reworked image container classes for easier support of new features
This commit is contained in:
@@ -15,11 +15,10 @@
|
||||
|
||||
#include "../../lib/json/JsonNode.h"
|
||||
|
||||
ImageLocator::ImageLocator(const JsonNode & config)
|
||||
SharedImageLocator::SharedImageLocator(const JsonNode & config, EImageBlitMode mode)
|
||||
: defFrame(config["defFrame"].Integer())
|
||||
, defGroup(config["defGroup"].Integer())
|
||||
, verticalFlip(config["verticalFlip"].Bool())
|
||||
, horizontalFlip(config["horizontalFlip"].Bool())
|
||||
, layer(mode)
|
||||
{
|
||||
if(!config["file"].isNull())
|
||||
image = ImagePath::fromJson(config["file"]);
|
||||
@@ -28,19 +27,28 @@ ImageLocator::ImageLocator(const JsonNode & config)
|
||||
defFile = AnimationPath::fromJson(config["defFile"]);
|
||||
}
|
||||
|
||||
ImageLocator::ImageLocator(const ImagePath & path)
|
||||
SharedImageLocator::SharedImageLocator(const ImagePath & path, EImageBlitMode mode)
|
||||
: image(path)
|
||||
, layer(mode)
|
||||
{
|
||||
}
|
||||
|
||||
ImageLocator::ImageLocator(const AnimationPath & path, int frame, int group)
|
||||
SharedImageLocator::SharedImageLocator(const AnimationPath & path, int frame, int group, EImageBlitMode mode)
|
||||
: defFile(path)
|
||||
, defFrame(frame)
|
||||
, defGroup(group)
|
||||
, layer(mode)
|
||||
{
|
||||
}
|
||||
|
||||
bool ImageLocator::operator<(const ImageLocator & other) const
|
||||
ImageLocator::ImageLocator(const JsonNode & config, EImageBlitMode mode)
|
||||
: SharedImageLocator(config, mode)
|
||||
, verticalFlip(config["verticalFlip"].Bool())
|
||||
, horizontalFlip(config["horizontalFlip"].Bool())
|
||||
{
|
||||
}
|
||||
|
||||
bool SharedImageLocator::operator < (const SharedImageLocator & other) const
|
||||
{
|
||||
if(image != other.image)
|
||||
return image < other.image;
|
||||
@@ -50,14 +58,6 @@ bool ImageLocator::operator<(const ImageLocator & other) const
|
||||
return defGroup < other.defGroup;
|
||||
if(defFrame != other.defFrame)
|
||||
return defFrame < other.defFrame;
|
||||
if(verticalFlip != other.verticalFlip)
|
||||
return verticalFlip < other.verticalFlip;
|
||||
if(horizontalFlip != other.horizontalFlip)
|
||||
return horizontalFlip < other.horizontalFlip;
|
||||
if(scalingFactor != other.scalingFactor)
|
||||
return scalingFactor < other.scalingFactor;
|
||||
if(playerColored != other.playerColored)
|
||||
return playerColored < other.playerColored;
|
||||
if(layer != other.layer)
|
||||
return layer < other.layer;
|
||||
|
||||
@@ -68,70 +68,3 @@ bool ImageLocator::empty() const
|
||||
{
|
||||
return !image.has_value() && !defFile.has_value();
|
||||
}
|
||||
|
||||
ImageLocator ImageLocator::copyFile() const
|
||||
{
|
||||
ImageLocator result;
|
||||
result.scalingFactor = 1;
|
||||
result.preScaledFactor = preScaledFactor;
|
||||
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
|
||||
}
|
||||
|
||||
std::string ImageLocator::toString() const
|
||||
{
|
||||
std::string result;
|
||||
if (empty())
|
||||
return "invalid";
|
||||
|
||||
if (image)
|
||||
{
|
||||
result += image->getOriginalName();
|
||||
assert(!result.empty());
|
||||
}
|
||||
|
||||
if (defFile)
|
||||
{
|
||||
result += defFile->getOriginalName();
|
||||
assert(!result.empty());
|
||||
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();
|
||||
|
||||
if (layer == EImageBlitMode::ONLY_OVERLAY)
|
||||
result += "-overlay";
|
||||
|
||||
if (layer == EImageBlitMode::ONLY_SHADOW)
|
||||
result += "-shadow";
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user