2015-12-23 08:45:53 -05:00
|
|
|
namespace Components
|
|
|
|
{
|
|
|
|
class Dvar : public Component
|
|
|
|
{
|
|
|
|
public:
|
2016-02-11 05:26:41 -05:00
|
|
|
typedef void(Callback)();
|
2016-01-02 20:37:06 -05:00
|
|
|
|
2016-06-30 13:38:48 -04:00
|
|
|
class Flag
|
|
|
|
{
|
|
|
|
public:
|
2015-12-26 21:56:00 -05:00
|
|
|
Flag(Game::dvar_flag flag) : val(flag){};
|
|
|
|
Flag(int flag) : Flag((Game::dvar_flag)flag) {};
|
|
|
|
|
|
|
|
Game::dvar_flag val;
|
|
|
|
};
|
|
|
|
|
2015-12-23 08:45:53 -05:00
|
|
|
class Var
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Var() : dvar(0) {};
|
|
|
|
Var(const Var &obj) { this->dvar = obj.dvar; };
|
|
|
|
Var(Game::dvar_t* _dvar) : dvar(_dvar) {};
|
|
|
|
Var(std::string dvarName);
|
2015-12-25 15:42:35 -05:00
|
|
|
Var(std::string dvarName, std::string value);
|
2015-12-23 08:45:53 -05:00
|
|
|
|
|
|
|
template<typename T> T Get();
|
|
|
|
|
|
|
|
void Set(char* string);
|
|
|
|
void Set(const char* string);
|
|
|
|
void Set(std::string string);
|
|
|
|
|
|
|
|
void Set(int integer);
|
|
|
|
void Set(float value);
|
|
|
|
|
2015-12-26 21:56:00 -05:00
|
|
|
// TODO: Add others
|
|
|
|
void SetRaw(int integer);
|
2015-12-23 08:45:53 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
Game::dvar_t* dvar;
|
|
|
|
};
|
|
|
|
|
|
|
|
Dvar();
|
2016-08-15 10:40:30 -04:00
|
|
|
~Dvar();
|
|
|
|
|
2016-09-16 05:04:28 -04:00
|
|
|
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
|
2015-12-23 08:45:53 -05:00
|
|
|
const char* GetName() { return "Dvar"; };
|
2016-08-15 10:40:30 -04:00
|
|
|
#endif
|
2015-12-23 08:45:53 -05:00
|
|
|
|
2016-02-11 05:26:41 -05:00
|
|
|
static void OnInit(Callback* callback);
|
2016-01-02 20:37:06 -05:00
|
|
|
|
2015-12-26 21:56:00 -05:00
|
|
|
// Only strings and bools use this type of declaration
|
|
|
|
template<typename T> static Var Register(const char* name, T value, Flag flag, const char* description);
|
|
|
|
template<typename T> static Var Register(const char* name, T value, T min, T max, Flag flag, const char* description);
|
|
|
|
|
2015-12-23 08:45:53 -05:00
|
|
|
private:
|
2016-02-11 05:26:41 -05:00
|
|
|
static wink::signal<wink::slot<Callback>> RegistrationSignal;
|
2016-01-02 20:37:06 -05:00
|
|
|
|
2015-12-23 11:12:15 -05:00
|
|
|
static Game::dvar_t* RegisterName(const char* name, const char* default, Game::dvar_flag flag, const char* description);
|
2015-12-23 08:45:53 -05:00
|
|
|
};
|
|
|
|
}
|