| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- /*
- * 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"
- #include "../gui/CGuiHandler.h"
- #include "IScreenHandler.h"
- #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;
- 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;
- return false;
- }
- bool ImageLocator::empty() const
- {
- return !image.has_value() && !defFile.has_value();
- }
- ImageLocator ImageLocator::copyFile() const
- {
- ImageLocator result;
- result.scalingFactor = 1;
- 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 != EImageLayer::ALL)
- result += "-layer" + std::to_string(static_cast<int>(layer));
- return result;
- }
|