-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathutility.lua
More file actions
87 lines (80 loc) · 2.53 KB
/
utility.lua
File metadata and controls
87 lines (80 loc) · 2.53 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
local AddonName, Addon = ...
function Addon:Round(number, decimals)
return (("%%.%df"):format(decimals)):format(number)
end
function Addon:StartDragging(self, elem)
self:StartMoving()
self.isMoving = true
end
function Addon:StopDragging(self, elem)
self:StopMovingOrSizing()
self.isMoving = false
end
function Addon:PrintObject(data, prefix, toText)
local text = ''
if prefix == nil then
prefix = ''
end
for key,value in pairs(data) do
if value == nil then
text = text .. prefix .. key .. " = nil\n"
elseif type(value) == 'table' then
local subText = Addon:PrintObject(value, prefix .. key .. '.', toText)
if subText == nil then
subText = ' ?? '
end
text = text .. subText .. "\n"
elseif type(value) == 'boolean' then
if value then
text = text .. prefix .. key .. " = true\n"
else
text = text .. prefix .. key .. " = false\n"
end
else
text = text .. prefix .. key .. " = " .. value .. "\n"
end
end
if toText then
return text
else
print(text)
end
end
function Addon:CopyObject(template, filled)
if template == nil then
return nil
end
local result = {}
for key,value in pairs(template) do
if type(value) == 'table' then
if filled ~= nil and type(filled[key]) == 'table' then
result[key] = Addon:CopyObject(value, filled[key])
else
result[key] = Addon:CopyObject(value)
end
else
if filled and filled[key] ~= nil and type(filled[key]) ~= 'table' then
result[key] = filled[key]
else
result[key] = value
end
end
end
return result
end
function Addon:PrepareName(playerName)
local playerName, realm, region = strsplit('-', playerName)
if realm then
playerName = playerName .. "-" .. realm
end
return playerName
end
function Addon:SetPortraitToTexture(frame, texture)
frame.Portrait:SetTexture(texture)
if not frame.portraitMask then
frame.portraitMask = frame:CreateMaskTexture()
frame.portraitMask:SetTexture("Interface\\CharacterFrame\\TempPortraitAlphaMask")
frame.portraitMask:SetAllPoints(frame.Portrait)
frame.Portrait:AddMaskTexture(frame.portraitMask)
end
end