7#include <tier1/convar.h>
32template <ConVarValue T>
35 const std::string
owned(name);
37 if (!
ref.IsValidRef() || !
ref.IsConVarDataAvailable())
46 std::format(
"convar '{}' is engine type {}, not the requested one",
owned,
static_cast<int>(type))));
57 return std::unexpected(
Error::Engine(std::format(
"convar '{}' has no value storage",
owned)));
76 const auto type =
static_cast<ConVarType>(_type);
78 if constexpr (std::is_same_v<T, bool>)
80 return _storage->m_bValue;
82 else if constexpr (std::is_same_v<T, std::string>)
84 const char*
text = _storage->m_StringValue.Get();
85 return text ? std::string(
text) : std::string{};
87 else if constexpr (std::is_same_v<T, float>)
89 return _storage->m_fl32Value;
97 return _storage->m_i16Value;
99 return _storage->m_u16Value;
101 return _storage->m_i32Value;
109 if (!_storage || !_service)
111 return std::unexpected(
Error::NotReady(
"convar handle is unresolved"));
116 _service->SetByConsole(_name,
ConVarText(value));
129 const auto type =
static_cast<ConVarType>(_type);
130 if constexpr (std::is_same_v<T, bool>)
132 _storage->m_bValue = value;
134 else if constexpr (std::is_same_v<T, float>)
136 _storage->m_fl32Value = value;
143 _storage->m_i16Value =
static_cast<int16_t>(value);
146 _storage->m_u16Value =
static_cast<uint16_t>(value);
149 _storage->m_i32Value = value;
158 if (_storage && _service)
177 _cvar->SetRaw(_previous);
ConVarRawScope(ConVar< T > &cvar, const T &value)
Status Set(const T &value)
void SetFor(int slot, const T &value) const
Result< ConVar< T > > Find(std::string_view name)
std::string ConVarText(const T &value)
static std::string ReadFile(const std::filesystem::path &path)
std::expected< void, Error > Status
std::expected< T, Error > Result
static Error Invalid(std::string detail)
static Error Engine(std::string detail)
static Error NotFound(std::string detail)
static Error NotReady(std::string detail)