vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --===========================================================================-- |
2 | ---------------------------- LootTracker by PNB ---------------------------- |
||
3 | --===========================================================================-- |
||
4 | -- LootTrackerOutput.lua |
||
5 | -- |
||
6 | -- Debug methods |
||
7 | --===========================================================================-- |
||
8 | |||
9 | ------------------------------------------------------------------------------ |
||
10 | -- Globals |
||
11 | -- These values are global, but not saved when the session ends. |
||
12 | ------------------------------------------------------------------------------ |
||
13 | |||
14 | LT_CurrentIndentString = ""; |
||
15 | LT_Indent = " "; |
||
16 | |||
17 | LT_WriteBuffer = ""; |
||
18 | LT_BufferCurrentIndent = ""; |
||
19 | |||
20 | |||
21 | ------------------------------------------------------------------------------ |
||
22 | -- Message |
||
23 | -- Writes a system message to the chat frame |
||
24 | ------------------------------------------------------------------------------ |
||
25 | function LT_Message(msg) |
||
26 | |||
27 | -- Make sure the chat frame we're adding messages to exists |
||
28 | if (DEFAULT_CHAT_FRAME) then |
||
29 | -- Get the information for system messages |
||
30 | local info = ChatTypeInfo["SYSTEM"]; |
||
31 | |||
32 | local settings = LT_GetSettings(); |
||
33 | |||
34 | local chatColor = {r=info.r,g=info.g,b=info.b}; |
||
35 | if (settings.ChatColor ~= nil) then |
||
36 | chatColor = settings.ChatColor; |
||
37 | end |
||
38 | |||
39 | -- Add the message as a system message |
||
40 | DEFAULT_CHAT_FRAME:AddMessage(LT_CurrentIndentString .. msg, chatColor.r, chatColor.g, chatColor.b, info.id); |
||
41 | end |
||
42 | |||
43 | end |
||
44 | |||
45 | |||
46 | ------------------------------------------------------------------------------ |
||
47 | -- MessageIndent |
||
48 | -- Indent all following Message() calls. |
||
49 | ------------------------------------------------------------------------------ |
||
50 | |||
51 | function LT_MessageIndent() |
||
52 | |||
53 | LT_CurrentIndentString = LT_CurrentIndentString .. LT_Indent; |
||
54 | |||
55 | end |
||
56 | |||
57 | |||
58 | ------------------------------------------------------------------------------ |
||
59 | -- MessageUnindent |
||
60 | -- Unindent all following Message() calls. |
||
61 | ------------------------------------------------------------------------------ |
||
62 | |||
63 | function LT_MessageUnindent() |
||
64 | |||
65 | local indentSize = strlen(LT_Indent); |
||
66 | local currentIndentSize = strlen(LT_CurrentIndentString); |
||
67 | |||
68 | LT_CurrentIndentString = strsub(LT_CurrentIndentString, 1, currentIndentSize - indentSize); |
||
69 | |||
70 | end |
||
71 | |||
72 | |||
73 | ------------------------------------------------------------------------------ |
||
74 | -- StdOut |
||
75 | ------------------------------------------------------------------------------ |
||
76 | |||
77 | LT_StdOut = { |
||
78 | Write=LT_Message, |
||
79 | Indent=LT_MessageIndent, |
||
80 | Unindent=LT_MessageUnindent |
||
81 | }; |
||
82 | |||
83 | |||
84 | ------------------------------------------------------------------------------ |
||
85 | -- BufferWrite |
||
86 | ------------------------------------------------------------------------------ |
||
87 | |||
88 | function LT_BufferWrite(text) |
||
89 | |||
90 | LT_WriteBuffer = LT_WriteBuffer .. LT_BufferCurrentIndent .. text .. "\n"; |
||
91 | |||
92 | end |
||
93 | |||
94 | |||
95 | ------------------------------------------------------------------------------ |
||
96 | -- BufferIndent |
||
97 | ------------------------------------------------------------------------------ |
||
98 | |||
99 | function LT_BufferIndent() |
||
100 | |||
101 | LT_BufferCurrentIndent = LT_BufferCurrentIndent .. LT_Indent; |
||
102 | |||
103 | end |
||
104 | |||
105 | |||
106 | ------------------------------------------------------------------------------ |
||
107 | -- BufferUnindent |
||
108 | ------------------------------------------------------------------------------ |
||
109 | |||
110 | function LT_BufferUnindent() |
||
111 | |||
112 | local indentSize = strlen(LT_Indent); |
||
113 | local currentIndentSize = strlen(LT_BufferCurrentIndent); |
||
114 | |||
115 | LT_BufferCurrentIndent = strsub(LT_BufferCurrentIndent, 1, currentIndentSize - indentSize); |
||
116 | |||
117 | end |
||
118 | |||
119 | |||
120 | ------------------------------------------------------------------------------ |
||
121 | -- BufferOut |
||
122 | ------------------------------------------------------------------------------ |
||
123 | |||
124 | LT_BufferOut = { |
||
125 | Write=LT_BufferWrite, |
||
126 | Indent=LT_BufferIndent, |
||
127 | Unindent=LT_BufferUnindent |
||
128 | }; |
||
129 | |||
130 | |||
131 | ------------------------------------------------------------------------------ |
||
132 | -- FormatMessageTable |
||
133 | -- Formats and outputs a table object. |
||
134 | ------------------------------------------------------------------------------ |
||
135 | |||
136 | function LT_FormatMessageTable(t, prefix, output) |
||
137 | |||
138 | if (output == nil) then |
||
139 | LT_DebugMessage(2, "Redirecting to standard output in LT_FormatMessageTable"); |
||
140 | output = LT_StdOut; |
||
141 | end |
||
142 | |||
143 | if (prefix == nil) then |
||
144 | output.Write("{"); |
||
145 | else |
||
146 | output.Write(prefix); |
||
147 | end |
||
148 | |||
149 | output.Indent(); |
||
150 | |||
151 | foreach(t, function(k,v) |
||
152 | LT_FormatMessageKeyValue(k, v, output); |
||
153 | end); |
||
154 | |||
155 | output.Unindent(); |
||
156 | |||
157 | if (prefix == nil) then |
||
158 | output.Write("}"); |
||
159 | end |
||
160 | |||
161 | end |
||
162 | |||
163 | |||
164 | ------------------------------------------------------------------------------ |
||
165 | -- FormatMessageKeyValue |
||
166 | -- Formats and outputs a key,value pair. |
||
167 | ------------------------------------------------------------------------------ |
||
168 | |||
169 | function LT_FormatMessageKeyValue(key, value, output) |
||
170 | |||
171 | if (output == nil) then |
||
172 | LT_DebugMessage(2, "Redirecting to standard output in LT_FormatMessageKeyValue"); |
||
173 | output = LT_StdOut; |
||
174 | end |
||
175 | |||
176 | local prefix = key .. ": "; |
||
177 | |||
178 | if (type(value) == "table") then |
||
179 | LT_FormatMessageTable(value, prefix, output); |
||
180 | else |
||
181 | output.Write(prefix .. tostring(value)); |
||
182 | end |
||
183 | |||
184 | end |
||
185 | |||
186 | |||
187 | ------------------------------------------------------------------------------ |
||
188 | -- FormatMessage |
||
189 | -- Formats and outputs an object depending on its type. |
||
190 | ------------------------------------------------------------------------------ |
||
191 | |||
192 | function LT_FormatMessage(value, output) |
||
193 | |||
194 | if (output == nil) then |
||
195 | LT_DebugMessage(2, "Redirecting to standard output in LT_FormatMessage"); |
||
196 | output = LT_StdOut; |
||
197 | end |
||
198 | |||
199 | if (type(value) == "table") then |
||
200 | LT_FormatMessageTable(value, nil, output); |
||
201 | else |
||
202 | output.Write(tostring(value)); |
||
203 | end |
||
204 | |||
205 | end |
||
206 | |||
207 | |||
208 | ------------------------------------------------------------------------------ |
||
209 | -- DebugMessage |
||
210 | -- Displays a message only if debug mode is enabled |
||
211 | ------------------------------------------------------------------------------ |
||
212 | |||
213 | function LT_DebugMessage(level, message) |
||
214 | |||
215 | local settings = LT_GetSettings(); |
||
216 | local levelThreshold = settings.DebugLevel; |
||
217 | if (levelThreshold == nil) then |
||
218 | levelThreshold = 1; |
||
219 | end |
||
220 | |||
221 | if (levelThreshold >= level) then |
||
222 | LT_Message(message); |
||
223 | end |
||
224 | |||
225 | end |
||
226 |