ImageLocator.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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(layerShadow != other.layerShadow)
  53. return layerShadow < other.layerShadow;
  54. if(layerBody != other.layerBody)
  55. return layerBody < other.layerBody;
  56. if (layerOverlay != other.layerOverlay)
  57. return layerOverlay < other.layerOverlay;
  58. return false;
  59. }
  60. bool ImageLocator::empty() const
  61. {
  62. return !image.has_value() && !defFile.has_value();
  63. }
  64. ImageLocator ImageLocator::copyFile() const
  65. {
  66. ImageLocator result;
  67. result.image = image;
  68. result.defFile = defFile;
  69. result.defFrame = defFrame;
  70. result.defGroup = defGroup;
  71. return result;
  72. }
  73. ImageLocator ImageLocator::copyFileTransform() const
  74. {
  75. ImageLocator result = copyFile();
  76. result.horizontalFlip = horizontalFlip;
  77. result.verticalFlip = verticalFlip;
  78. return result;
  79. }
  80. ImageLocator ImageLocator::copyFileTransformScale() const
  81. {
  82. return *this; // full copy
  83. }