This repository has been archived by the owner on Jan 16, 2021. It is now read-only.
forked from HgAlexx/Buffet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utility.lua
198 lines (174 loc) · 5.16 KB
/
Utility.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
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
local _, ns = ...
-- Local namespace
local Utility = {}
-- Localize functions
local string_match = string.match
local string_find = string.find
-- Parameters
do
Utility.DebugStatus = false
Utility.buffetTooltip = nil
Utility.Mode = 1
Utility.IsClassic = false
--Utility.IsTBC = false
Utility.IsRetail = false
local _, _, _, interfaceVersion = GetBuildInfo()
if interfaceVersion >= 10000 and interfaceVersion < 20000 then
Utility.IsClassic = true
--elseif interfaceVersion >= 20000 and interfaceVersion < 30000 then
-- Utility.IsTBC = true
elseif interfaceVersion >= 90000 then
Utility.IsRetail = true
end
end
function Utility.GetTime()
return (debugprofilestop() / 1000)
end
function Utility.Print(...)
if Utility.Mode == 2 then
print("|cFF33FF99Buffet|r:", ...)
else
DEFAULT_CHAT_FRAME:AddMessage(string.join(" ", "|cFF33FF99Buffet|r:", ...))
end
end
function Utility.Debug(...)
--@debug@
if not Utility.DebugStatus then
return
end
if Utility.Mode == 2 then
print("|cFF33BB99Buffet|r:", ...)
else
local arg = {...}
local t = ""
for i, v in ipairs(arg) do
if type(v) == "table" then
for k, w in pairs(v) do
t = t .. ", " .. k .. "=" .. tostring(w)
end
else
t = t .. " " .. tostring(v)
end
end
DEFAULT_CHAT_FRAME:AddMessage("|cFF33BB99Buffet|r:" .. t)
end
--@end-debug@
end
function Utility.BoolToStr(value)
if value then
return "Yes"
end
return "No"
end
function Utility.Trim(s)
return string_match(s,'^()%s*$') and '' or string_match(s,'^%s*(.*%S)')
end
function Utility.StringContains(string, needle)
if string and needle then
local found = string_find(string, needle, 1, true)
if found == nil then
return false
end
return true
end
return false
end
function Utility.TableCount(table)
local c = 0
if table then
for _, v in pairs(table) do
if v then
c = c + 1
end
end
end
return c
end
function Utility.GetTooltip()
local tooltip = Utility.buffetTooltip or CreateFrame("GameToolTip", "buffetTooltip", nil, "GameTooltipTemplate")
tooltip:SetOwner(WorldFrame, "ANCHOR_NONE")
tooltip:ClearLines()
return tooltip
end
function Utility.IsPlayerInInstanceId(ids)
local _,_,_,_,_,_,_,instanceId = GetInstanceInfo()
if instanceId then
for _,v in pairs(ids) do
if v == instanceId then
return true
end
end
end
return false
end
function Utility.IsPlayerInInstanceType(types)
local _,instanceType, diffId = GetInstanceInfo()
instanceType = instanceType or "none"
for _,v in pairs(types) do
if (v == "none" and diffId == 0 and instanceType ~= "pvp" and instanceType ~= "arena") then
return true
end
if (v == instanceType) then
return true
end
end
return false
end
function Utility.IsPlayerInMapId(ids)
local uiMapId = C_Map.GetBestMapForUnit("player");
if uiMapId then
repeat
for _,v in pairs(ids) do
if v == uiMapId then
return true
end
end
local mapInfo = C_Map.GetMapInfo(uiMapId);
uiMapId = mapInfo and mapInfo.parentMapID or 0;
until uiMapId == 0;
end
return false
end
function Utility.IsPlayerInSubZoneName(names)
local currentSubZone = string.lower(GetSubZoneText())
if currentSubZone ~= "" then
local babbleSubZone = LibStub("LibBabble-SubZone-3.0"):GetUnstrictLookupTable();
for k,v in pairs(names) do
local subZone = babbleSubZone[v] -- get locale subzone name from LibBabble
if subZone and (subZone:lower() == currentSubZone) then
return true
end
end
end
return false
end
function Utility.ShowPlayerZoneInfo()
local uiMapId = C_Map.GetBestMapForUnit("player");
if uiMapId then
repeat
Utility.Debug("uiMapId=" .. uiMapId)
local mapInfo = C_Map.GetMapInfo(uiMapId);
uiMapId = mapInfo and mapInfo.parentMapID or 0;
until uiMapId == 0;
end
local _,instanceType,diffId,_,_,_,_,instanceId = GetInstanceInfo()
instanceType = instanceType or "none"
if instanceId then
Utility.Debug("instanceId=" .. instanceId)
Utility.Debug("instanceType=" .. instanceType)
Utility.Debug("diffId=" .. diffId)
end
local currentSubZone = string.lower(GetSubZoneText())
if currentSubZone ~= "" then
local babbleSubZone = LibStub("LibBabble-SubZone-3.0"):GetUnstrictLookupTable();
for k, v in pairs(babbleSubZone) do
local subZone = v -- get locale subzone name from LibBabble
if subZone and (subZone:lower() == currentSubZone) then
Utility.Debug("currentSubZone=" .. currentSubZone .. ", EN=" .. k)
return
end
end
end
end
-- Export
ns.Utility = Utility