-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsettings_schema.lua
More file actions
304 lines (287 loc) · 9.3 KB
/
settings_schema.lua
File metadata and controls
304 lines (287 loc) · 9.3 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
-- Settings schema - combines UI configuration and default values in one structure
--
-- This schema defines both the UI configuration for settings and their default values.
-- Settings are defined in a nested structure matching how they'll appear in the final config.
--
-- For settings that should appear in the UI, add a 'ui' field with configuration metadata:
-- {
-- default = <value>, -- The default value for this setting
-- ui = { -- UI metadata (only needed for configurable settings)
-- title = "Setting Name",
-- type = "slider", -- Currently only sliders are supported
-- min = 0,
-- max = 100,
-- step = 1,
-- description = "Help text shown in tooltip"
-- }
-- }
--
-- For settings that don't need to appear in the UI:
-- {
-- default = <value> -- Just specify the default value
-- }
local settings_schema =
{
-- Core settings definition - everything in one place
settings =
{
notifications =
{
-- Config menu items have a 'ui' field
max_num =
{
default = 4,
ui =
{
title = 'Max',
type = 'slider',
min = 3,
max = 10,
step = 1,
description = 'Maximum number of notifications to display',
},
},
hideDelay =
{
default = 5,
ui =
{
title = 'Auto-hide delay',
type = 'slider',
min = 1,
max = 10,
step = 1,
description = 'Time in seconds before notifications auto-hide',
},
},
spacing =
{
default = 8,
ui =
{
title = 'Spacing',
type = 'slider',
min = 0,
max = 20,
step = 1,
description = 'Vertical spacing between notifications',
},
},
scale =
{
default = 1.0,
ui =
{
title = 'Scale',
type = 'slider',
min = 0.1,
max = 5.0,
step = 0.05,
description = 'Size scaling factor for notifications',
},
},
offset =
{
x =
{
default = 20,
ui =
{
title = 'Offset X (from bottom right)',
type = 'slider',
min = 0,
max = backend.get_resolution_width(),
step = 5,
description = 'Horizontal offset from screen edge',
},
},
y =
{
default = 20,
ui =
{
title = 'Offset Y (from bottom right)',
type = 'slider',
min = 0,
max = backend.get_resolution_height(),
step = 5,
description = 'Vertical offset from screen edge',
},
},
},
-- Non-UI settings just have default values
show = { default = true },
autoHide = { default = true },
colors =
{
title = { default = ColorEnum.SoftBlue },
key = { default = ColorEnum.Purple },
value = { default = ColorEnum.Seafoam },
},
pos =
{
x = { default = 200 },
y = { default = 50 },
},
text =
{
alpha = { default = 255 },
red = { default = 255 },
green = { default = 255 },
blue = { default = 255 },
},
flags =
{
right = { default = false },
bottom = { default = false },
bold = { default = false },
italic = { default = false },
draggable = { default = true },
},
padding = { default = 0 },
bg =
{
red = { default = 30 },
green = { default = 30 },
blue = { default = 60 },
alpha = { default = 230 },
},
},
textBox =
{
scale =
{
default = 1.0,
ui =
{
title = 'Scale',
type = 'slider',
min = 0.5,
max = 5.0,
step = 0.1,
description = 'Size scaling factor for text boxes',
},
},
positions =
{
default = {},
},
defaults =
{
pos =
{
x = { default = 290 },
y = { default = 0 },
},
bg =
{
alpha = { default = 64 },
red = { default = 0 },
green = { default = 0 },
blue = { default = 0 },
visible = { default = true },
},
flags =
{
right = { default = false },
bottom = { default = false },
bold = { default = false },
italic = { default = false },
draggable = { default = true },
},
padding = { default = 3 },
},
},
},
-- UI category definitions
categories =
{
{
id = 'textBox',
title = 'TextBox',
},
{
id = 'notifications',
title = 'Notifications',
},
},
-- Build default settings from the schema
build_defaults = function(self)
local function extract_defaults(schema, result)
result = result or {}
for k, v in pairs(schema) do
if type(v) == 'table' then
if v.default ~= nil then
-- This is a leaf setting with a default value
result[k] = v.default
else
-- This is a branch, recurse
result[k] = {}
extract_defaults(v, result[k])
end
else
-- Direct value assignment (rare case)
result[k] = v
end
end
return result
end
return extract_defaults(self.settings)
end,
-- Get UI-configurable settings for a category
get_ui_settings = function(self, category_id)
-- Define the order of UI elements for each category
local ui_order =
{
notifications =
{
'max_num',
'hideDelay',
'spacing',
'scale',
'offset.x',
'offset.y',
},
textBox =
{
'scale',
},
}
local result = {}
-- Function to find a setting by path
local function find_setting_by_path(schema, path)
local parts = {}
for part in string.gmatch(path, '[^%.]+') do
table.insert(parts, part)
end
local current = schema
for i, part in ipairs(parts) do
if current[part] == nil then
return nil
end
current = current[part]
end
return current
end
-- Process settings in order
if ui_order[category_id] and self.settings[category_id] then
for _, path in ipairs(ui_order[category_id]) do
local setting = find_setting_by_path(self.settings[category_id], path)
if setting and setting.ui then
table.insert(result,
{
path = path,
default = setting.default,
ui = setting.ui,
})
end
end
end
return result
end,
}
local module = settings_schema
module.get_defaults = function()
return module:build_defaults()
end
return module