Repository navigation
Expand file tree
/
Copy pathUtils.lua
More file actions
267 lines (234 loc) · 8.51 KB
/
Copy pathUtils.lua
File metadata and controls
267 lines (234 loc) · 8.51 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
local _, WE = ...
local floor = math.floor
local max = math.max
local min = math.min
function WE.DeepCopy(value)
if type(value) ~= "table" then
return value
end
local result = {}
for key, child in pairs(value) do
result[key] = WE.DeepCopy(child)
end
return result
end
function WE.DeepCopyDefaults()
return WE.DeepCopy(WE.DEFAULT_DB)
end
local function MergeDefaults(target, defaults)
if type(target) ~= "table" then
return WE.DeepCopy(defaults)
end
for key, defaultValue in pairs(defaults) do
if type(defaultValue) == "table" then
target[key] = MergeDefaults(target[key], defaultValue)
elseif type(target[key]) ~= type(defaultValue) then
target[key] = defaultValue
end
end
return target
end
function WE.Clamp(value, low, high)
value = tonumber(value) or low
return max(low, min(high, value))
end
local function ValidateColor(color, fallback)
if type(color) ~= "table" then
return WE.DeepCopy(fallback)
end
for index = 1, 4 do
color[index] = WE.Clamp(color[index], 0, 1)
end
return color
end
local function ValidateProfile(profile)
local defaults = WE.DEFAULT_PROFILE
local frame = profile.frame
frame.scale = WE.Clamp(frame.scale, 0.75, 2.0)
frame.alphaNormal = WE.Clamp(frame.alphaNormal, 0, 1)
frame.alphaOccluded = WE.Clamp(frame.alphaOccluded, 0, 1)
frame.alphaClamped = WE.Clamp(frame.alphaClamped, 0, 1)
frame.clampRadiusX = WE.Clamp(frame.clampRadiusX, 200, 900)
frame.clampRadiusY = WE.Clamp(frame.clampRadiusY, 100, 500)
if frame.strata ~= "MEDIUM" and frame.strata ~= "HIGH" and frame.strata ~= "DIALOG" then
frame.strata = "HIGH"
end
local icon = profile.icon
icon.size = WE.Clamp(icon.size, 24, 96)
if not WE.GLOW_SHAPES[icon.glowShape] then
icon.glowShape = defaults.icon.glowShape
end
icon.glowSize = WE.Clamp(icon.glowSize, 24, 160)
icon.glowAlpha = WE.Clamp(icon.glowAlpha, 0, 1)
icon.shadowOffsetX = WE.Clamp(icon.shadowOffsetX, -50, 50)
icon.shadowOffsetY = WE.Clamp(icon.shadowOffsetY, -50, 50)
local text = profile.text
if text.font == "" then
text.font = defaults.text.font
end
text.size = WE.Clamp(text.size, 10, 32)
text.offsetX = WE.Clamp(text.offsetX, -50, 50)
text.offsetY = WE.Clamp(text.offsetY, -50, 50)
text.shadowOffsetX = WE.Clamp(text.shadowOffsetX, -10, 10)
text.shadowOffsetY = WE.Clamp(text.shadowOffsetY, -10, 10)
text.nearDistance = WE.Clamp(text.nearDistance, 0, 200)
text.farDistance = WE.Clamp(text.farDistance, text.nearDistance + 1, 5000)
text.backgroundAlpha = WE.Clamp(text.backgroundAlpha, 0, 1)
text.backgroundPaddingX = WE.Clamp(text.backgroundPaddingX, 0, 30)
text.backgroundPaddingY = WE.Clamp(text.backgroundPaddingY, 0, 20)
if text.outline ~= "" and text.outline ~= "OUTLINE" and text.outline ~= "THICKOUTLINE" then
text.outline = "OUTLINE"
end
if text.compact and text.uppercase then
text.uppercase = false
end
local arrow = profile.arrow
arrow.scale = WE.Clamp(arrow.scale, 0.5, 2.5)
if not WE.GLOW_SHAPES[arrow.glowShape] then
arrow.glowShape = defaults.arrow.glowShape
end
arrow.glowSize = WE.Clamp(arrow.glowSize, 16, 128)
arrow.glowAlpha = WE.Clamp(arrow.glowAlpha, 0, 1)
local background = profile.background
background.width = WE.Clamp(background.width, 40, 180)
background.height = WE.Clamp(background.height, 40, 180)
background.alpha = WE.Clamp(background.alpha, 0, 1)
profile.visibility.hideNearDistance = WE.Clamp(profile.visibility.hideNearDistance, 1, 100)
local validPoints = {
TOPLEFT = true, TOP = true, TOPRIGHT = true,
LEFT = true, CENTER = true, RIGHT = true,
BOTTOMLEFT = true, BOTTOM = true, BOTTOMRIGHT = true,
}
if not validPoints[profile.preview.point] then
profile.preview.point = "CENTER"
end
if not validPoints[profile.preview.relativePoint] then
profile.preview.relativePoint = "CENTER"
end
profile.preview.x = WE.Clamp(profile.preview.x, -5000, 5000)
profile.preview.y = WE.Clamp(profile.preview.y, -5000, 5000)
icon.tintColor = ValidateColor(icon.tintColor, defaults.icon.tintColor)
icon.glowColor = ValidateColor(icon.glowColor, defaults.icon.glowColor)
icon.shadowColor = ValidateColor(icon.shadowColor, defaults.icon.shadowColor)
text.color = ValidateColor(text.color, defaults.text.color)
text.shadowColor = ValidateColor(text.shadowColor, defaults.text.shadowColor)
text.nearColor = ValidateColor(text.nearColor, defaults.text.nearColor)
text.farColor = ValidateColor(text.farColor, defaults.text.farColor)
text.backgroundColor = ValidateColor(text.backgroundColor, defaults.text.backgroundColor)
arrow.tintColor = ValidateColor(arrow.tintColor, defaults.arrow.tintColor)
background.color = ValidateColor(background.color, defaults.background.color)
if not WE.PRESETS[profile.preset] and profile.preset ~= "CUSTOM" then
profile.preset = "HIGH_CONTRAST"
end
end
function WE.ValidateCurrentProfile()
ValidateProfile(WE.GetDB())
end
function WE.InitializeDB()
local previousVersion = type(WaypointEnhancerDB) == "table" and (tonumber(WaypointEnhancerDB.version) or 0) or WE.DB_VERSION
if type(WaypointEnhancerDB) ~= "table" then
WaypointEnhancerDB = WE.DeepCopyDefaults()
else
WaypointEnhancerDB = MergeDefaults(WaypointEnhancerDB, WE.DEFAULT_DB)
end
WaypointEnhancerDB.version = WE.DB_VERSION
WaypointEnhancerDB.profile = "Default"
local profile = WaypointEnhancerDB.profiles.Default
local icon = profile.icon
icon.borderEnabled = nil
icon.borderSize = nil
icon.borderColor = nil
icon.borderAlpha = nil
icon.alpha = nil
profile.arrow.alpha = nil
if previousVersion < 2 then
profile.background.enabled = false
end
if previousVersion < 4 and profile.preset ~= "CUSTOM" then
profile.background.enabled = false
end
ValidateProfile(profile)
return WaypointEnhancerDB
end
function WE.GetDB()
if type(WaypointEnhancerDB) ~= "table" then
WE.InitializeDB()
end
return WaypointEnhancerDB.profiles.Default
end
function WE.ResetAllSettings()
WaypointEnhancerDB = WE.DeepCopyDefaults()
end
function WE.GetPath(path)
local value = WE.GetDB()
for segment in string.gmatch(path, "[^.]+") do
if type(value) ~= "table" then
return nil
end
value = value[segment]
end
return value
end
function WE.SetPath(path, newValue)
local target = WE.GetDB()
local segments = {}
for segment in string.gmatch(path, "[^.]+") do
segments[#segments + 1] = segment
end
for index = 1, #segments - 1 do
target = target[segments[index]]
end
target[segments[#segments]] = newValue
end
function WE.MarkCustom()
if not WE.applyingPreset then
WE.GetDB().preset = "CUSTOM"
local presetSetting = WE.settingsByPath and WE.settingsByPath.preset
if presetSetting and presetSetting:GetValue() ~= "CUSTOM" then
C_Timer.After(0, function()
if presetSetting:GetValue() ~= "CUSTOM" then
presetSetting:SetValue("CUSTOM")
end
end)
end
end
end
function WE.ApplyPreset(presetKey)
local preset = WE.PRESETS[presetKey]
if not preset then
return false
end
WE.applyingPreset = true
local profile = WE.GetDB()
for _, section in ipairs({ "frame", "icon", "text", "arrow", "background" }) do
profile[section] = WE.DeepCopy(preset[section])
end
profile.preset = presetKey
WE.applyingPreset = false
if WE.InvalidateHotState then
WE.InvalidateHotState()
end
if WE.ApplyAll then
WE.ApplyAll()
end
if WE.UpdatePreview then
WE.UpdatePreview()
end
if WE.RefreshSettingsLayout then
WE.RefreshSettingsLayout()
end
return true
end
function WE.Round(value)
return floor((tonumber(value) or 0) + 0.5)
end
function WE.LerpColor(nearColor, farColor, amount)
amount = WE.Clamp(amount, 0, 1)
return nearColor[1] + (farColor[1] - nearColor[1]) * amount,
nearColor[2] + (farColor[2] - nearColor[2]) * amount,
nearColor[3] + (farColor[3] - nearColor[3]) * amount,
nearColor[4] + (farColor[4] - nearColor[4]) * amount
end
function WE.Print(message)
DEFAULT_CHAT_FRAME:AddMessage("|cff33f2ffWaypoint Enhancer:|r " .. tostring(message))
end