#ifndef ANIMATIONEFFECT_H
#define ANIMATIONEFFECT_H

#include <vector>
#include <string>
#include <map>
#include "./effects/effect.h"
#include "./math/Mathematics.h"

///Auxiliary structure for AnimationManager. Holds data for 1 frame of animation.
struct AnimationFrame
{
	unsigned int textureId;
	float time;
};

/// Class to manage animations.
/**
* Class to manage animations. Animation is set of pictures which changes in time.
*/
class AnimationManager
{
private:
	std::map< std::string, vector< AnimationFrame >*  > animations;

	AnimationManager( const AnimationManager& ); //cannot be copied
	AnimationManager& operator=( const AnimationManager& ); //cannot be assigned

public:
	AnimationManager() {};
	~AnimationManager();

	bool insertAnimation( const std::string &name, const std::vector< AnimationFrame >& animation ); /**< Inserts animation into database. */
	bool removeAnimation( const std::string &name );		/**< Removes animation from database. */
	const std::vector< AnimationFrame >* getAnimation( const std::string &name );	/**< Returns animation from database. */
};

//map< std::string, vector< AnimationFrame > > FrameAnimationManager;


/// Class for effects based on animation.
class AnimationEffect: public Effect
{
public:
	/// has to be sorted ascending according to the time
	const vector< AnimationFrame >& animPtr;
	unsigned int lastFrameIdx;

	float animationLength;
	float animationTime;

	Point_3<float>	pos;
	float size[2];

	void render( Render & render );
	void simulate( float dt );

	virtual bool isActive( void ) { return animationTime < animationLength; }
	AnimationEffect( const vector< AnimationFrame >& animationPtr, float animationLength ):animPtr( animationPtr), animationLength(animationLength) {  lastFrameIdx = 0; animationTime=0; };
	~AnimationEffect() {};
};



#endif