This repository was archived by the owner on Mar 27, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathse_base.lua
More file actions
102 lines (77 loc) · 2.49 KB
/
se_base.lua
File metadata and controls
102 lines (77 loc) · 2.49 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
function SimpleExtension.Base:Initialize(defaults)
if SimpleExtension._settings[self.SE_NAME] == nil then
SimpleExtension._settings[self.SE_NAME] = defaults
SimpleExtension._settings[self.SE_NAME]._debug = false
SimpleExtension._settings[self.SE_NAME]._enabled = true
end
self.settings = SimpleExtension._settings[self.SE_NAME]
self._cache = {}
end
function SimpleExtension.Base:addBooleanOption(name, storage, flag)
local checkbox = {
type = "checkbox",
name = name,
getFunc = function()
local value = storage[flag]
return (value == nil) or value
end,
setFunc = function(value)
storage[flag] = (value == nil) or value
end,
}
table.insert(SimpleExtension._controls, checkbox)
return checkbox
end
function SimpleExtension.Base:addDebugOption()
self:addBooleanOption(
"Enable debug", SimpleExtension._settings[self.SE_NAME], "_debug")
end
function SimpleExtension.Base:addEnableOption()
local checkbox = self:addBooleanOption(
"Enable extension", SimpleExtension._settings[self.SE_NAME], "_enabled")
checkbox.requiresReload = true
end
function SimpleExtension.Base:cache(cacheName, cacheKey, cacheAction)
if self._cache[cacheName] == nil then
self._cache[cacheName] = {}
end
if self._cache[cacheName][cacheKey] == nil then
self._cache[cacheName][cacheKey] = cacheAction()
end
return self._cache[cacheName][cacheKey]
end
function SimpleExtension.Base:controls(header, controls)
table.insert(SimpleExtension._controls, {
type = "header",
name = header
})
self:addEnableOption()
if self:isEnabled() then
self:addDebugOption()
for _, control in ipairs(controls) do
table.insert(SimpleExtension._controls, control)
end
end
table.insert(SimpleExtension._controls, {
type = "custom",
})
end
function SimpleExtension.Base:debugAction(action)
if self:hasDebug() then
action()
end
end
function SimpleExtension.Base:debugMessage(format, ...)
if self:hasDebug() then
if self.SE_NAME then
format = self.SE_NAME .. ": " .. format
end
d(string.format(format, ...))
end
end
function SimpleExtension.Base:hasDebug()
return SimpleExtension._settings[self.SE_NAME]["_debug"]
end
function SimpleExtension.Base:isEnabled()
return SimpleExtension._settings[self.SE_NAME]["_enabled"]
end