2017-01-20 08:36:52 -05:00
|
|
|
#pragma once
|
|
|
|
|
2017-01-19 16:23:59 -05:00
|
|
|
namespace Components
|
|
|
|
{
|
|
|
|
class Dvar : public Component
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
class Flag
|
|
|
|
{
|
|
|
|
public:
|
2017-06-14 06:06:04 -04:00
|
|
|
Flag(Game::dvar_flag flag) : val(flag) {};
|
2017-01-19 16:23:59 -05:00
|
|
|
Flag(int flag) : Flag(static_cast<Game::dvar_flag>(flag)) {};
|
|
|
|
|
|
|
|
Game::dvar_flag val;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Var
|
|
|
|
{
|
|
|
|
public:
|
2017-01-20 16:41:03 -05:00
|
|
|
Var() : dvar(nullptr) {};
|
2017-01-19 16:23:59 -05:00
|
|
|
Var(const Var &obj) { this->dvar = obj.dvar; };
|
|
|
|
Var(Game::dvar_t* _dvar) : dvar(_dvar) {};
|
|
|
|
Var(DWORD ppdvar) : Var(*reinterpret_cast<Game::dvar_t**>(ppdvar)) {};
|
2018-12-17 08:29:18 -05:00
|
|
|
Var(const std::string& dvarName);
|
2017-01-19 16:23:59 -05:00
|
|
|
|
|
|
|
template<typename T> T get();
|
|
|
|
|
|
|
|
void set(char* string);
|
|
|
|
void set(const char* string);
|
2018-12-17 08:29:18 -05:00
|
|
|
void set(const std::string& string);
|
2017-01-19 16:23:59 -05:00
|
|
|
|
|
|
|
void set(int integer);
|
|
|
|
void set(float value);
|
2021-08-29 11:41:21 -04:00
|
|
|
void set(bool enabled);
|
2017-01-19 16:23:59 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
Game::dvar_t* dvar;
|
|
|
|
};
|
|
|
|
|
|
|
|
Dvar();
|
|
|
|
~Dvar();
|
|
|
|
|
2017-05-31 09:45:12 -04:00
|
|
|
static void OnInit(Utils::Slot<Scheduler::Callback> callback);
|
2017-01-19 16:23:59 -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);
|
|
|
|
|
|
|
|
private:
|
2017-05-31 09:45:12 -04:00
|
|
|
static Utils::Signal<Scheduler::Callback> RegistrationSignal;
|
2017-01-19 16:23:59 -05:00
|
|
|
|
2017-01-20 16:41:03 -05:00
|
|
|
static Game::dvar_t* RegisterName(const char* name, const char* defaultVal, Game::dvar_flag flag, const char* description);
|
2017-02-18 05:39:01 -05:00
|
|
|
|
|
|
|
static Game::dvar_t* SetFromStringByNameExternal(const char* dvar, const char* value);
|
2017-07-09 07:36:13 -04:00
|
|
|
static Game::dvar_t* SetFromStringByNameSafeExternal(const char* dvar, const char* value);
|
2017-01-19 16:23:59 -05:00
|
|
|
};
|
|
|
|
}
|