/*********************************************************************//**
*	\brief Game variables library.
*	Modul uziva mapu pro ukladani promenych a tvori 
*			databazi vsech promenych. Promenna ma pristupova prava,
*			minimalni, maximalni a standardni hodnotu.  
*
*	\author Michal Jirous
*	\date 23.7.2008
*	\file ctrl_gamevars.h
**********************************************************************/

#ifndef __GAMEVAR_H__
#define __GAMEVAR_H__

#include <string>

enum vartypes				//Typy ukladanych dat
{
	VAR_INT = 0,
	VAR_FLOAT,
	VAR_STRING
};

struct FloatData
{
	float min, max;
	float value;
	float default_value;
};

struct IntData
{
	int min, max;
	int value;
	int default_value;
};

struct StringData
{
	//bool ascii7;
	size_t maxlength;
	std::string value;
	std::string default_value;
};

struct variable				//objekt pro ulozeni do tabulky, nese 3 mozne typy dat
{
	bool user_allowed;
	int type;
	void *data;
	variable() : data(NULL) {}
};

namespace gamevarsLibrary
{
	static const char* VARIABLE_TYPE_ERROR = "Error: Wrong parameter type: its ";
	static const char* ERROR_VARIABLE_DEVELOPER_ONLY = "Error: Variable can be changed in developer mode only.";
	static const char* ERROR_VARIABLE_OUT_OF_RANGE = "Error: Value out of range. Use range ";
	const size_t GAMEVAR_DEFAULT_STRING_LENGHT = 30;
	

	void init();
	void initVariables();
	void destroy();

	bool setVariable(std::string key, int data);			//Pretizene funkce, pro zmenu hodnot dat objektu tabulky
	bool setVariable(std::string key, float data);
	bool setVariable(std::string key, std::string data);

	bool setVariable(variable *var, int data);			//Pretizene funkce, pro zmenu hodnot dat objektu tabulky
	bool setVariable(variable *var, float data);
	bool setVariable(variable *var, std::string data);


	void addVar(std::string key,int data, bool allowed_for_user = false, int min = 0, int max = 1);				//Pretizene funkce, pro pridani objektu do tabulky
	void addVar(std::string key, float data, bool allowed_for_user = false, float min = 0.0f, float max = 1.0f);
	void addVar(std::string key, std::string data, bool allowed_for_user = false, size_t maxlenght = GAMEVAR_DEFAULT_STRING_LENGHT );
	
	variable *getVariable( std::string key);				//vraci ukazatel na objekt
	
	int getiData(std::string key);						//Funkce vraci hodnotu int objektu tabulky
	float getfData(std::string key);						//pro float
	std::string getsData(std::string key);					//pro string

	int getiData(variable *var);						
	float getfData(variable *var);						
	std::string getsData(variable *var);					

	void printVar( std::string name, variable *data );
	void printVar( std::string var );


};

#endif

