vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | |
2 | local mod = klhtm |
||
3 | local me = {} |
||
4 | mod.console = me |
||
5 | |||
6 | -- Special onload method called from Core.lua |
||
7 | me.onload = function() |
||
8 | |||
9 | -- Set up a command line handler |
||
10 | SLASH_KLHThreatMeter1 = "/ktm" |
||
11 | SLASH_KLHThreatMeter2 = "/klhtm" |
||
12 | SLASH_KLHThreatMeter3 = "/klhthreatmeter" |
||
13 | SlashCmdList["KLHThreatMeter"] = me.consolecommand |
||
14 | |||
15 | -- create all the CLUI tables |
||
16 | me.defineclui() |
||
17 | |||
18 | -- Add their .rootstring values |
||
19 | me.clui.rootstring = "/ktm " |
||
20 | me.clui.colourrootstring = "|cffffff00/ktm " |
||
21 | |||
22 | me.fillchildrootstrings(me.clui) |
||
23 | |||
24 | end |
||
25 | |||
26 | --[[ |
||
27 | me.fillchildrootstrings(clui) |
||
28 | Computes the value of clui.rootstring and .rootstring for all its child branches. |
||
29 | the .rootstring value is what the user has to type to get into that branch. The rootstring for the |
||
30 | topmost node is just "/ktm"; for the test child of the main node, the rootstring is "/ktm test". |
||
31 | This method is called recursively on all child branches. |
||
32 | ]] |
||
33 | me.fillchildrootstrings = function(clui) |
||
34 | |||
35 | local key |
||
36 | local value |
||
37 | |||
38 | -- debug checks |
||
39 | if clui == nil then |
||
40 | mod.out.print("clui = nil") |
||
41 | elseif clui.branches == nil then |
||
42 | mod.out.print("branches = nil") |
||
43 | end |
||
44 | |||
45 | local colourcommands = { } |
||
46 | local key2 |
||
47 | local value2 |
||
48 | local length |
||
49 | |||
50 | for key, value in clui.branches do |
||
51 | length = 1 |
||
52 | |||
53 | for key2, value2 in clui.branches do |
||
54 | |||
55 | if value ~= value2 then |
||
56 | |||
57 | for x = length, string.len(value.command) - 1 do |
||
58 | |||
59 | if string.sub(value.command, 1, x) == string.sub(value2.command, 1, x) then |
||
60 | length = x + 1 |
||
61 | else |
||
62 | break |
||
63 | end |
||
64 | end |
||
65 | end |
||
66 | end |
||
67 | |||
68 | value.colourcommand = "|cff33ff88" .. string.sub(value.command, 1, length) .. "|cffffff00" .. string.sub(value.command, length + 1) |
||
69 | |||
70 | -- debug |
||
71 | if value == nil then |
||
72 | mod.out.print("oops, nil for key = " .. key) |
||
73 | end |
||
74 | |||
75 | if type(value.output) ~= "function" then |
||
76 | value.output.rootstring = clui.rootstring .. value.command .. " " |
||
77 | value.output.colourrootstring = clui.colourrootstring .. value.colourcommand .. " " |
||
78 | me.fillchildrootstrings(value.output) |
||
79 | end |
||
80 | end |
||
81 | |||
82 | end |
||
83 | |||
84 | --[[ |
||
85 | me.runclui(commands, clui) |
||
86 | Process the commands <commands> on <clui>. |
||
87 | <commands> is an array with 0 or more strings. |
||
88 | <clui> is a branch of the console tree, e.g. me.cluitest |
||
89 | ]] |
||
90 | me.runclui = function(commands, clui) |
||
91 | |||
92 | local command = commands[1] |
||
93 | local key |
||
94 | local branch |
||
95 | |||
96 | if command == nil then |
||
97 | -- just print out help information for this one |
||
98 | me.printhelpforclui(clui) |
||
99 | |||
100 | else |
||
101 | |||
102 | -- find the branches that match the command |
||
103 | local matchingbranches = { } |
||
104 | |||
105 | for key, branch in clui.branches do |
||
106 | if string.len(branch.command) >= string.len(command) and string.sub(branch.command, 1, string.len(command)) == command then |
||
107 | -- this branch matches the command |
||
108 | table.insert(matchingbranches, branch) |
||
109 | end |
||
110 | end |
||
111 | |||
112 | -- 1) Not enough branches |
||
113 | if table.getn(matchingbranches) == 0 then |
||
114 | |||
115 | -- print error, print help, abort. |
||
116 | mod.out.print("|cffff8888No command matching " .. clui.colourrootstring .. command .. "|cffff8888 could be found.") |
||
117 | |||
118 | me.printhelpforclui(clui) |
||
119 | |||
120 | -- too many branches that match the abbreviation. Error then exit |
||
121 | elseif table.getn(matchingbranches) > 1 then |
||
122 | |||
123 | local errorstring = "|cffff8888Could not disambiguate your command " .. clui.colourrootstring .. command .. " |cffff8888, after " .. clui.colourrootstring .. "|cffff8888 you could mean {" |
||
124 | for key, branch in matchingbranches do |
||
125 | if key > 1 then |
||
126 | errorstring = errorstring .. ", " |
||
127 | end |
||
128 | |||
129 | errorstring = errorstring .. branch.colourcommand .. "|cffff8888" |
||
130 | end |
||
131 | |||
132 | errorstring = errorstring .. "}." |
||
133 | mod.out.print(errorstring) |
||
134 | |||
135 | else -- just one branch matches the abbreviation. run it. |
||
136 | |||
137 | branch = matchingbranches[1] |
||
138 | if type(branch.output) == "function" then |
||
139 | |||
140 | -- base command |
||
141 | local message = "|cff8888ffRunning the command " .. clui.colourrootstring .. branch.colourcommand |
||
142 | |||
143 | -- arguments |
||
144 | table.remove(commands, 1) |
||
145 | |||
146 | for _, key in commands do |
||
147 | message = message .. " " .. key |
||
148 | end |
||
149 | |||
150 | -- print |
||
151 | message = message .. "|cff8888ff." |
||
152 | mod.out.print(message) |
||
153 | |||
154 | -- run |
||
155 | branch.output(commands[1], commands) |
||
156 | |||
157 | else |
||
158 | -- run the block |
||
159 | table.remove(commands, 1) |
||
160 | me.runclui(commands, branch.output) |
||
161 | end |
||
162 | end |
||
163 | end |
||
164 | end |
||
165 | |||
166 | |||
167 | me.printhelpforclui = function(clui) |
||
168 | |||
169 | mod.out.print("|cff8888ffThis is the help topic for " .. clui.colourrootstring .. "|cff8888ff.") |
||
170 | |||
171 | if type(clui.description) == "string" then |
||
172 | mod.out.print(clui.description) |
||
173 | |||
174 | elseif type(clui.description) == "function" then |
||
175 | clui.description() |
||
176 | end |
||
177 | |||
178 | local key |
||
179 | local branch |
||
180 | local message |
||
181 | |||
182 | for key, branch in clui.branches do |
||
183 | message = clui.colourrootstring .. branch.colourcommand .. "|r - " |
||
184 | |||
185 | if type(branch.description) == "function" then |
||
186 | message = message .. branch.description() |
||
187 | else |
||
188 | message = message .. branch.description |
||
189 | end |
||
190 | |||
191 | mod.out.print(message) |
||
192 | end |
||
193 | |||
194 | end |
||
195 | |||
196 | --[[ |
||
197 | This method is called by typing a "/ktm" command in the console. |
||
198 | ]] |
||
199 | me.consolecommand = function(message) |
||
200 | |||
201 | -- parse space-delimited words into a list |
||
202 | local commandlist = { } |
||
203 | local command |
||
204 | |||
205 | for command in string.gfind(message, "[^ ]+") do |
||
206 | table.insert(commandlist, string.lower(command)) |
||
207 | end |
||
208 | |||
209 | me.runclui(commandlist, me.clui) |
||
210 | |||
211 | end |
||
212 | |||
213 | --[[ |
||
214 | These are static variables, but they depend on static variables defined in other modules (function pointers and such). |
||
215 | Therefore they are initialised at onload(), not when the code is read. |
||
216 | ]] |
||
217 | me.defineclui = function() |
||
218 | |||
219 | me.subclui = { } |
||
220 | |||
221 | me.subclui.version = |
||
222 | { |
||
223 | ["description"] = |
||
224 | function() |
||
225 | mod.out.print(string.format("This is Release |cff33ff33%s|r Revision |cff33ff33%s|r. These commands require you to be the raid leader or an officer.", mod.release, mod.revision)) |
||
226 | end, |
||
227 | ["branches"] = |
||
228 | { |
||
229 | { |
||
230 | ["command"] = "notify", |
||
231 | ["description"] = "Notifies users with an older version of the mod to upgrade.", |
||
232 | ["output"] = mod.net.versionnotify |
||
233 | }, |
||
234 | { |
||
235 | ["command"] = "query", |
||
236 | ["description"] = "Asks everyone in the raid to report their mod version.", |
||
237 | ["output"] = mod.net.versionquery |
||
238 | }, |
||
239 | { |
||
240 | ["command"] = "advertise", |
||
241 | ["description"] = "Will occasionally tell people who pull aggro and don't have the mod to get it. Run this command again to stop it.", |
||
242 | ["output"] = mod.net.toggleadvertise, |
||
243 | }, |
||
244 | } |
||
245 | } |
||
246 | |||
247 | -- GUI commands. Most commands would be fairly redundany, because you can just use the GUI, after all. |
||
248 | -- You can use this to bring up the window if it has been closed, or reset it completely if you have lost it. |
||
249 | me.subclui.gui = |
||
250 | { |
||
251 | ["description"] = nil, |
||
252 | ["branches"] = |
||
253 | { |
||
254 | { |
||
255 | ["command"] = "show", |
||
256 | ["description"] = "Shows the window.", |
||
257 | ["output"] = |
||
258 | function() |
||
259 | KLHTM_SetVisible(true) |
||
260 | end, |
||
261 | }, |
||
262 | { |
||
263 | ["command"] = "hide", |
||
264 | ["description"] = "Hides the window.", |
||
265 | ["output"] = |
||
266 | function() |
||
267 | KLHTM_SetVisible(false) |
||
268 | end, |
||
269 | }, |
||
270 | { |
||
271 | ["command"] = "reset", |
||
272 | ["description"] = "Puts the window back in the middle of the screen.", |
||
273 | ["output"] = KLHTM_ResetFrame, |
||
274 | }, |
||
275 | } |
||
276 | } |
||
277 | |||
278 | me.subclui.test = |
||
279 | { |
||
280 | ["description"] = nil, |
||
281 | ["branches"] = |
||
282 | { |
||
283 | { |
||
284 | ["command"] = "talents", |
||
285 | ["description"] = "Prints out your talent points in any talents that affect your threat.", |
||
286 | ["output"] = mod.data.testtalents |
||
287 | }, |
||
288 | { |
||
289 | ["command"] = "gear", |
||
290 | ["description"] = "Prints out the set pieces you are wearing for sets that affect your threat.", |
||
291 | ["output"] = mod.data.testitemsets |
||
292 | }, |
||
293 | { |
||
294 | ["command"] = "threat", |
||
295 | ["description"] = "Prints out a variety of threat parameters.", |
||
296 | ["output"] = mod.my.testthreat |
||
297 | }, |
||
298 | { |
||
299 | ["command"] = "time", |
||
300 | ["description"] = "Prints out processor time information.", |
||
301 | ["output"] = |
||
302 | function() |
||
303 | mod.diag.printalldata("time", "Milliseconds, or Milliseconds per Second") |
||
304 | end |
||
305 | }, |
||
306 | { |
||
307 | ["command"] = "memory", |
||
308 | ["description"] = "Prints out memory usage information.", |
||
309 | ["output"] = |
||
310 | function() |
||
311 | mod.diag.printalldata("memory", "Kilobytes, or Kilobytes per Second") |
||
312 | end |
||
313 | }, |
||
314 | { |
||
315 | ["command"] = "channel", |
||
316 | ["description"] = "Checks whether the communication channel is properly set up.", |
||
317 | ["output"] = function() |
||
318 | |||
319 | local number |
||
320 | local name |
||
321 | local source |
||
322 | |||
323 | number, name, source = mod.net.getchannel() |
||
324 | |||
325 | if number == 0 then |
||
326 | mod.out.print("The mod could not find a suitable channel!") |
||
327 | |||
328 | else |
||
329 | mod.out.print(string.format("You are using channel number %s, %s, from %s.", number, name, source)) |
||
330 | |||
331 | end |
||
332 | |||
333 | end |
||
334 | }, |
||
335 | { |
||
336 | ["command"] = "netlog", |
||
337 | ["description"] = "Information about the channel messages received.", |
||
338 | ["output"] = |
||
339 | function() |
||
340 | local key |
||
341 | local value |
||
342 | |||
343 | for key, value in mod.netin.messagelog do |
||
344 | mod.out.print(string.format("|cffffff00%s: |r%d bytes in %d messages (%d average).", key, value.bytes, value.count, math.floor(0.5 + value.bytes / math.max(value.count, 0)))) |
||
345 | end |
||
346 | end |
||
347 | }, |
||
348 | { |
||
349 | ["command"] = "states", |
||
350 | ["description"] = "Check that the mod has the correct value for its state variables", |
||
351 | ["output"] = |
||
352 | function() |
||
353 | local key |
||
354 | local value |
||
355 | |||
356 | local doformat = function(Time) |
||
357 | if Time == 0 then |
||
358 | return "never" |
||
359 | end |
||
360 | |||
361 | return string.format("%d seconds ago", GetTime() - Time) |
||
362 | end |
||
363 | |||
364 | for key, value in mod.my.states do |
||
365 | mod.out.print(string.format("The state '%s' is '%s'. The last change was %s.", key, mod.out.booltostring(value.value), doformat(value.lastchange))) |
||
366 | end |
||
367 | end |
||
368 | }, |
||
369 | { |
||
370 | ["command"] = "local", |
||
371 | ["description"] = "Check for localisations that are missing in your locale.", |
||
372 | ["output"] = mod.string.testlocalisation, |
||
373 | }, |
||
374 | } |
||
375 | } |
||
376 | |||
377 | me.subclui.boss = |
||
378 | { |
||
379 | description = "To run these commands you must be a raid assistant or the group leader.", |
||
380 | branches = |
||
381 | { |
||
382 | { |
||
383 | command = "report", |
||
384 | description = "Make players notify you when their threat is changed by boss abilities.", |
||
385 | output = mod.net.startspellreporting, |
||
386 | }, |
||
387 | { |
||
388 | command = "endreport", |
||
389 | description = "Stop players reporting when their threat is changed by boss abilities.", |
||
390 | output = mod.net.stopspellreporting, |
||
391 | }, |
||
392 | { |
||
393 | command = "setspell", |
||
394 | description = "Change a parameter of a known boss ability.", |
||
395 | |||
396 | output = function(firstvalue, allvalues) |
||
397 | |||
398 | local value, errormessage = mod.net.checkspellvaluesyntax(allvalues) |
||
399 | |||
400 | if errormessage then |
||
401 | mod.out.print("|cffff8888Syntax: setspell <spellid> <bossid> <parameter> <value>") |
||
402 | mod.out.print(errormessage) |
||
403 | |||
404 | else |
||
405 | -- set the value |
||
406 | mod.net.setspellvalue(allvalues[1], allvalues[2], allvalues[3], allvalues[4]) |
||
407 | end |
||
408 | end, |
||
409 | }, |
||
410 | { |
||
411 | command = "autotarget", |
||
412 | description = "Clear the meter and set the master target automatically when you next target a world boss.", |
||
413 | output = function() |
||
414 | if mod.net.checkpermission() then |
||
415 | mod.boss.starttrigger("autotarget") |
||
416 | mod.out.print(mod.string.get("print", "boss", "autotargetstart")) |
||
417 | end |
||
418 | end, |
||
419 | }, |
||
420 | } |
||
421 | } |
||
422 | |||
423 | me.clui = |
||
424 | { |
||
425 | --["RootString"] = <a string>. Gets filled in at RunTime - KLHTM_ConsoleUIStartup() |
||
426 | ["description"] = nil, |
||
427 | ["branches"] = |
||
428 | { |
||
429 | { |
||
430 | ["command"] = "test", |
||
431 | ["description"] = "A set of debugging commands.", |
||
432 | ["output"] = me.subclui.test |
||
433 | }, |
||
434 | { |
||
435 | ["command"] = "gui", |
||
436 | ["description"] = "Commands to show the window.", |
||
437 | ["output"] = me.subclui.gui |
||
438 | }, |
||
439 | { |
||
440 | ["command"] = "version", |
||
441 | ["description"] = "Commands to check and upgrade the version of other users.", |
||
442 | ["output"] = me.subclui.version, |
||
443 | }, |
||
444 | { |
||
445 | ["command"] = "disable", |
||
446 | ["description"] = "Emergency stop: disables events / onupdate.", |
||
447 | ["output"] = function() |
||
448 | if mod.isenabled == false then |
||
449 | mod.out.print("The mod is already disabled. Run the 'enable' command to restart it.") |
||
450 | |||
451 | else |
||
452 | mod.isenabled = false |
||
453 | mod.out.print("The mod has been disabled, and won't work until you run the 'enable' command.") |
||
454 | end |
||
455 | end |
||
456 | }, |
||
457 | { |
||
458 | ["command"] = "enable", |
||
459 | ["description"] = "Restart the mod after an emergency stop.", |
||
460 | ["output"] = function() |
||
461 | if mod.isenabled == true then |
||
462 | mod.out.print("The mod is already running.") |
||
463 | |||
464 | else |
||
465 | mod.isenabled = true |
||
466 | mod.out.print("The mod has been restarted, and will now receive events / onupdate.") |
||
467 | end |
||
468 | end |
||
469 | }, |
||
470 | { |
||
471 | ["command"] = "mastertarget", |
||
472 | ["description"] = "Set or clear the Master Target.", |
||
473 | ["output"] = function() |
||
474 | if (UnitExists("target")) then |
||
475 | mod.net.sendmastertarget() |
||
476 | else |
||
477 | mod.net.clearmastertarget() |
||
478 | end |
||
479 | end |
||
480 | }, |
||
481 | { |
||
482 | ["command"] = "resetraid", |
||
483 | ["description"] = "Reset the threat of everyone in the raid group.", |
||
484 | ["output"] = mod.net.clearraidthreat, |
||
485 | }, |
||
486 | { |
||
487 | ["command"] = "boss", |
||
488 | ["description"] = "Functions to work out and set boss abilities.", |
||
489 | ["output"] = me.subclui.boss, |
||
490 | }, |
||
491 | }, |
||
492 | } |
||
493 | |||
494 | end |