| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- /*
- * CAnimation.h, 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
- *
- */
- #pragma once
- #include "../../lib/GameConstants.h"
- #include "../../lib/filesystem/ResourcePath.h"
- VCMI_LIB_NAMESPACE_BEGIN
- class JsonNode;
- VCMI_LIB_NAMESPACE_END
- class CDefFile;
- class IImage;
- class RenderHandler;
- /// Class for handling animation
- class CAnimation
- {
- private:
- //source[group][position] - file with this frame, if string is empty - image located in def file
- std::map<size_t, std::vector <JsonNode> > source;
- //bitmap[group][position], store objects with loaded bitmaps
- std::map<size_t, std::map<size_t, std::shared_ptr<IImage> > > images;
- //animation file name
- AnimationPath name;
- bool preloaded;
- //loader, will be called by load(), require opened def file for loading from it. Returns true if image is loaded
- bool loadFrame(size_t frame, size_t group);
- //unloadFrame, returns true if image has been unloaded ( either deleted or decreased refCount)
- bool unloadFrame(size_t frame, size_t group);
- //to get rid of copy-pasting error message :]
- void printError(size_t frame, size_t group, std::string type) const;
- public:
- CAnimation(const AnimationPath & Name, std::map<size_t, std::vector <JsonNode> > layout);
- CAnimation();
- ~CAnimation();
- //duplicates frame at [sourceGroup, sourceFrame] as last frame in targetGroup
- //and loads it if animation is preloaded
- void duplicateImage(const size_t sourceGroup, const size_t sourceFrame, const size_t targetGroup);
- //add custom surface to the selected position.
- void setCustom(std::string filename, size_t frame, size_t group=0);
- std::shared_ptr<IImage> getImage(size_t frame, size_t group=0, bool verbose=true) const;
- void exportBitmaps(const boost::filesystem::path & path) const;
- //all available frames
- void load ();
- void unload();
- void preload();
- //all frames from group
- void loadGroup (size_t group);
- void unloadGroup(size_t group);
- //single image
- void load (size_t frame, size_t group=0);
- void unload(size_t frame, size_t group=0);
- //total count of frames in group (including not loaded)
- size_t size(size_t group=0) const;
- void horizontalFlip();
- void verticalFlip();
- void playerColored(PlayerColor player);
- void createFlippedGroup(const size_t sourceGroup, const size_t targetGroup);
- };
|