VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
KeyValues.cpp
Go to the documentation of this file.
1
#include <
VoltMod/Entities/KeyValues.hpp
>
2
#include <color.h>
3
#include <entity2/entitykeyvalues.h>
4
#include <mathlib/vector.h>
5
#include <string>
6
7
namespace
VoltMod
8
{
9
10
KeyValues::KeyValues
() : _kv(new CEntityKeyValues()) {}
11
12
KeyValues::~KeyValues
()
13
{
14
// The refcount starts at 0 and Release() deletes at <= 0, so this frees a
15
// never-spawned object; after Detach() there is nothing left to free here.
16
if
(_kv)
17
{
18
_kv->Release();
19
}
20
}
21
22
// CEntityKeyValues interns the key and copies the value, so the NUL-terminated temporaries below
23
// only have to survive the call.
24
KeyValues
&
KeyValues::Set
(std::string_view key, std::string_view value)
25
{
26
if
(_kv)
27
{
28
_kv->SetString(std::string(key).c_str(), std::string(value).c_str());
29
}
30
return
*
this
;
31
}
32
33
KeyValues
&
KeyValues::Set
(std::string_view key,
int
value)
34
{
35
if
(_kv)
36
{
37
_kv->SetInt(std::string(key).c_str(), value);
38
}
39
return
*
this
;
40
}
41
42
KeyValues
&
KeyValues::Set
(std::string_view key,
float
value)
43
{
44
if
(_kv)
45
{
46
_kv->SetFloat(std::string(key).c_str(), value);
47
}
48
return
*
this
;
49
}
50
51
KeyValues
&
KeyValues::Set
(std::string_view key,
bool
value)
52
{
53
if
(_kv)
54
{
55
_kv->SetBool(std::string(key).c_str(), value);
56
}
57
return
*
this
;
58
}
59
60
KeyValues
&
KeyValues::Set
(std::string_view key,
const
Vector
& value)
61
{
62
if
(_kv)
63
{
64
_kv->SetVector(std::string(key).c_str(), value);
65
}
66
return
*
this
;
67
}
68
69
KeyValues
&
KeyValues::Set
(std::string_view key,
const
QAngle
& value)
70
{
71
if
(_kv)
72
{
73
_kv->SetQAngle(std::string(key).c_str(), value);
74
}
75
return
*
this
;
76
}
77
78
KeyValues
&
KeyValues::Set
(std::string_view key,
const
Color
& value)
79
{
80
if
(_kv)
81
{
82
_kv->SetColor(std::string(key).c_str(),
::Color
(value.
R
, value.
G
, value.
B
, value.
A
));
83
}
84
return
*
this
;
85
}
86
87
CEntityKeyValues*
KeyValues::Detach
()
88
{
89
CEntityKeyValues* kv = _kv;
90
_kv =
nullptr
;
91
return
kv;
92
}
93
94
}
// namespace VoltMod
KeyValues.hpp
VoltMod::KeyValues::KeyValues
KeyValues()
Definition
KeyValues.cpp:10
VoltMod::KeyValues::Set
KeyValues & Set(std::string_view key, std::string_view value)
Definition
KeyValues.cpp:24
VoltMod::KeyValues::Detach
CEntityKeyValues * Detach()
Definition
KeyValues.cpp:87
VoltMod::KeyValues::~KeyValues
~KeyValues()
Definition
KeyValues.cpp:12
VoltMod
Definition
Options.hpp:13
VoltMod::QAngle
::QAngle QAngle
Definition
Math.hpp:15
VoltMod::Vector
::Vector Vector
Definition
Math.hpp:12
VoltMod::Color
An RGBA color in the engine's byte order, as m_clrRender and glow colors hold it.
Definition
Color.hpp:15
VoltMod::Color::A
uint8_t A
Definition
Color.hpp:19
VoltMod::Color::G
uint8_t G
Definition
Color.hpp:17
VoltMod::Color::B
uint8_t B
Definition
Color.hpp:18
VoltMod::Color::R
uint8_t R
Definition
Color.hpp:16
src
Entities
KeyValues.cpp
Generated by
1.15.0