CAnimation.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * CAnimation.h, 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. #pragma once
  11. #include "../../lib/GameConstants.h"
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. class JsonNode;
  14. VCMI_LIB_NAMESPACE_END
  15. class CDefFile;
  16. class IImage;
  17. /// Class for handling animation
  18. class CAnimation
  19. {
  20. private:
  21. //source[group][position] - file with this frame, if string is empty - image located in def file
  22. std::map<size_t, std::vector <JsonNode> > source;
  23. //bitmap[group][position], store objects with loaded bitmaps
  24. std::map<size_t, std::map<size_t, std::shared_ptr<IImage> > > images;
  25. //animation file name
  26. std::string name;
  27. bool preloaded;
  28. std::shared_ptr<CDefFile> defFile;
  29. //loader, will be called by load(), require opened def file for loading from it. Returns true if image is loaded
  30. bool loadFrame(size_t frame, size_t group);
  31. //unloadFrame, returns true if image has been unloaded ( either deleted or decreased refCount)
  32. bool unloadFrame(size_t frame, size_t group);
  33. //initialize animation from file
  34. void initFromJson(const JsonNode & input);
  35. void init();
  36. //to get rid of copy-pasting error message :]
  37. void printError(size_t frame, size_t group, std::string type) const;
  38. //not a very nice method to get image from another def file
  39. //TODO: remove after implementing resource manager
  40. std::shared_ptr<IImage> getFromExtraDef(std::string filename);
  41. public:
  42. CAnimation(std::string Name);
  43. CAnimation();
  44. ~CAnimation();
  45. //duplicates frame at [sourceGroup, sourceFrame] as last frame in targetGroup
  46. //and loads it if animation is preloaded
  47. void duplicateImage(const size_t sourceGroup, const size_t sourceFrame, const size_t targetGroup);
  48. //add custom surface to the selected position.
  49. void setCustom(std::string filename, size_t frame, size_t group=0);
  50. std::shared_ptr<IImage> getImage(size_t frame, size_t group=0, bool verbose=true) const;
  51. void exportBitmaps(const boost::filesystem::path & path) const;
  52. //all available frames
  53. void load ();
  54. void unload();
  55. void preload();
  56. //all frames from group
  57. void loadGroup (size_t group);
  58. void unloadGroup(size_t group);
  59. //single image
  60. void load (size_t frame, size_t group=0);
  61. void unload(size_t frame, size_t group=0);
  62. //total count of frames in group (including not loaded)
  63. size_t size(size_t group=0) const;
  64. void horizontalFlip();
  65. void verticalFlip();
  66. void playerColored(PlayerColor player);
  67. void createFlippedGroup(const size_t sourceGroup, const size_t targetGroup);
  68. };