forked from manavortex/FurnitureCatalogue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFurCUtil.lua
89 lines (79 loc) · 2.03 KB
/
FurCUtil.lua
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
-- TABLE UTILS --
--- Merges Table2 into Table1, mutates Table1 inplace and replaces its values if they have the same key. Example: merge({a="1",b="3"},{b="2"}) => {a="1",b="2"}
--- @param t1 any
--- @param t2 any
--- @see ZO_CombineNonContiguousTables (for no entry replacement)
--- @return table
function FurC.MergeTable(t1, t2)
if nil == t2 and nil == t1 then
return {}
elseif nil == t2 then
return t1
elseif nil == t1 then
return t2
end
for k, v in pairs(t2) do
t1[k] = v
end
return t1
end
-- ruthlessly stolen from TextureIt
-- ToDo: ZO_TableOrderingFunction
--- @return table sortedTable
function FurC.SortTable(tTable, sortKey, SortOrderUp)
local keys = {}
for k in pairs(tTable) do
table.insert(keys, k)
end
table.sort(keys, function(a, b)
if nil == tTable[a] or nil == tTable[b] then
elseif nil == tTable[a][sortKey] then
return false
elseif nil == tTable[b][sortKey] then
return true
else
if SortOrderUp then
return tTable[a][sortKey] > tTable[b][sortKey]
else
return tTable[a][sortKey] < tTable[b][sortKey]
end
end
return tTable
end)
local ret = {}
local scannedLinks = {}
local itemLink, entry
for _, k in ipairs(keys) do
entry = tTable[k]
itemLink = entry["itemLink"]
ingredients = entry["ingredients"]
local index = scannedLinks[itemLink] or k
table.insert(ret, entry)
end
return ret
end
-- STRING UTILS --
function FurC.capitalise(str)
str = str:gsub("^(%l)(%w*)", function(a, b)
return string.upper(a) .. b
end)
return str
end
-- ToDo: make flexible
function FurC.stripColor(aString)
if nil == aString then
return ""
end
return aString:gsub("|%l%l%d%d%d%d%d", ""):gsub("|%l%l%d%l%l%d%d", ""):gsub("|c25C31E", ""):gsub("", "")
end
-- ToDo: remove/change ret param
function FurC.colourise(txt, colourCode, ret)
txt = tostring(txt)
if txt:find("%d000$") then
txt = txt:gsub("000$", "k")
end
if ret then
return txt
end
return string.format("|c%s%s|r", colourCode, txt)
end