/***********************************************************
This class will deal with all the aspects about animation related things.
To spawn a new animation state - reset it's state using state reset functions

Active - currently active animation state 
Default - when the active animation state expires it must goes back to default state 
			(code must be explicitly given to switch between states)

Normal - normal frame progression from 0 to (maxFrameCount -1) --for index
Reverse - reverse frame progression from (maxFrameCount -1) to 0 --for index

doLoop - keep the animation in Loop 
isActive - only render if the state is active else it is ignored 
			default state is always isActive = true and doLoop = true
************************************************************/
#pragma once
#include "Animation.h"
#include "Position.h"
#include <mutex>

class AnimationState
{
	bool isActive = false;
	bool doReverse = false;
	bool doLoop = false;

	int activeFrameNo = 0;
	std::chrono::system_clock::time_point lastUpdate;
	Animation* ptr2Animation = nullptr;
	std::mutex renderingLock;

	void updateReverse();
	void updateNormal();
	bool needUpdate();
	void updateState();
public:

	void setActiveNormal(Animation* animPtr);
	void setActiveReverse(Animation* animPtr);
	void setDefaultNormal(Animation* animPtr);
	void setDefaultReverse(Animation* animPtr);
	void clearState();
	
	const bool& active();

	void draw(Position& objPos, Position& camPos, float& xScale, float& yScale, ALLEGRO_COLOR& tint);
	void draw(Position& objPos, Position& camPos, float& xScale, float& yScale);
	void draw(Position& objPos, Position& camPos);

	void draw(Position& objPos, float& xScale, float& yScale, ALLEGRO_COLOR& tint);
	void draw(Position& objPos, float& xScale, float& yScale);
	void draw(Position& objPos);
	
	AnimationState();
	~AnimationState();
};


