ImageLocator.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * ImageLocator.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "ImageLocator.h"
  12. #include "../gui/CGuiHandler.h"
  13. #include "IScreenHandler.h"
  14. #include "../../lib/json/JsonNode.h"
  15. ImageLocator::ImageLocator(const JsonNode & config)
  16. : image(ImagePath::fromJson(config["file"]))
  17. , defFile(AnimationPath::fromJson(config["defFile"]))
  18. , defFrame(config["defFrame"].Integer())
  19. , defGroup(config["defGroup"].Integer())
  20. , verticalFlip(config["verticalFlip"].Bool())
  21. , horizontalFlip(config["horizontalFlip"].Bool())
  22. {
  23. }
  24. ImageLocator::ImageLocator(const ImagePath & path)
  25. : image(path)
  26. {
  27. }
  28. ImageLocator::ImageLocator(const AnimationPath & path, int frame, int group)
  29. : defFile(path)
  30. , defFrame(frame)
  31. , defGroup(group)
  32. {
  33. }
  34. bool ImageLocator::operator<(const ImageLocator & other) const
  35. {
  36. if(image != other.image)
  37. return image < other.image;
  38. if(defFile != other.defFile)
  39. return defFile < other.defFile;
  40. if(defGroup != other.defGroup)
  41. return defGroup < other.defGroup;
  42. if(defFrame != other.defFrame)
  43. return defFrame < other.defFrame;
  44. if(verticalFlip != other.verticalFlip)
  45. return verticalFlip < other.verticalFlip;
  46. if(horizontalFlip != other.horizontalFlip)
  47. return horizontalFlip < other.horizontalFlip;
  48. if(scalingFactor != other.scalingFactor)
  49. return scalingFactor < other.scalingFactor;
  50. if(playerColored != other.playerColored)
  51. return playerColored < other.playerColored;
  52. if(layer != other.layer)
  53. return layer < other.layer;
  54. return false;
  55. }
  56. bool ImageLocator::empty() const
  57. {
  58. return !image.has_value() && !defFile.has_value();
  59. }
  60. ImageLocator ImageLocator::copyFile() const
  61. {
  62. ImageLocator result;
  63. result.scalingFactor = 1;
  64. result.image = image;
  65. result.defFile = defFile;
  66. result.defFrame = defFrame;
  67. result.defGroup = defGroup;
  68. return result;
  69. }
  70. ImageLocator ImageLocator::copyFileTransform() const
  71. {
  72. ImageLocator result = copyFile();
  73. result.horizontalFlip = horizontalFlip;
  74. result.verticalFlip = verticalFlip;
  75. return result;
  76. }
  77. ImageLocator ImageLocator::copyFileTransformScale() const
  78. {
  79. return *this; // full copy
  80. }