//  BlockyFroggy
//  Copyright © 2017 John Ryland.
//  All rights reserved.
#include "LuaBindings.h"
#include "SelectorState.h"
#include "GameSim.h"
#include "Math.h"
#include "Graphics.h"


REGISTER_GAME_STATE(SelectorState)


int m_editModel = 0;


void setModelNext() { m_editModel--; }
void setModelPrev() { m_editModel++; }


// Import table
static const struct luaL_Reg scriptCallableFunctions[] =
{
  { "setModelNext",   [](lua_State* lua)->int { return MakeCallableFunc(lua, setModelNext ); } },
  { "setModelPrev",   [](lua_State* lua)->int { return MakeCallableFunc(lua, setModelPrev ); } },
};


void SelectorState::getScriptCallableFunctions(const struct luaL_Reg* &list, int &count)
{
  list = scriptCallableFunctions;
  count = sizeof(scriptCallableFunctions) / sizeof(scriptCallableFunctions[0]);
}


void SelectorState::enter(GameGraphics& graphics)
{
  std::vector<GameSim::GameObjectList*> objectLists;
  graphics.resetVertexBuffers(objectLists);
}


void SelectorState::draw(GameGraphics& graphics)
{
/*
  //! @todo need to fix
  const char* modelNames[] = {
    " car ", " car ", " bus ", " bus ", " bike", " bike", " van ", " van ",
    "truck", "truck", "train", "train", " road", "water", " rail", " road", " tree", "empty"
  };
  state.addContrastString(250, 320, modelNames[std::abs(m_editModel % MODEL_COUNT)]);
*/

  graphics.prepareScreenContext();
  graphics.setEditModel(m_editModel);
}


bool SelectorState::update(GameUi::UpdateState& state, float elapsed)
{
  return true; // has to be exited via ui
}


