forked from NanMetal/WorldQuestTab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Debug.lua
301 lines (264 loc) · 9.79 KB
/
Debug.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
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
local addonName, addon = ...
local WQT = addon.WQT
local _L = addon.L
local _V = addon.variables
local WQT_Utils = addon.WQT_Utils
------------------------
-- DEBUGGING
------------------------
local _debugTable
if (addon.debug and LDHDebug) then
LDHDebug:Monitor(addonName)
end
function WQT:debugPrint(...)
if (addon.debug and LDHDebug) then
LDHDebug:Print(...)
end
end
local function AddIndentedDoubleLine(tooltip, a, b, level, color)
local indented = string.rep(" ", level) .. a
if (type(b) == "table" and b.GetRGBA) then
b = floor(b.r * 100) / 100 .. "/" .. floor(b.g * 100) / 100 .. "/" .. floor(b.b * 100) / 100
elseif (type(b) == "table" and b.GetXY) then
b = "{" .. floor(b.x * 100) / 100 .. " | " .. floor(b.y * 100) / 100 .. "}"
elseif (type(b) == "boolean") then
b = b and "true" or "false"
elseif (type(a) == "string" and a:find("Bits") and type(b) == "number" and b > 0) then
local bits = b
local o = ""
local index = 0
while (bits > 0) do
local rest = bits % 2
if (rest > 0) then
o = o .. (o == "" and "" or ", ") .. index
end
bits = (bits - rest) / 2
index = index + 1
end
b = string.format("%s (%s)", b, o)
elseif (b == nil) then
b = "nil"
end
tooltip:AddDoubleLine(indented, b, color.r, color.g, color.b, color.r, color.g, color.b)
end
function WQT:AddDebugToTooltip(tooltip, questInfo, level)
if (not addon.debug) then
return
end
level = level or 0
local color = LIGHTBLUE_FONT_COLOR
if (level == 0) then
AddIndentedDoubleLine(tooltip, "questInfo data:", "", 0, color)
end
-- First all non table values;
for key, value in pairs(questInfo) do
if ((type(value) ~= "table" or value.GetRGBA) and type(value) ~= "function") then
AddIndentedDoubleLine(tooltip, key, value, level + 1, color)
end
end
-- Actual tables
for key, value in pairs(questInfo) do
if (type(value) == "table" and not value.GetRGBA and key ~= "debug") then
AddIndentedDoubleLine(tooltip, key, "", level + 1, color)
self:AddDebugToTooltip(tooltip, value, level + 1)
end
end
if (level == 0 and questInfo.questID) then
color = GRAY_FONT_COLOR
AddIndentedDoubleLine(tooltip, "Through functions:", "", 0, color)
local title, factionId = C_TaskQuest.GetQuestInfoByQuestID(questInfo.questID)
AddIndentedDoubleLine(tooltip, "title", title, 1, color)
-- Time
local seconds, timeString, timeColor, timeStringShort = WQT_Utils:GetQuestTimeString(questInfo, true, true)
AddIndentedDoubleLine(tooltip, "time", "", 1, color)
AddIndentedDoubleLine(tooltip, "seconds", seconds, 2, color)
AddIndentedDoubleLine(tooltip, "timeString", timeString, 2, color)
AddIndentedDoubleLine(tooltip, "color", timeColor, 2, color)
AddIndentedDoubleLine(tooltip, "timeStringShort", timeStringShort, 2, color)
AddIndentedDoubleLine(tooltip, "isExpired", questInfo:IsExpired(), 2, color)
-- Faction
local factionInfo = WQT_Utils:GetFactionDataInternal(factionId)
AddIndentedDoubleLine(tooltip, "faction", "", 1, color)
AddIndentedDoubleLine(tooltip, "factionId", factionId, 2, color)
AddIndentedDoubleLine(tooltip, "name", factionInfo.name, 2, color)
AddIndentedDoubleLine(tooltip, "playerFaction", factionInfo.playerFaction, 2, color)
AddIndentedDoubleLine(tooltip, "texture", factionInfo.texture, 2, color)
AddIndentedDoubleLine(tooltip, "expansion", factionInfo.expansion, 2, color)
-- MapInfo
local mapInfo = WQT_Utils:GetMapInfoForQuest(questInfo.questID)
AddIndentedDoubleLine(tooltip, "mapInfo", "", 1, color)
AddIndentedDoubleLine(tooltip, "name", mapInfo.name, 2, color)
AddIndentedDoubleLine(tooltip, "mapID", mapInfo.mapID, 2, color)
AddIndentedDoubleLine(tooltip, "parentMapID", mapInfo.parentMapID, 2, color)
AddIndentedDoubleLine(tooltip, "mapType", mapInfo.mapType, 2, color)
end
end
function WQT:ShowDebugTooltipForQuest(questInfo, anchor)
if (not addon.debug) then
return
end
WQT_DebugTooltip:SetOwner(anchor, "ANCHOR_LEFT")
WQT_DebugTooltip:SetText("Debug Info")
self:AddDebugToTooltip(WQT_DebugTooltip, questInfo)
WQT_DebugTooltip:Show()
end
function WQT:HideDebugTooltip()
WQT_DebugTooltip:Hide()
end
------------------------
-- OUTPUT DUMP
------------------------
local URL_CURSEFORGE = "https://www.curseforge.com/wow/addons/worldquesttab/issues"
local URL_WOWI = "https://www.wowinterface.com/downloads/info25042-WorldQuestTab.html"
-- regionID, locale, textLocale, playerFaction, map, coords, addonVersion
local FORMAT_PLAYER = "%d;%s;%s;%s;%d;%s;%s\n"
local FORMAT_QUEST_HEADER = "Quests;%d;%d\nQuestId;Counted;Frequency;IsTask;IsBounty;IsHidden\n"
local FORMAT_QUEST = "%s%d;%s;%d;%s;%s;%s\n"
local FORMAT_WORLDQUEST_HEADER =
"World Quests;%d\nQuestId;MapId;PassedFilter;IsValid;AlwaysHide;IsDaily;IsAllyQuest;Seconds;RewardBits\n"
local FORMAT_WORLDQUEST = "%s%d;%d;%s;%s;%s;%s;%s;%d;%d\n"
-- output, name
local FORMAT_ADDON = "%s%s\n"
-- ouput, indentation, key, value
local FORMAT_TABLE_VALUE = "%s%s%s = %s\n"
local function bts(bool)
return bool and "Y" or "N"
end
local function GetQuestDump()
local removedQuests = {}
local counted, limit = WQT_Utils:GetQuestLogInfo(removedQuests)
local output = FORMAT_QUEST_HEADER:format(counted, limit)
local numEntries = C_QuestLog.GetNumQuestLogEntries()
for index = 1, numEntries do
local info = C_QuestLog.GetInfo(index)
local counted = WQT_Utils:QuestCountsToCap(index)
if (not info.isHeader) then
output =
FORMAT_QUEST:format(
output,
info.questID,
bts(counted),
info.frequency,
bts(info.isTask),
bts(info.isBounty),
bts(info.isHidden)
)
end
end
return output
end
local function GetWorldQuestDump()
local mapID = WorldMapFrame:GetMapID() or 0
local output = FORMAT_WORLDQUEST_HEADER:format(mapID)
local list = WQT_WorldQuestFrame.dataProvider:GetIterativeList()
for k, questInfo in ipairs(list) do
local title = C_TaskQuest.GetQuestInfoByQuestID(questInfo.questID)
local mapInfo = WQT_Utils:GetMapInfoForQuest(questInfo.questID)
output =
FORMAT_WORLDQUEST:format(
output,
questInfo.questID,
mapInfo.mapID,
bts(questInfo.passedFilter),
bts(questInfo.isValid),
bts(questInfo.alwaysHide),
bts(questInfo.isDaily),
bts(questInfo.isAllyQuest),
questInfo.time.seconds,
questInfo.reward.typeBits
)
end
return output
end
local function GetPlayerDump()
local version = C_AddOns.GetAddOnMetadata(addonName, "version")
local map = C_Map.GetBestMapForUnit("player")
local coords = nil
if (map) then
local pos = C_Map.GetPlayerMapPosition(map, "player")
coords = string.format("%.2f,%.2f", pos.x, pos.y)
end
local output =
FORMAT_PLAYER:format(
GetCurrentRegion(),
GetLocale(),
C_CVar.GetCVar("textLocale"),
UnitFactionGroup("player"),
map,
coords,
version
)
return output
end
local function LoopTableValues(output, t, level)
local indented = string.rep(" ", level)
for k, v in pairs(t) do
if (type(v) ~= "table") then
output = FORMAT_TABLE_VALUE:format(output, indented, k, tostring(v))
end
end
for k, v in pairs(t) do
if (type(v) == "table") then
output = output .. indented .. k .. "\n"
output = LoopTableValues(output, v, level + 1)
end
end
return output
end
local function GetSettingsDump()
local output = "Settings\n"
output = LoopTableValues(output, WQT.settings, 0)
return output
end
local function GetAddonDump()
local output = "Addons\n"
for i = 1, GetNumAddOns() do
if (IsAddOnLoaded(i)) then
output = FORMAT_ADDON:format(output, GetAddOnInfo(i))
end
end
return output
end
local function GetOutputTypeFromString(s)
if (s == "s") then
return _V["DEBUG_OUTPUT_TYPE"].setting
elseif (s == "q") then
return _V["DEBUG_OUTPUT_TYPE"].quest
elseif (s == "wq") then
return _V["DEBUG_OUTPUT_TYPE"].worldQuest
elseif (s == "a") then
return _V["DEBUG_OUTPUT_TYPE"].addon
end
return _V["DEBUG_OUTPUT_TYPE"].invalid
end
WQT_DebugFrameMixin = {}
function WQT_DebugFrameMixin:OnLoad()
self.CurseURL:SetText(URL_CURSEFORGE)
self.WoWIURL:SetText(URL_WOWI)
end
function WQT_DebugFrameMixin:DumpDebug(input)
local outputType = input
if (type(outputType) == "string") then
outputType = GetOutputTypeFromString(input)
end
if (outputType == _V["DEBUG_OUTPUT_TYPE"].invalid) then
print("Usage: /wqt dump <type> where <type> is:")
print("s: Settings")
print("q: Normal quests")
print("wq: World Quests (current map)")
print("a: Enabled Add-ons")
return
end
local text = GetPlayerDump()
if (outputType == _V["DEBUG_OUTPUT_TYPE"].quest) then
text = text .. GetQuestDump()
elseif (outputType == _V["DEBUG_OUTPUT_TYPE"].worldQuest) then
text = text .. GetWorldQuestDump()
elseif (outputType == _V["DEBUG_OUTPUT_TYPE"].setting) then
text = text .. GetSettingsDump()
elseif (outputType == _V["DEBUG_OUTPUT_TYPE"].addon) then
text = text .. GetAddonDump()
end
self.DumpFrame.EditBox:SetText(text)
self:Show()
end