Skip to content

Commit fbdcb5b

Browse files
committed
0.3.3
1 parent 80b1bd0 commit fbdcb5b

26 files changed

Lines changed: 357 additions & 83 deletions

Code/API/Core/FrameUtil.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ do
6363

6464
function addon.API.FrameUtil:SetDynamicTextSize(frame, relativeTo, maxWidth, maxHeight, setMaxWidth, setMaxHeight)
6565
local function updateSize()
66+
if addon.API.Util:IsSecretValue(frame:GetText()) then return end
67+
6668
local width = maxWidth and (type(maxWidth) == "function" and maxWidth(relativeTo:GetWidth(), relativeTo:GetHeight()) or maxWidth) or relativeTo:GetWidth()
6769
local height = maxHeight and (type(maxHeight) == "function" and maxHeight(relativeTo:GetWidth(), relativeTo:GetHeight()) or maxHeight) or 10000
6870
local stringWidth, stringHeight = addon.API.Util:GetStringSize(frame, width, height)

Code/API/Core/Main.lua

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,15 @@ do -- UI Visibility
190190
function addon.API.Main:SetupUICheck()
191191
local IsInCutscene = false
192192

193+
local function UpdateCutsceneUIVisibility()
194+
local profile = addon.Database.DB_GLOBAL and addon.Database.DB_GLOBAL.profile
195+
if not (profile and profile.INT_HIDEUI and InteractionPriorityFrame) then
196+
return
197+
end
198+
199+
if IsInCutscene then addon.BlizzardFrames.Script:RemoveElements() else addon.BlizzardFrames.Script:SetElements() end
200+
end
201+
193202
local uiFrame = CreateFrame("Frame")
194203
uiFrame:RegisterEvent("CINEMATIC_START")
195204
uiFrame:RegisterEvent("PLAY_MOVIE")
@@ -202,11 +211,11 @@ do -- UI Visibility
202211
IsInCutscene = false
203212
end
204213

205-
if addon.Database.DB_GLOBAL.profile.INT_HIDEUI and InteractionPriorityFrame then
206-
if IsInCutscene then addon.BlizzardFrames.Script:RemoveElements() else addon.BlizzardFrames.Script:SetElements() end
207-
end
214+
UpdateCutsceneUIVisibility()
208215
end)
209216

217+
addon.CallbackRegistry:Add("ADDON_DATABASE_READY", UpdateCutsceneUIVisibility)
218+
210219
function addon.API.Main:CanShowUIAndHideElements()
211220
local result = not C_PlayerInteractionManager.IsInteractingWithNpcOfType(57) and not IsInCutscene
212221

Code/API/Core/Util.lua

Lines changed: 150 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ do -- String measurement & parsing
2828
addon.API.MeasurementText:Hide()
2929

3030
function addon.API.Util:GetStringSize(frame, maxWidth, maxHeight)
31-
local text = addon.API.Util:GetUnformattedText(frame:GetText())
31+
local rawText = frame:GetText()
32+
if addon.API.Util:IsSecretValue(rawText) then
33+
return maxWidth or 0, maxHeight or 0
34+
end
35+
36+
local text = addon.API.Util:GetUnformattedText(rawText)
3237
local font, size, flags = frame:GetFont()
3338
local justifyH, justifyV = frame:GetJustifyH(), frame:GetJustifyV()
3439

@@ -50,12 +55,47 @@ do -- String measurement & parsing
5055
return textFrame:GetHeight()
5156
end
5257

53-
function addon.API.Util:FindString(text, stringToSearch) return text and stringToSearch and text:match(stringToSearch) ~= nil or false end
58+
function addon.API.Util:FindString(text, stringToSearch)
59+
if addon.API.Util:IsSecretValue(text) or addon.API.Util:IsSecretValue(stringToSearch) then return false end
60+
local found = text and stringToSearch and string.match(text, stringToSearch)
61+
return found and true or false
62+
end
63+
64+
function addon.API.Util:HasVisibleText(text)
65+
if addon.API.Util:IsSecretValue(text) then return true end
66+
local match = type(text) == "string" and string.match(text, "%S")
67+
return match and true or false
68+
end
69+
70+
function addon.API.Util:AreValuesEqual(valueA, valueB)
71+
if type(valueA) == "nil" or type(valueB) == "nil" then
72+
return type(valueA) == type(valueB)
73+
end
74+
75+
local isCompared, isEqual = pcall(function()
76+
return valueA == valueB
77+
end)
78+
79+
return isCompared and isEqual or false
80+
end
81+
82+
function addon.API.Util:GetInteractionUnitToken()
83+
if UnitExists("npc") then return "npc" end
84+
if UnitExists("questnpc") then return "questnpc" end
85+
if addon.API.Main:IsNPCGossip() then return "npc" end
86+
if addon.API.Main:IsNPCQuest() then return "questnpc" end
87+
return nil
88+
end
89+
90+
function addon.API.Util:IsStaticInteractionTarget()
91+
return addon.API.Main:IsNPCQuestOrGossip() and not UnitExists("npc") and not UnitExists("questnpc")
92+
end
5493

5594
function addon.API.Util:GetCharacterStartIndex(str, index)
95+
if addon.API.Util:IsSecretValue(str) then return nil end
5696
local i, charCount = 1, 0
5797
while i <= #str do
58-
local byte = str:byte(i)
98+
local byte = string.byte(str, i)
5999
if byte >= 0 and byte <= 127 then
60100
charCount = charCount + 1
61101
if charCount == index then return i end
@@ -82,58 +122,105 @@ do -- String measurement & parsing
82122
function addon.API.Util:GetCharacterEndIndex(str, index)
83123
local start = addon.API.Util:GetCharacterStartIndex(str, index)
84124
if not start then return nil end
85-
local byte = str:byte(start)
125+
local byte = string.byte(str, start)
86126
if byte <= 127 then return start end
87127
if byte <= 223 then return start + 1 end
88128
if byte <= 239 then return start + 2 end
89129
if byte <= 247 then return start + 3 end
90130
end
91131

92132
function addon.API.Util:GetSubstring(str, A, B)
133+
if addon.API.Util:IsSecretValue(str) then return "" end
93134
local startIndex = addon.API.Util:GetCharacterStartIndex(str, A)
94135
local endIndex = addon.API.Util:GetCharacterEndIndex(str, B)
95-
return startIndex and endIndex and str:sub(startIndex, endIndex) or ""
136+
return startIndex and endIndex and string.sub(str, startIndex, endIndex) or ""
96137
end
97138

98139
function addon.API.Util:RemoveAtlasMarkup(str, removeSpace)
140+
if addon.API.Util:IsSecretValue(str) then return "" end
99141
str = str or ""
100-
return removeSpace and str:gsub("(|A.-|a )", ""):gsub("(|H.-|h )", "") or str:gsub("(|A.-|a)", ""):gsub("(|H.-|h)", "")
142+
if removeSpace then
143+
str = string.gsub(str, "(|A.-|a )", "")
144+
return string.gsub(str, "(|H.-|h )", "")
145+
end
146+
147+
str = string.gsub(str, "(|A.-|a)", "")
148+
return string.gsub(str, "(|H.-|h)", "")
101149
end
102150
end
103151

104152
do -- Text formatting
105-
function addon.API.Util:StripColorCodes(text) return text and text:gsub("|cff%x%x%x%x%x%x%x%x", ""):gsub("|r", "") or "" end
153+
function addon.API.Util:IsSecretValue(value)
154+
if type(issecretvalue) ~= "function" then return false end
155+
156+
local checked, isSecret = pcall(issecretvalue, value)
157+
if not checked or not isSecret then return false end
158+
159+
if type(canaccessvalue) ~= "function" then return true end
160+
161+
local accessChecked, canAccess = pcall(canaccessvalue, value)
162+
return not accessChecked or not canAccess
163+
end
164+
165+
function addon.API.Util:GetValueOrFallback(value, fallback)
166+
if addon.API.Util:IsSecretValue(value) then return value end
167+
if value == nil then return fallback end
168+
return value
169+
end
170+
171+
function addon.API.Util:GetDisplayValueOrFallback(value, fallback)
172+
if addon.API.Util:IsSecretValue(value) then return fallback end
173+
if value == nil then return fallback end
174+
return value
175+
end
176+
177+
function addon.API.Util:GetFirstValue(valueA, valueB)
178+
if addon.API.Util:IsSecretValue(valueA) then return valueA end
179+
if valueA ~= nil then return valueA end
180+
return valueB
181+
end
182+
183+
function addon.API.Util:StripColorCodes(text)
184+
if addon.API.Util:IsSecretValue(text) then return "" end
185+
if type(text) ~= "string" then return "" end
186+
text = string.gsub(text, "|cff%x%x%x%x%x%x%x%x", "")
187+
return string.gsub(text, "|r", "")
188+
end
106189

107190
function addon.API.Util:GetHexColor(r, g, b)
108191
r, g, b = math.floor(r * 255), math.floor(g * 255), math.floor(b * 255)
109192
return string.format("%02x%02x%02x", r, g, b)
110193
end
111194

112195
function addon.API.Util:SetHexColorFromModifier(hexColor, factor)
113-
local color = hexColor:match("([0-9A-Fa-f]+)")
196+
local color = string.match(hexColor, "([0-9A-Fa-f]+)")
114197
if not color then return hexColor end
115-
local r, g, b = tonumber(color:sub(1, 2), 16), tonumber(color:sub(3, 4), 16), tonumber(color:sub(5, 6), 16)
198+
local r = tonumber(string.sub(color, 1, 2), 16)
199+
local g = tonumber(string.sub(color, 3, 4), 16)
200+
local b = tonumber(string.sub(color, 5, 6), 16)
116201
r, g, b = math.max(0, math.floor(r * factor)), math.max(0, math.floor(g * factor)), math.max(0, math.floor(b * factor))
117202
return string.format("%02x%02x%02x", r, g, b)
118203
end
119204

120205
function addon.API.Util:SetHexColorFromModifierWithBase(hexColor, factor, baseColor)
121-
local color = hexColor:match("([0-9A-Fa-f]+)")
206+
local color = string.match(hexColor, "([0-9A-Fa-f]+)")
122207
if not color then return hexColor end
123-
local r, g, b = tonumber(color:sub(1, 2), 16) or 0, tonumber(color:sub(3, 4), 16) or 0, tonumber(color:sub(5, 6), 16) or 0
124-
local baseR = tonumber(baseColor:sub(1, 2), 16) or 0
125-
local baseG = tonumber(baseColor:sub(3, 4), 16) or 0
126-
local baseB = tonumber(baseColor:sub(5, 6), 16) or 0
208+
local r = tonumber(string.sub(color, 1, 2), 16) or 0
209+
local g = tonumber(string.sub(color, 3, 4), 16) or 0
210+
local b = tonumber(string.sub(color, 5, 6), 16) or 0
211+
local baseR = tonumber(string.sub(baseColor, 1, 2), 16) or 0
212+
local baseG = tonumber(string.sub(baseColor, 3, 4), 16) or 0
213+
local baseB = tonumber(string.sub(baseColor, 5, 6), 16) or 0
127214
r = math.min(255, math.floor(r * factor + baseR * (1 - factor)))
128215
g = math.min(255, math.floor(g * factor + baseG * (1 - factor)))
129216
b = math.min(255, math.floor(b * factor + baseB * (1 - factor)))
130217
return string.format("%02x%02x%02x", math.max(0, r), math.max(0, g), math.max(0, b))
131218
end
132219

133220
function addon.API.Util:GetRGBFromHexColor(hexColor)
134-
local r = tonumber(hexColor:sub(1, 2), 16) or 0
135-
local g = tonumber(hexColor:sub(3, 4), 16) or 0
136-
local b = tonumber(hexColor:sub(5, 6), 16) or 0
221+
local r = tonumber(string.sub(hexColor, 1, 2), 16) or 0
222+
local g = tonumber(string.sub(hexColor, 3, 4), 16) or 0
223+
local b = tonumber(string.sub(hexColor, 5, 6), 16) or 0
137224
return { r = r / 255, g = g / 255, b = b / 255 }
138225
end
139226

@@ -148,26 +235,31 @@ do -- Text formatting
148235
end
149236

150237
function addon.API.Util:GetUnformattedText(text)
151-
if not text or text == "" then return "" end
152-
text = text:gsub("|c%x%x%x%x%x%x%x%x(.-)|r", "%1"):gsub("\124cn.-:", "")
153-
return text:gsub("|H(.-)|h(.-)|h", "%2")
238+
if addon.API.Util:IsSecretValue(text) then return "" end
239+
if type(text) ~= "string" then return "" end
240+
text = string.gsub(text, "|c%x%x%x%x%x%x%x%x(.-)|r", "%1")
241+
text = string.gsub(text, "\124cn.-:", "")
242+
return string.gsub(text, "|H(.-)|h(.-)|h", "%2")
154243
end
155244

156245
function addon.API.Util:GetImportantFormattedText(text)
157-
if not text or text == "" then return "" end
158-
return text:gsub("|cff000000", ""):gsub("|cffFFFFFF", "")
246+
if addon.API.Util:IsSecretValue(text) then return "" end
247+
if type(text) ~= "string" then return "" end
248+
text = string.gsub(text, "|cff000000", "")
249+
return string.gsub(text, "|cffFFFFFF", "")
159250
end
160251

161252
function addon.API.Util:SetUnformattedText(fontString)
162253
if fontString.IsObjectType and fontString:IsObjectType("FontString") then fontString:SetText(addon.API.Util:GetUnformattedText(fontString:GetText())) end
163254
end
164255

165256
function addon.API.Util:ParseNumberFromString(str)
166-
str = str:gsub("|c%x%x%x%x%x%x%x%x(.-)|r", "%1")
167-
local numberString = str:match("%-?%d[%d,]*")
257+
if addon.API.Util:IsSecretValue(str) then return nil, nil end
258+
str = string.gsub(str, "|c%x%x%x%x%x%x%x%x(.-)|r", "%1")
259+
local numberString = string.match(str, "%-?%d[%d,]*")
168260
if not numberString then return nil, nil end
169-
local sign = str:find("%-") and "-" or "+"
170-
numberString = numberString:gsub("[,+%-]", "")
261+
local sign = string.find(str, "%-") and "-" or "+"
262+
numberString = string.gsub(numberString, "[,+%-]", "")
171263
return tonumber(numberString), sign
172264
end
173265
end
@@ -223,12 +315,35 @@ end
223315
do -- Table & list helpers
224316
function addon.API.Util:FindItemInInventory(itemName)
225317
if not itemName then return nil, nil end
318+
319+
local isItemNameLowered, loweredItemName = pcall(function()
320+
return string.lower(itemName)
321+
end)
322+
323+
if not isItemNameLowered then
324+
return nil, nil
325+
end
326+
226327
for bag = 0, 4 do
227328
for slot = 1, C_Container.GetContainerNumSlots(bag) do
228329
local itemLink = C_Container.GetContainerItemLink(bag, slot)
229330
if itemLink then
230331
local itemNameInBag = C_Item.GetItemInfo(itemLink)
231-
if itemNameInBag and itemNameInBag:lower() == itemName:lower() then return C_Container.GetContainerItemID(bag, slot) or nil, itemLink end
332+
if itemNameInBag then
333+
local isBagItemNameLowered, loweredBagItemName = pcall(function()
334+
return string.lower(itemNameInBag)
335+
end)
336+
337+
if isBagItemNameLowered then
338+
local isMatchCompared, isMatch = pcall(function()
339+
return loweredBagItemName == loweredItemName
340+
end)
341+
342+
if isMatchCompared and isMatch then
343+
return C_Container.GetContainerItemID(bag, slot) or nil, itemLink
344+
end
345+
end
346+
end
232347
end
233348
end
234349
end
@@ -277,8 +392,8 @@ do -- Table & list helpers
277392

278393
function addon.API.Util:SortListByAlphabeticalOrder(list, subVariableList, descending)
279394
table.sort(list, function(a, b)
280-
local subA = addon.API.Util:GetSubVariableFromList(a, subVariableList):lower()
281-
local subB = addon.API.Util:GetSubVariableFromList(b, subVariableList):lower()
395+
local subA = string.lower(addon.API.Util:GetSubVariableFromList(a, subVariableList))
396+
local subB = string.lower(addon.API.Util:GetSubVariableFromList(b, subVariableList))
282397
return descending and subA > subB or subA < subB
283398
end)
284399
return list
@@ -291,13 +406,13 @@ do -- Table & list helpers
291406
table.insert(filteredList, entry)
292407
elseif roughMatch then
293408
local subValue = addon.API.Util:GetSubVariableFromList(entry, subVariableList)
294-
local lhs = caseSensitive ~= false and tostring(subValue) or tostring(subValue):lower()
295-
local rhs = caseSensitive ~= false and tostring(value) or tostring(value):lower()
409+
local lhs = caseSensitive ~= false and tostring(subValue) or string.lower(tostring(subValue))
410+
local rhs = caseSensitive ~= false and tostring(value) or string.lower(tostring(value))
296411
if addon.API.Util:FindString(lhs, rhs) then table.insert(filteredList, entry) end
297412
else
298413
local subValue = addon.API.Util:GetSubVariableFromList(entry, subVariableList)
299-
local lhs = caseSensitive ~= false and tostring(subValue) or tostring(subValue):lower()
300-
local rhs = caseSensitive ~= false and tostring(value) or tostring(value):lower()
414+
local lhs = caseSensitive ~= false and tostring(subValue) or string.lower(tostring(subValue))
415+
local rhs = caseSensitive ~= false and tostring(value) or string.lower(tostring(value))
301416
if lhs == rhs then table.insert(filteredList, entry) end
302417
end
303418
end
@@ -363,7 +478,7 @@ do -- General helpers
363478
local hash, chars = "", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
364479
for i = 1, 16 do
365480
local rand = math.random(1, #chars)
366-
hash = hash .. chars:sub(rand, rand)
481+
hash = hash .. string.sub(chars, rand, rand)
367482
end
368483
return hash
369484
end
@@ -375,7 +490,7 @@ end
375490

376491
do -- Inline icons
377492
function addon.API.Util:InlineIcon(path, height, width, horizontalOffset, verticalOffset, type) return type == "Atlas" and CreateAtlasMarkup(path, width, height, horizontalOffset, verticalOffset) or "|T" .. path .. ":" .. height .. ":" .. width .. ":" .. horizontalOffset .. ":" .. verticalOffset .. "|t" end
378-
function addon.API.Util:IconOffset(iconString, newXOffset, newYOffset) return iconString:gsub(":(%d+):(%d+)|a", ":" .. newXOffset .. ":" .. newYOffset .. "|a") end
493+
function addon.API.Util:IconOffset(iconString, newXOffset, newYOffset) return string.gsub(iconString, ":(%d+):(%d+)|a", ":" .. newXOffset .. ":" .. newYOffset .. "|a") end
379494
end
380495

381496
do -- Frame helpers

0 commit comments

Comments
 (0)