Repository navigation
Expand file tree
/
Copy pathKit.lua
More file actions
248 lines (217 loc) · 5.6 KB
/
Copy pathKit.lua
File metadata and controls
248 lines (217 loc) · 5.6 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
--| Purpose: General toolkit functionality
--| Authors: Atriace@Gmail.com
--| Website: massive.atriace.com
----------------------------------------------------------------------------------
local parent, db = ...
DEFAULT_CHAT_FRAME:AddMessage("Massive: Kit Loaded", 1, 0, 0)
function db.get(stringPath)
-- Resolves a dot.notation to the nested object it was refering to.
local path = db.split(stringPath, ".")
local objName = table.remove(path, 1)
local obj = _G[objName]
if (obj ~= nil) then
for k,v in pairs(path) do
local matchFound = false
if (db.isFrame(obj)) then
--db.print(objName .. " is a frame. Searching for " .. v .. " inside it.")
local child = db.getChildByName(obj, v)
if (child ~= nil) then
--db.print("Found " .. v .. " inside " .. objName, 4)
objName = v
obj = child
matchFound = true
else
--db.print(v .. " is not a child region of " .. objName, 3)
end
end
if (matchFound == false) then
--db.print(objName .. " is a " .. type(obj) .. ". Searching for " .. v .. " inside it.")
if obj[v] then
--db.print("Found " .. v .. " inside " .. objName, 4)
objName = v
obj = obj[v]
else
--db.print(v .. " is not a property of " .. objName, 3)
end
end
end
return obj
else
db.print(objName .. " is not a global property.", 3)
return nil
end
end
function db.getChildByName(f, name)
local list = {f:GetChildren()}
local obj = nil
for k,v in pairs(list) do
if (v:GetName() == name) then
obj = v
break
end
end
return obj
end
function db.isFrame(obj)
if (type(obj) == "table") then
if obj.GetName then
db.print(tostring(obj) .. " is a frame called " .. obj:GetName())
return true
else
db.print(tostring(obj) .. " is not a frame")
return false
end
else
db.print(tostring(obj) .. " is not a table")
return false
end
end
-----------------------
--| Table Functions |--
-----------------------
function db.TableSort(a, b)
if a < b then
return true
end
end
function db.length(T)
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
end
function db.clone(input, output)
-- Duplicates the values from input to output
-- Validate content
if (not input) then
db.print("input was null");
return
elseif (not output) then
db.print("output was null");
return
end
-- Iterate over the input object
for k, v in pairs(input) do
if (type(v) == "table") then
if (output[k] and type(output[k]) == "table") then
--db.print("Cloning table to existing " .. tostring(k))
output[k] = db.clone(v, output[k])
else
--db.print("Cloning to new table " .. tostring(k))
output[k] = db.clone(v, {})
end
else
--db.print("Cloning " .. tostring(k) .. " | " .. (tostring(output[k]) or "nil") .. " >> " .. (tostring(input[k]) or "nil"))
output[k] = input[k]
end
end
return output
end
function db.merge(input, output)
-- Copies any values from input into output that share the same key
-- Validate content
if (not input) then
db.print("input was null");
return
elseif (not output) then
db.print("output was null");
return
end
-- Iterate over the input object
for k, v in pairs(input) do
-- if the property is shared...
if (output[k]) then
-- ... and the value is another table
if (type(v) == "table" and type(output[k]) == "table") then
-- use the current object and merge the new values into it
output[k] = db.merge(v, output[k])
elseif (type(v) == "table") then
-- create a new object and clone the values into it
output[k] = db.clone(v, {})
else
-- Otherwise, just copy the value.
output[k] = input[k]
end
end
end
return output
end
function db.getKeyOrder(hash)
-- Returns an array with sorted key values.
local order = {}
for k,v in pairs(hash) do
table.insert(order, k)
end
db.alphanumsort(order)
return order
end
function db.alphanumsort(o)
local function padnum(d) return ("%03d%s"):format(#d, d) end
table.sort(o, function(a,b)
return tostring(a):gsub("%d+",padnum) < tostring(b):gsub("%d+",padnum) end)
return o
end
function db.type(item)
local msg = type(item)
if (msg == "table") then
if (item.IsForbidden and type(item.IsForbidden) == "function") then
--db.print("Checking: " .. type(item) .. type(rawget(item, 0)))
if (type(rawget(item, 0)) == "nil" or item:IsForbidden() == true ) then
msg = "forbidden"
else
msg = string.lower(item:GetObjectType())
end
end
end
return msg
end
------------------------
--| String Functions |--
------------------------
db.hue = {
["azure"] = "40acf6",
["blue"] = "2b74a6",
["green"] = "7af965",
["darkGreen"] = "339a22",
["orange"] = "fd9317",
["red"] = "ff2717",
["white"] = "FFFFFF",
["lightGrey"] = "d9d9d9",
["grey"] = "808080",
["darkGrey"] = "333333",
["black"] = "000000"
}
function db.color(string, color)
-- Returns text in the color chosen
return ("|c00" .. db.hue[color] .. string .. "|r")
end
function db.split(s, sep)
--db.print("Running split on '" .. s .. "' using '" .. sep .. "'")
local sep, fields = sep or ":", {}
local pattern = string.format("([^%s]+)", sep)
string.gsub(s, pattern, function(c) fields[#fields+1] = c end)
return fields
end
function db.join(arr, sep)
--db.print("Joining " .. #arr .. " with '" .. sep .. "'")
local s = arr[1]
if #arr > 1 then
for k, v in pairs(arr) do
if k > 1 then
s = s .. sep .. v
end
end
end
return s
end
function charPad(num, char)
-- Returns a string of num length of char type
if (num < 1) then num = 0 end
if char == nil then char = " " end
local i = 0
local txt = ""
while (i <= num) do
txt = txt .. char
i = i + 1
end
return txt
end