-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathderma_convar_fix.lua
60 lines (51 loc) · 1.52 KB
/
derma_convar_fix.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
local cacheKeys, cache, len = {}, {}, 0
timer.Create("derma_convar_fix", 0.5, 0, function()
if len == 0 then return end
local name
for i = 1, len do
name = cache[i]
RunConsoleCommand(name, cacheKeys[name])
cacheKeys[name] = nil
cache[i] = nil
end
len = 0
end)
function Derma_SetCvar_Safe(name, value)
if not cacheKeys[name] then
cacheKeys[name] = tostring(value)
len = len + 1
cache[len] = name
else
timer.Adjust("derma_convar_fix", 0.5)
cacheKeys[name] = tostring(value)
end
end
function Derma_Install_Convar_Functions(PANEL)
function PANEL:SetConVar(strConVar)
self.m_strConVar = strConVar
end
function PANEL:ConVarChanged(strNewValue)
local cvar = self.m_strConVar
if not cvar or string.len(cvar) < 2 then return end
Derma_SetCvar_Safe(cvar, strNewValue)
end
-- Todo: Think only every 0.1 seconds?
function PANEL:ConVarStringThink()
local cvar = self.m_strConVar
if not cvar or string.len(cvar) < 2 then return end
local strValue = GetConVarString(cvar)
if self.m_strConVarValue == strValue then return end
self.m_strConVarValue = strValue
self:SetValue(strValue)
end
function PANEL:ConVarNumberThink()
local cvar = self.m_strConVar
if not cvar or string.len(cvar) < 2 then return end
local numValue = GetConVarNumber(cvar)
-- In case the convar is a "nan"
if numValue ~= numValue then return end
if self.m_strConVarValue == numValue then return end
self.m_strConVarValue = numValue
self:SetValue(numValue)
end
end