#include "AnimatedState.h"
#include "../util/mathUtils.h"

AnimatedState::AnimatedState()
{
  clear();
}

AnimatedState::~AnimatedState()
{
}

void AnimatedState::clear()
{
  totalRunningTime=0;
  lastTimeAnimated=0;
  previousAnimationStatus=ANIMATION_STATUS_STOP;
  currentAnimationStatus=ANIMATION_STATUS_STOP;
  animToPlay="NULL_INDEX";
  doNotPlaySoundUntilThisTime=0;
}

uint8_t AnimatedState::getAnimationStatus()
{
  return currentAnimationStatus;
}

uint8_t AnimatedState::getPreviousAnimationStatus()
{
  return previousAnimationStatus;
}

void AnimatedState::play()
{
  previousAnimationStatus=currentAnimationStatus;
  currentAnimationStatus=ANIMATION_STATUS_PLAY;
}

void AnimatedState::pause()
{
  previousAnimationStatus=currentAnimationStatus;
  currentAnimationStatus=ANIMATION_STATUS_PAUSE;
}

void AnimatedState::stop()
{
  previousAnimationStatus=currentAnimationStatus;
  currentAnimationStatus=ANIMATION_STATUS_STOP;
  totalRunningTime=0;
  doNotPlaySoundUntilThisTime=0;
}

void AnimatedState::randomizedStop(int maxTime)
{
  //stops playback but sets the frame to random point.

  stop();
  totalRunningTime=generateRandomNumber(maxTime);
}

void AnimatedState::setAnimation (const string & name)
{
  if (name != animToPlay)
    {
      animToPlay=name;
      stop();
    }
}

const string & AnimatedState::getAnimation ()
{
  return animToPlay;
}

void AnimatedState::setDoNotPlaySoundUntilThisTime(uint32_t a)
{
  doNotPlaySoundUntilThisTime=a;
}

uint32_t AnimatedState::getDoNotPlaySoundUntilThisTime()
{
  return doNotPlaySoundUntilThisTime;
}

uint32_t AnimatedState::getTotalRunningTime()
{
  return totalRunningTime;
}

void AnimatedState::setTotalRunningTime(uint32_t a)
{
  totalRunningTime=a;
}

uint32_t AnimatedState::getLastTimeAnimated()
{
  return lastTimeAnimated;
}

void AnimatedState::setLastTimeAnimated(uint32_t a)
{
  lastTimeAnimated=a;
}

void AnimatedState::addToTotalRunningTime(uint32_t a)
{
  totalRunningTime+=a;
}
