forked from Hydra9268/ZGESO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Debug.lua
136 lines (106 loc) · 3.45 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
local ZGV = _G.ZGV
-----------------------------------------
-- LOCAL REFERENCES
-----------------------------------------
local tinsert, type, ipairs = table.insert, type, ipairs
local print = ZGV.print
local L = ZGV.L
-----------------------------------------
-- LOCAL VARIABLES
-----------------------------------------
local debugcolor="|cff88dd"
local lastdate=0
local mscycle=0
local mscolors,mscolorsn={[0]="|cffcc00",[1]="|cffaa00"},2
local timecolor=mscolors[0]
local errorlog = ""
local blockedmsgs = {}
-----------------------------------------
-- LOCAL FUNCTIONS
-----------------------------------------
local flags = {}
-- Easy setting of flags
local function SetDebugFlags()
flags = ZGV.sv and ZGV.sv.profile and ZGV.sv.profile.debug_flags or flags
flags.quest = false
flags.parser = false
flags.viewer = false
flags.goal = false
end
-----------------------------------------
-- DEBUG
-----------------------------------------
function ZGV:Debug (msg,...)
local GetFrameTimeSeconds, GetGameTimeMilliseconds = _G.GetFrameTimeSeconds, _G.GetGameTimeMilliseconds
if not msg or type(msg)~="string" then error("Debug msg type error") end
SetDebugFlags()
local flagsmsg
while msg:sub(1,1)=="&" do
local flag,rest = msg:match("^&([a-zA-Z0-9_]+)%s+(.*)$")
if flag then
local flagdata = flags[flag]
if flagdata==false then return end -- otherwise assume it SET!
if type(flagdata)=="table" and flagdata.color then flag = "|c"..flagdata.color..flag.."|r" end
flagsmsg = (flagsmsg and (flagsmsg.." ") or "") .. "[" .. flag .. "]"
msg = rest
else
msg="?"..msg:sub(2) -- failsafe, cut the & off
end
end
if flagsmsg then msg = flagsmsg.." "..msg end
local formatted_msg = string.format(tostring(msg),...) :gsub("|r",debugcolor)
self.DebugI = (self.DebugI or 0) + 1
local t = GetFrameTimeSeconds()
local datestamp = ("%06.03f"):format(t%60)
if t~=lastdate then
mscycle=(mscycle+1)%mscolorsn
lastdate=t
timecolor=mscolors[mscycle]
end
local debugms = GetGameTimeMilliseconds() - t*1000
local message = ("|cffee77Z|r: %s%s+%03d|r |c00ddbb#%d: %s%s"):format(timecolor,datestamp,debugms,self.DebugI,debugcolor,formatted_msg)
if (not ZGV.blockdebug and self.sv and self.sv.profile and self.sv.profile.debug) or flags.forcedisplay or ZGV.DEV then
print(message)
else
tinsert(blockedmsgs,message)
end
self.Log:Add("%s",formatted_msg)
end
-- Used in coroutines because they can't print
function ZGV:BlockDebugOutput()
ZGV.blockdebug = true
end
function ZGV:UnBlockDebugOutput()
ZGV.blockdebug = nil
for msg in ipairs(blockedmsgs) do
print(msg)
end
blockedmsgs = {} -- TODO could wipe it instead. Meh
end
-----------------------------------------
-- PRINT
-----------------------------------------
function ZGV:Print(str,...)
str = string.format(tostring(str),...)
-- TODO
print(L['name']..": "..str)
end
-----------------------------------------
-- ERROR
-----------------------------------------
function ZGV:Error(str,...)
str = "|cff0000ERROR|r - "..str
self:Print(str,...)
self:Debug(str,...) -- Eh send it there too
errorlog = errorlog..str..'\n'
end
function ZGV:DumpErrorLog()
if #errorlog<=0 then return end
ZGV:Dump(errorlog)
end
-----------------------------------------
-- DUMP
-----------------------------------------
function ZGV:Dump(str,title)
self.BugReport:ShowDump(str,title)
end