forked from typicalzergling/vendor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.lua
237 lines (211 loc) · 8.29 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
-- This is exclusively for the debug options panel and Debug-specific commands that do not appear in a normal build.
-- This entire file is excluded from packaging and it is not localized intentionally.
local AddonName, Addon = ...
local L = Addon:GetLocale()
-- Sets up all the console commands for debug functions in this file.
function Addon:SetupDebugConsoleCommands()
self:AddConsoleCommand("debug", "Toggle Debug. No args prints channels. Specify channel to toggle.",
function(channel)
if not channel then
Addon:PrintDebugChannels()
else
Addon:ToggleDebug(channel)
end
end)
self:AddConsoleCommand("disabledebug", "Turn off all debug channels.", "DisableAllDebugChannels")
self:AddConsoleCommand("link", "Dump hyperlink information", "DumpLink_Cmd")
self:AddConsoleCommand("simulate", "Simulates deleting and selling items, without actually doing it.", "ToggleSimulate_Cmd")
self:AddConsoleCommand("cache", "Clears all caches.", "ClearCache_Cmd")
self:AddConsoleCommand("profile", "Profile management.", "Profile_Cmd")
-- Register debug channels for the addon. Register must be done after addon loaded.
Addon:RegisterDebugChannel("autosell")
Addon:RegisterDebugChannel("blocklists")
Addon:RegisterDebugChannel("config")
Addon:RegisterDebugChannel("destroy")
Addon:RegisterDebugChannel("evaluate")
Addon:RegisterDebugChannel("events")
Addon:RegisterDebugChannel("extensions")
Addon:RegisterDebugChannel("history")
Addon:RegisterDebugChannel("historystats")
Addon:RegisterDebugChannel("itemerrors")
Addon:RegisterDebugChannel("items")
Addon:RegisterDebugChannel("itemcache")
Addon:RegisterDebugChannel("itemproperties")
Addon:RegisterDebugChannel("ldbstatus")
Addon:RegisterDebugChannel("libdatabroker")
Addon:RegisterDebugChannel("minimapbutton")
Addon:RegisterDebugChannel("profile")
Addon:RegisterDebugChannel("refresh")
Addon:RegisterDebugChannel("rules")
Addon:RegisterDebugChannel("rulesdialog")
Addon:RegisterDebugChannel("rulesengine")
Addon:RegisterDebugChannel("resultcache")
Addon:RegisterDebugChannel("test")
Addon:RegisterDebugChannel("threads")
Addon:RegisterDebugChannel("tooltip")
Addon:RegisterDebugChannel("tooltiperrors")
end
-- Debug Commands
function Addon:DumpLink_Cmd(arg)
self:Print("Link: "..tostring(arg))
self:Print("Raw: "..gsub(arg, "\124", "\124\124"))
self:Print("ItemString: "..tostring(self:GetLinkFromString(arg)))
local props = self:GetLinkPropertiesFromString(arg)
for i, v in pairs(props) do
self:Print("["..tostring(i).."] "..tostring(v))
end
self:Print("ItemInfo:")
local itemInfo = {GetItemInfo(tostring(arg))}
for i, v in pairs(itemInfo) do
self:Print("["..tostring(i).."] "..tostring(v))
end
end
function Addon:ToggleSimulate_Cmd()
Addon:SetDebugSetting("simulate", not Addon:GetDebugSetting("simulate"))
Addon:Print("Simulate set to %s", tostring(Addon:GetDebugSetting("simulate")))
end
function Addon:ClearCache_Cmd()
Addon:ClearItemResultCache()
Addon:Print("Item cache and result cache cleared.")
end
function Addon:Profile_Cmd(cmd, arg1, arg2)
if cmd then
cmd = string.lower(cmd)
end
if not cmd then
local profiles = Addon:GetProfileList()
local active = Addon:GetProfile()
Addon:Print("All available profiles:")
for _, profile in pairs(profiles) do
Addon:Print(" %s [%s]", tostring(profile:GetName()), tostring(profile:GetId()))
end
Addon:Print("Active profile: %s", tostring(active:GetName()))
elseif cmd == "get" then
local active = Addon:GetProfile()
Addon:Print("Active profile: %s", tostring(active:GetName()))
elseif cmd == "set" and type(arg1) == "string" then
if not Addon:ProfileExists(arg1) then
Addon:Print("Profile '%s' does not exist.", arg1)
return
end
if Addon:SetProfile(arg1) then
Addon:Print("Active profile set to '%s'", arg1)
else
Addon:Print("Failed setting active profile.")
end
elseif cmd == "copy" and type(arg1) == "string" and type(arg2) == "string" then
if not Addon:ProfileExists(arg1) then
Addon:Print("Profile '%s' does not exist.", arg1)
return
end
if Addon:ProfileExists(arg2) then
Addon:Print("Profile '%s' already exists.", arg2)
return
end
if Addon:CopyProfile(arg1, arg2) then
Addon:Print("Profile '%s' copied as profile '%s'", arg1, arg2)
else
Addon:Print("Failed copying the profile.")
end
elseif cmd == "delete" and type(arg1) == "string" then
if not Addon:ProfileExists(arg1) then
Addon:Print("Profile '%s' does not exist.", arg1)
return
end
if Addon:DeleteProfile(arg1) then
Addon:Print("Profile '%s' has been deleted.", arg1)
else
Addon:Print("Failed deleting the profile.")
end
elseif cmd == "create" and type(arg1) == "string" then
if Addon:ProfileExists(arg1) then
Addon:Print("Profile '%s' already exists.", arg1)
return
end
if Addon:NewProfile(arg1) then
Addon:Print("Profile '%s' has been created and set to the active profile.", arg1)
else
Addon:Print("Failed creating the profile.")
end
elseif cmd == "rename" and type(arg1) == "string" and type(arg2) == "string" then
if not Addon:ProfileExists(arg1) then
Addon:Print("Profile '%s' does not exist.", arg1)
return
end
if Addon:RenameProfile(arg1, arg2) then
Addon:Print("Profile '%s' has been renamed to '%s'.", arg1, arg2)
else
Addon:Print("Failed renaming the profile.")
end
else
Addon:Print("profile usage: <none> | get | set | create | copy | delete | rename")
end
end
-- Beyond this point are debug related functions that are not packaged.
function Addon:DumpTooltipItemProperties()
local props = self:GetItemPropertiesFromTooltip()
if not props then return end
self:Print("Properties for "..props["Link"])
-- Print non-derived properties first.
for i, v in Addon.orderedPairs(props) do
if not string.find(i, "^Is") then
local val = v
if type(v) == "table" then
val = "{"..table.concat(v, ", ").."}"
end
self:Print(" [%s] %s", tostring(i), tostring(val))
end
end
-- Print all the derived properties ("Is*") together.
for i, v in Addon.orderedPairs(props) do
if string.find(i, "^Is") then
self:Print(" ["..tostring(i).."] "..tostring(v))
end
end
end
function Addon:DumpItemPropertiesFromTooltip()
Addon:DumpTooltipItemProperties()
end
Addon:MakePublic(
"DumpItemPropertiesFromTooltip",
function () Addon:DumpItemPropertiesFromTooltip() end,
"DumpItemPropertiesFromTooltip",
"Dumps properties for item over toolip.")
-- Sorted Pairs from Lua-Users.org. We use this for pretty-printing tables for debugging purposes.
function Addon.__genOrderedIndex( t )
local orderedIndex = {}
for key in pairs(t) do
table.insert( orderedIndex, key )
end
table.sort( orderedIndex )
return orderedIndex
end
function Addon.orderedNext(t, state)
-- Equivalent of the next function, but returns the keys in the alphabetic
-- order. We use a temporary ordered key table that is stored in the
-- table being iterated.
local key = nil
if state == nil then
-- the first time, generate the index
t.__orderedIndex = Addon.__genOrderedIndex( t )
key = t.__orderedIndex[1]
else
-- fetch the next value
for i = 1,table.getn(t.__orderedIndex) do
if t.__orderedIndex[i] == state then
key = t.__orderedIndex[i+1]
end
end
end
if key then
return key, t[key]
end
-- no more value to return, cleanup
t.__orderedIndex = nil
return
end
function Addon.orderedPairs(t)
-- Equivalent of the pairs() function on tables. Allows to iterate
-- in order
return Addon.orderedNext, t, nil
end