#include "Session.h"

Session::Session()
{
  sdlRE=NULL;
  rander=NULL;
  sh=NULL;
  rulez=NULL;
  hitboxes.clear();
  pwrSelector.clear();
}

Session::~Session()
{
  sdlRE=NULL;
}

shippingHandler * Session::getShippingHandler ()
{
  return sdlRE;
}

void Session::setShippingHandler (shippingHandler * s)
{
  sdlRE=s;
}

LocalInputCollection & Session::getPlayerInput ()
{
  return playerInput;
}

//Renderer
Renderer * Session::getRenderer()
{
  return rander;
}

void Session::setRenderer(Renderer * r)
{
  rander =r;
}

//StateHandler
StateHandler * Session::getStateHandler()
{
  return sh;
}

void Session::setStateHandler(StateHandler * s)
{
  sh=s;
}

//Param handling
//You should only have an old param and a new param at all times to quickly load data into. They will be cleared whenever you change state.
void Session::initParams ()
{
  //setting up param swap.
  paramOld=NULL, paramNew=NULL;
  paramA.clearParamState();
  paramB.clearParamState();

  paramOld=&paramA;
  paramNew=&paramB;
}

Param * Session::getParamOld ()
{
  return paramOld;
}

Param * Session::getParamNew ()
{
  return paramNew;
}

//params are swapped
//ParamOld is emptied; ParamOld and ParamNew are swapped
void Session::swapParams()
{
  paramOld->clearParamState();

  if (paramOld==&paramA)
    {
      paramOld=&paramB;
      paramNew=&paramA;
    }
  else
    {
      paramOld=&paramA;
      paramNew=&paramB;
    }
}

//retrieve hitboxes
vector<HitBox> & Session::getHitBoxes()
{
  return hitboxes;
}

//Rules
Rules * Session::getRules()
{
  return rulez;
}

void Session::setRules(Rules * r)
{
  rulez=r;
}

//These functions load an object from the ParamOld and put it into ParamNew.
//If the key doesn't exist, the Default value is 0
void Session::passOldHashToNewInt (const string & key)
{
  int value=0;
  getParamOld()->getInt(key, value);
  getParamNew()->setInt(key, value);
}

//If the key doesn't exist, the Default value is false
void Session::passOldHashToNewBool (const string & key)
{
  bool value=false;
  getParamOld()->getBool(key, value);
  getParamNew()->setBool(key, value);
}

//If the key doesn't exist, the Default value is ""
void Session::passOldHashToNewString (const string & key)
{
  string value="";
  getParamOld()->getString(key, value);
  getParamNew()->setString(key, value);
}

//PowerSelector
PowerSelector * Session::getPowerSelector()
{
  return &pwrSelector;
}

//TextContainer
TextContainer * Session::getTextContainer()
{
  return &tc;
}
