2010-10-18 18:08:59 +03:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
2017-07-13 10:26:03 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../../lib/GameConstants.h"
|
2023-08-23 14:07:50 +02:00
|
|
|
#include "../../lib/filesystem/ResourcePath.h"
|
2010-10-18 18:08:59 +03:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
2011-07-21 21:29:22 +03:00
|
|
|
class JsonNode;
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_END
|
|
|
|
|
2016-11-07 23:19:53 +02:00
|
|
|
class CDefFile;
|
2023-02-01 20:42:06 +02:00
|
|
|
class IImage;
|
2023-09-04 17:01:44 +02:00
|
|
|
class RenderHandler;
|
2010-10-18 18:08:59 +03:00
|
|
|
|
2011-03-22 15:19:07 +02:00
|
|
|
/// Class for handling animation
|
2011-02-06 19:26:27 +02:00
|
|
|
class CAnimation
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
//source[group][position] - file with this frame, if string is empty - image located in def file
|
2011-07-21 21:29:22 +03:00
|
|
|
std::map<size_t, std::vector <JsonNode> > source;
|
2011-02-06 19:26:27 +02:00
|
|
|
|
|
|
|
//bitmap[group][position], store objects with loaded bitmaps
|
2018-04-07 13:34:11 +02:00
|
|
|
std::map<size_t, std::map<size_t, std::shared_ptr<IImage> > > images;
|
2010-10-18 18:08:59 +03:00
|
|
|
|
2011-01-01 22:26:39 +02:00
|
|
|
//animation file name
|
2023-08-23 14:07:50 +02:00
|
|
|
AnimationPath name;
|
2011-01-01 22:26:39 +02:00
|
|
|
|
2016-10-18 09:31:31 +02:00
|
|
|
bool preloaded;
|
|
|
|
|
2018-07-25 00:36:48 +02:00
|
|
|
std::shared_ptr<CDefFile> defFile;
|
2017-09-08 13:25:12 +02:00
|
|
|
|
2010-10-18 18:08:59 +03:00
|
|
|
//loader, will be called by load(), require opened def file for loading from it. Returns true if image is loaded
|
2017-09-08 13:25:12 +02:00
|
|
|
bool loadFrame(size_t frame, size_t group);
|
2010-10-18 18:08:59 +03:00
|
|
|
|
|
|
|
//unloadFrame, returns true if image has been unloaded ( either deleted or decreased refCount)
|
|
|
|
bool unloadFrame(size_t frame, size_t group);
|
|
|
|
|
|
|
|
//initialize animation from file
|
2013-04-22 22:51:22 +03:00
|
|
|
void initFromJson(const JsonNode & input);
|
2017-09-08 13:25:12 +02:00
|
|
|
void init();
|
2010-10-18 18:08:59 +03:00
|
|
|
|
|
|
|
//to get rid of copy-pasting error message :]
|
|
|
|
void printError(size_t frame, size_t group, std::string type) const;
|
|
|
|
|
2011-02-20 11:24:53 +02:00
|
|
|
//not a very nice method to get image from another def file
|
|
|
|
//TODO: remove after implementing resource manager
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<IImage> getFromExtraDef(std::string filename);
|
2011-02-20 11:24:53 +02:00
|
|
|
|
2010-10-18 18:08:59 +03:00
|
|
|
public:
|
2023-08-23 14:07:50 +02:00
|
|
|
CAnimation(const AnimationPath & Name);
|
2010-10-18 18:08:59 +03:00
|
|
|
CAnimation();
|
|
|
|
~CAnimation();
|
|
|
|
|
2016-11-07 23:19:53 +02:00
|
|
|
//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);
|
|
|
|
|
2011-02-06 19:26:27 +02:00
|
|
|
//add custom surface to the selected position.
|
2011-02-20 11:24:53 +02:00
|
|
|
void setCustom(std::string filename, size_t frame, size_t group=0);
|
2010-10-18 18:08:59 +03:00
|
|
|
|
2018-04-07 13:34:11 +02:00
|
|
|
std::shared_ptr<IImage> getImage(size_t frame, size_t group=0, bool verbose=true) const;
|
2010-10-25 22:37:21 +03:00
|
|
|
|
2016-11-25 14:23:28 +02:00
|
|
|
void exportBitmaps(const boost::filesystem::path & path) const;
|
|
|
|
|
2010-10-18 18:08:59 +03:00
|
|
|
//all available frames
|
|
|
|
void load ();
|
|
|
|
void unload();
|
2016-10-18 09:31:31 +02:00
|
|
|
void preload();
|
2010-10-18 18:08:59 +03:00
|
|
|
|
|
|
|
//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);
|
|
|
|
|
2011-02-06 19:26:27 +02:00
|
|
|
//total count of frames in group (including not loaded)
|
|
|
|
size_t size(size_t group=0) const;
|
2017-09-05 15:44:27 +02:00
|
|
|
|
|
|
|
void horizontalFlip();
|
|
|
|
void verticalFlip();
|
|
|
|
void playerColored(PlayerColor player);
|
2017-09-05 19:04:17 +02:00
|
|
|
|
2017-09-05 19:45:29 +02:00
|
|
|
void createFlippedGroup(const size_t sourceGroup, const size_t targetGroup);
|
2010-11-15 17:15:00 +02:00
|
|
|
};
|
2015-01-31 00:37:28 +02:00
|
|
|
|