From cc39a7bbe5ca55c1d92192f0d6c7e99f282463fc Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 10 Sep 2021 11:40:30 +0200 Subject: [PATCH] Reintroduce setRaw dvar methods - Makes it possible to set the value of a dvar without using the game's way of first converting it to a string and checking all kinds of dvar flags --- src/Components/Modules/Dvar.cpp | 30 ++++++++++++++++++++++++++++++ src/Components/Modules/Dvar.hpp | 4 ++++ 2 files changed, 34 insertions(+) diff --git a/src/Components/Modules/Dvar.cpp b/src/Components/Modules/Dvar.cpp index ad28175c..c83a1f7c 100644 --- a/src/Components/Modules/Dvar.cpp +++ b/src/Components/Modules/Dvar.cpp @@ -134,6 +134,36 @@ namespace Components } } + void Dvar::Var::setRaw(int integer) + { + assert(this->dvar->type == Game::DVAR_TYPE_INT); + if (this->dvar) + { + this->dvar->current.integer = integer; + this->dvar->latched.integer = integer; + } + } + + void Dvar::Var::setRaw(float value) + { + assert(this->dvar->type == Game::DVAR_TYPE_FLOAT); + if (this->dvar) + { + this->dvar->current.value = value; + this->dvar->latched.value = value; + } + } + + void Dvar::Var::setRaw(bool enabled) + { + assert(this->dvar->type == Game::DVAR_TYPE_BOOL); + if (this->dvar) + { + this->dvar->current.enabled = enabled; + this->dvar->latched.enabled = enabled; + } + } + template<> static Dvar::Var Dvar::Register(const char* name, bool value, Dvar::Flag flag, const char* description) { return Game::Dvar_RegisterBool(name, value, flag.val, description); diff --git a/src/Components/Modules/Dvar.hpp b/src/Components/Modules/Dvar.hpp index 47cf8102..33f291fb 100644 --- a/src/Components/Modules/Dvar.hpp +++ b/src/Components/Modules/Dvar.hpp @@ -33,6 +33,10 @@ namespace Components void set(float value); void set(bool enabled); + void setRaw(int integer); + void setRaw(float value); + void setRaw(bool enabled); + private: Game::dvar_t* dvar; };