VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
KeyValues.cpp
Go to the documentation of this file.
1#include <Color.h>
3#include <entity2/entitykeyvalues.h>
4#include <mathlib/vector.h>
5#include <string>
6
7namespace VoltMod
8{
9
11
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.
24KeyValues& 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
33KeyValues& 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
42KeyValues& 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
51KeyValues& 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
60KeyValues& 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
69KeyValues& 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
78KeyValues& 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
88{
89 CEntityKeyValues* kv = _kv;
90 _kv = nullptr;
91 return kv;
92}
93
94} // namespace VoltMod
Spawn keyvalues such as "origin", "spawnflags" or "effect_name".
Definition KeyValues.hpp:16
KeyValues & Set(std::string_view key, std::string_view value)
Definition KeyValues.cpp:24
CEntityKeyValues * Detach()
Definition KeyValues.cpp:87
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
::QAngle QAngle
Definition Math.hpp:14
::Vector Vector
Definition Math.hpp:11
An RGBA color in the engine's byte order, as m_clrRender and glow colors hold it.
Definition Color.hpp:15
uint8_t A
Definition Color.hpp:19
uint8_t G
Definition Color.hpp:17
uint8_t B
Definition Color.hpp:18
uint8_t R
Definition Color.hpp:16