Mercurial > wow > devian
comparison Devian.lua @ 18:01c32c98e72a v1.4
LuaDoc info added
Removal of release tagged debug output
/dvn tag <prefix> <channel> can be applied to multiple channels, and re-using the command will toggle that output off
SetChannel data clobbering fixed
Message prefix coloring fixed
| author | Nenue |
|---|---|
| date | Sun, 20 Dec 2015 18:27:26 -0500 |
| parents | 48a1d9c14af5 |
| children | df098747b31d |
comparison
equal
deleted
inserted
replaced
| 17:48a1d9c14af5 | 18:01c32c98e72a |
|---|---|
| 7 local MAJOR, MINOR = 'Devian-1.3', 'r@project-revision@' | 7 local MAJOR, MINOR = 'Devian-1.3', 'r@project-revision@' |
| 8 local D = _G.Devian | 8 local D = _G.Devian |
| 9 local STATE_LOW, STATE_HIGH = 1, 2 | 9 local STATE_LOW, STATE_HIGH = 1, 2 |
| 10 local PLAYER_REALM = UnitName("player") .. '-' .. GetRealmName() | 10 local PLAYER_REALM = UnitName("player") .. '-' .. GetRealmName() |
| 11 local DEVIAN_FRAME = 'DevianConsole' | 11 local DEVIAN_FRAME = 'DevianConsole' |
| 12 local print = function(...) | 12 local print = _G.print |
| 13 _G.print('Dvn', ...) | |
| 14 end | |
| 15 local db | 13 local db |
| 16 local defaults = { | 14 local defaults = { |
| 17 ['global'] = {[STATE_LOW] = {}, [STATE_HIGH] = {}}, | 15 ['global'] = {[STATE_LOW] = {}, [STATE_HIGH] = {}}, |
| 18 ['tags'] = {}, | 16 ['tags'] = {}, |
| 19 ['channels'] = {[1] = {signature = 'Dvn', name = 'Main', header = "%n [%t]", x = 100, y = 800, height = 500, width = 600, enabled = true}}, | 17 ['channels'] = {[1] = {signature = 'Dvn', name = 'Main', header = "%n [%t]", x = 100, y = 800, height = 500, width = 600, enabled = true}}, |
| 58 return D:StackFrames() | 56 return D:StackFrames() |
| 59 elseif mode == 'grid' then | 57 elseif mode == 'grid' then |
| 60 return D:DistributeFrames() | 58 return D:DistributeFrames() |
| 61 elseif mode == 'tag' then -- tagging | 59 elseif mode == 'tag' then -- tagging |
| 62 if tag ~= nil and dest ~= nil then | 60 if tag ~= nil and dest ~= nil then |
| 63 if not D.console[dest] and not D.sig[dest] then | 61 local channel = D:SetChannel(dest:match('%a'), dest:match('%d')) |
| 64 local sig = dest:match('%a') | 62 if not D.tags[tag] then |
| 65 local id = dest:match('%d') | 63 D.tags[tag] = {} |
| 66 if not id then | 64 end |
| 67 id = self.last_channel + 1 | 65 if D.tags[tag][channel.index] then |
| 68 end | 66 D.tags[tag][channel.index] = nil |
| 69 if not sig then | 67 D:Print('Removed |cFFFFFF00'..tag..'|r from |cFF00FFFF'.. dest .. '|r') |
| 70 sig = tag | 68 else |
| 71 end | 69 D.tags[tag][channel.index] = channel.index |
| 72 D:SetChannel(sig, id) | 70 D:Print('Assigning |cFFFFFF00'..tag..'|r to |cFF00FFFF'.. dest .. '|r') |
| 73 end | 71 end |
| 74 D:Print('Assigning |cFFFFFF00'..tag..'|r to |cFF00FFFF'.. dest .. '|r') | 72 |
| 75 else | 73 else |
| 76 D:Print('Usage: /dvn tag <prefix> <console name or number>') | 74 D:Print('Usage: /dvn tag <prefix> <console name or number>') |
| 77 end | 75 end |
| 78 return | 76 return |
| 79 elseif mode ~= nil then | 77 elseif mode ~= nil then |
| 230 else | 228 else |
| 231 D:Print('toggled off?') | 229 D:Print('toggled off?') |
| 232 end | 230 end |
| 233 end | 231 end |
| 234 | 232 |
| 235 -- Bring console to the front | 233 --- Brings the console to the front. |
| 234 -- Frame method used to bring a console frame to the front of the display stack. | |
| 236 local function Console_ToFront(c) | 235 local function Console_ToFront(c) |
| 237 --print(D.raise_ct, 'Raising', c.signature) | 236 --print(D.raise_ct, 'Raising', c.signature) |
| 238 --print(unpack(db.frontdrop)) | 237 --print(unpack(db.frontdrop)) |
| 239 --print(unpack(db.frontgrad)) | 238 --print(unpack(db.frontgrad)) |
| 240 --print(db.frontblend) | 239 --print(db.frontblend) |
| 241 D.raise_ct = D.raise_ct + 1 | 240 D.raise_ct = D.raise_ct + 1 |
| 242 c:Raise() | 241 c:Raise() |
| 243 c.out.backdrop:SetTexture(unpack(db.frontdrop)) | 242 c.out.backdrop:SetTexture(unpack(db.frontdrop)) |
| 244 c.out.backdrop:SetGradientAlpha(unpack(db.frontgrad)) | 243 c.out.backdrop:SetGradientAlpha(unpack(db.frontgrad)) |
| 245 c.out.backdrop:SetBlendMode(db.frontblend) | 244 c.out.backdrop:SetBlendMode(db.frontblend) |
| 245 D.current_channel = c.index | |
| 246 | |
| 247 for _, part in pairs(c.border) do | |
| 248 part:SetTexture(1,0,0,1) | |
| 249 end | |
| 246 | 250 |
| 247 for id, bc in pairs(D.console) do | 251 for id, bc in pairs(D.console) do |
| 248 if id ~= c.index then | 252 if id ~= c.index then |
| 249 --print(D.raise_ct, 'Lowering', bc.signature) | 253 --print(D.raise_ct, 'Lowering', bc.signature) |
| 250 --print(unpack(db.backdrop)) | 254 --print(unpack(db.backdrop)) |
| 251 --print(unpack(db.backgrad)) | 255 --print(unpack(db.backgrad)) |
| 252 --print(db.backblend) | 256 --print(db.backblend) |
| 253 bc.out.backdrop:SetTexture(unpack(db.backdrop)) | 257 bc.out.backdrop:SetTexture(unpack(db.backdrop)) |
| 254 bc.out.backdrop:SetGradientAlpha(unpack(db.backgrad)) | 258 bc.out.backdrop:SetGradientAlpha(unpack(db.backgrad)) |
| 255 bc.out.backdrop:SetBlendMode(db.backblend) | 259 bc.out.backdrop:SetBlendMode(db.backblend) |
| 256 end | 260 |
| 257 end | 261 for _, part in pairs(bc.border) do |
| 258 | 262 part:SetTexture(0,0,0.5,0.6) |
| 259 end | 263 end |
| 260 | 264 end |
| 261 -- Generate a console frame | 265 |
| 262 -- @paramsig id, vars | 266 end |
| 263 -- @param id channel number | 267 |
| 264 -- @param vars alternative config, else uses db.channels[id] | 268 end |
| 269 | |
| 270 --- Constructs the frame object for a console channel | |
| 271 -- Initializes the console channel at a specified index. | |
| 272 -- Configuration data can be overridden by passing a desired settings table. | |
| 273 -- @param i Numeric index of the channel as it manifests in db.channels | |
| 274 -- @param vars Optional settings table to be used. | |
| 265 local function CreateConsole(i, vars) | 275 local function CreateConsole(i, vars) |
| 266 | 276 |
| 267 if not vars then | 277 if not vars then |
| 268 vars = db.channels[i] | 278 vars = db.channels[i] |
| 269 end | 279 end |
| 300 end | 310 end |
| 301 | 311 |
| 302 return f | 312 return f |
| 303 end | 313 end |
| 304 | 314 |
| 305 -- Print to Devian output | 315 --- Creates a Devian-style output. |
| 306 -- @paramsig tag, ... | 316 -- The first argument describes the channel to output on, and the remaining arguments are concatenated in a manner similar to default print() |
| 307 -- @param tag channel signature or number used to select console | 317 -- This becomes the print handler when development mode is active. The original print() function is assigned to oldprint(). |
| 308 -- @param ... print arguments | 318 -- @param Tag, signature, or numeric index of the channel to output on. Defaults to primary channel. |
| 319 -- @param ... Output contents. | |
| 309 local function Message(prefix, ...) | 320 local function Message(prefix, ...) |
| 310 if prefix == nil then | 321 if prefix == nil then |
| 311 prefix = 1 | 322 prefix = 1 |
| 312 end | 323 end |
| 313 | 324 |
| 314 local channel | 325 local sendq = {} |
| 326 local tag, id | |
| 315 local byName = true | 327 local byName = true |
| 328 if D.tags[prefix] then | |
| 329 for _, id in pairs(D.tags[prefix]) do | |
| 330 if D.console[id] then | |
| 331 sendq[id] = D.console[id] | |
| 332 end | |
| 333 end | |
| 334 end | |
| 335 | |
| 316 if D.sig[prefix] then | 336 if D.sig[prefix] then |
| 317 channel = D.sig[prefix] | 337 sendq[D.sig[prefix].index] = D.sig[prefix] |
| 318 elseif D.console[prefix] then | 338 elseif D.console[prefix] then |
| 319 channel = D.console[prefix] | 339 sendq[D.console[prefix]] = D.console[prefix] |
| 320 byName = nil | 340 else |
| 321 else | 341 sendq[D.primary_channel] = D.console[D.primary_channel] |
| 322 channel = D.console[1] | 342 end |
| 323 end | 343 |
| 324 -- color me timbers | 344 -- color me timbers |
| 325 local pcolor | 345 local pcolor |
| 326 if D.tags[prefix] then | 346 if (not db.tagcolor[prefix]) and byName then |
| 327 pcolor = db.tags[prefix] | |
| 328 elseif byName then | |
| 329 local c = {0, 0, 0 } | 347 local c = {0, 0, 0 } |
| 330 local max = string.len(prefix) | 348 local max = string.len(prefix) |
| 331 for i = 1, max, 3 do | 349 for i = 1, max, 3 do |
| 332 for k, v in ipairs(c) do | 350 for k, v in ipairs(c) do |
| 333 local j = i + (k - 1) | 351 local j = i + (k - 1) |
| 340 c[k] = 0 | 358 c[k] = 0 |
| 341 elseif c[k] > 127 then | 359 elseif c[k] > 127 then |
| 342 c[k] = 255 | 360 c[k] = 255 |
| 343 end | 361 end |
| 344 end | 362 end |
| 345 D.tags[prefix] = string.format('%02X%02X%02X', unpack(c)) | 363 db.tagcolor[prefix] = string.format('%02X%02X%02X', unpack(c)) |
| 346 end | 364 end |
| 347 | 365 pcolor = db.tagcolor[prefix] |
| 348 local buffer = {'|cFF'.. D.tags[prefix]..prefix ..'|r'} | 366 |
| 367 local buffer = {'|cFF'.. pcolor..prefix ..'|r'} | |
| 349 for i = 1, select('#',...) do | 368 for i = 1, select('#',...) do |
| 350 local var = select(i, ...) | 369 local var = select(i, ...) |
| 351 | 370 |
| 352 if type(var) == 'table' then | 371 if type(var) == 'table' then |
| 353 var = '<table>' | 372 var = '<table>' |
| 359 var = 'nil' | 378 var = 'nil' |
| 360 end | 379 end |
| 361 | 380 |
| 362 table.insert(buffer, var) | 381 table.insert(buffer, var) |
| 363 end | 382 end |
| 364 channel.out:AddMessage(table.concat(buffer, ' ')) | 383 local message = table.concat(buffer, ' ') |
| 384 for id, channel in pairs(sendq) do | |
| 385 channel.out:AddMessage(message) | |
| 386 end | |
| 365 table.wipe(buffer) | 387 table.wipe(buffer) |
| 366 end | 388 end |
| 367 | 389 |
| 368 -- Spaces each frame evenly across the screen | 390 --- Spaces each frame evenly across the screen. |
| 369 function D:DistributeFrames() -- | 391 function D:DistributeFrames() -- |
| 370 --print('frame grid:', max, num_side) | 392 --print('frame grid:', max, num_side) |
| 371 local max = self.num_channels | 393 local max = self.num_channels |
| 372 local num_side = math.ceil(math.sqrt(max)) | 394 local num_side = math.ceil(math.sqrt(max)) |
| 373 local w = GetScreenWidth() / num_side | 395 local w = GetScreenWidth() / num_side |
| 385 frame:Save() | 407 frame:Save() |
| 386 end | 408 end |
| 387 | 409 |
| 388 end | 410 end |
| 389 | 411 |
| 390 -- Place all frames stacked beneath the primary frame | 412 --- Place all frames stacked beneath the primary frame. |
| 391 -- @paramsig | |
| 392 function D:StackFrames() | 413 function D:StackFrames() |
| 393 local last | 414 local last |
| 394 for i, frame in pairs(self.console) do | 415 for i, frame in pairs(self.console) do |
| 395 if last then | 416 if last then |
| 396 frame.x = last.x | 417 frame.x = last.x |
| 402 frame:Save() | 423 frame:Save() |
| 403 last = frame | 424 last = frame |
| 404 end | 425 end |
| 405 end | 426 end |
| 406 | 427 |
| 407 -- Creates or updates a console frame | 428 --- Updates a console "channel" entry, generating a new one if necessary. |
| 408 -- @paramsig cinfo [, i] | 429 -- Config data will be take from cinfo. If cinfo is a string, then only channel signature is set. The remaining variables are filled in from the primary channel. |
| 409 -- @param cinfo an array from db.channels[x] or the desired string signature | 430 -- i can be given to select a specific channel table entry to work on. Otherwise, it will just create a new channel and the frame associated with it. |
| 410 -- @param id when set, the console at that index will be assigned all parameters in cinfo | 431 -- @usage cinfo [, i] |
| 432 -- @param cinfo Config variables table, or a string to be used as channel signature | |
| 433 -- @param i Console index. If valid, settings will be inherited from that channel. | |
| 411 function D:SetChannel(cinfo, i) | 434 function D:SetChannel(cinfo, i) |
| 412 --print('join:', i , cinfo) | 435 --print('join:', i , cinfo) |
| 413 local t_info = {} | 436 local t_info = {} |
| 437 local dbvars = db.channels[self.primary_channel] | |
| 438 if type(cinfo) == 'string' then | |
| 439 local signame = tostring(cinfo) | |
| 440 t_info.signature = signame | |
| 441 end | |
| 442 | |
| 414 if type(cinfo) ~= 'table' then | 443 if type(cinfo) ~= 'table' then |
| 415 t_info.signature = tostring(cinfo) | |
| 416 cinfo = {} | 444 cinfo = {} |
| 417 end | 445 end |
| 418 local srcdb = db.channels[self.primary_channel] | 446 |
| 419 if i ~= nil then | 447 if i then |
| 420 i = tonumber(i) | 448 i = tonumber(i) |
| 421 if db.channels[i] then | 449 if db.channels[i] then |
| 422 --print('pull vars from '..db.channels[i].signature) | 450 dbvars = db.channels[i] |
| 423 cinfo = db.channels[i] | 451 else |
| 424 srcdb = cinfo | 452 -- if there is no channels[i], then we need to check for sig collision |
| 425 end | 453 local sigvar = signame |
| 426 end | 454 local j = 2 |
| 427 | 455 while D.sig[sigvar] do |
| 428 for k,v in pairs(srcdb) do | 456 sigvar = signame .. j |
| 457 j = j + 1 | |
| 458 end | |
| 459 t_info.signature = sigvar | |
| 460 end | |
| 461 end | |
| 462 | |
| 463 if not (cinfo.signature or t_info.signature) then | |
| 464 t_info.signature = 'Console'..i | |
| 465 end | |
| 466 | |
| 467 for k,v in pairs(dbvars) do | |
| 429 if not t_info[k] then | 468 if not t_info[k] then |
| 430 if cinfo[k] then | 469 if cinfo[k] then |
| 431 --print('- pulling', k..':',v) | |
| 432 t_info[k] = cinfo[k] | 470 t_info[k] = cinfo[k] |
| 471 elseif db.channels[self.primary_channel][k] then | |
| 472 t_info[k] = db.channels[self.primary_channel][k] | |
| 433 end | 473 end |
| 434 end | 474 end |
| 435 end | 475 end |
| 436 | 476 |
| 437 if not db.channels[i] then | 477 if not db.channels[i] then |
| 438 t_info.x = t_info.x + 20 | 478 t_info.x = t_info.x + 20 |
| 439 t_info.y = t_info.y - 20 | 479 t_info.y = t_info.y - 20 |
| 440 db.channels[i] = t_info | 480 db.channels[i] = t_info |
| 441 end | 481 end |
| 482 | |
| 442 if not self.console[i] then | 483 if not self.console[i] then |
| 443 self.console[i] = CreateConsole(i, t_info) | 484 self.console[i] = CreateConsole(i, t_info) |
| 444 end | 485 end |
| 445 | 486 local channel = self.console[i] |
| 446 self.sig[cinfo.signature] = self.console[i] | 487 |
| 447 self.sigID[cinfo.signature] = i | 488 self.sig[t_info.signature] = channel |
| 448 self.IDsig[i] = cinfo.signature | 489 self.sigID[t_info.signature] = i |
| 490 self.IDsig[i] = t_info.signature | |
| 491 return channel | |
| 449 end | 492 end |
| 450 | 493 |
| 451 function D:OnEnable() | 494 function D:OnEnable() |
| 452 -- commands | 495 -- commands |
| 453 local cmdlist = { | 496 local cmdlist = { |
| 487 if not cherry then | 530 if not cherry then |
| 488 cherry = "This character didn't have an AddOn table." | 531 cherry = "This character didn't have an AddOn table." |
| 489 end | 532 end |
| 490 end | 533 end |
| 491 | 534 |
| 492 -- copy tags | 535 |
| 493 self.tags = {} | 536 if not db.tags then |
| 494 for n, c in pairs(db.tags) do | 537 db.tags = {} |
| 495 self.tags[n] = c | 538 end |
| 496 end | 539 self.tags = db.tags |
| 497 if cherry then | 540 if cherry then |
| 498 D:Print(cherry) | 541 D:Print(cherry) |
| 499 end | 542 end |
| 500 D.oldprint = getprinthandler() | 543 D.oldprint = getprinthandler() |
| 501 if not _G.oldprint then | 544 if not _G.oldprint then |
| 518 if i > self.last_channel then | 561 if i > self.last_channel then |
| 519 self.last_channel = i | 562 self.last_channel = i |
| 520 end | 563 end |
| 521 self.num_channels = self.num_channels + 1 | 564 self.num_channels = self.num_channels + 1 |
| 522 end | 565 end |
| 523 setprinthandler(Message) | 566 |
| 567 if self.console[db.current_channel] then | |
| 568 self.console[db.current_channel]:ToFront() | |
| 569 end | |
| 570 | |
| 571 -- only do this in dev mode | |
| 572 if db.enabled == false then | |
| 573 setprinthandler(Message) | |
| 574 print = function(...) | |
| 575 _G.print('Dvn', ...) | |
| 576 end | |
| 577 end | |
| 524 print(MAJOR, MINOR) | 578 print(MAJOR, MINOR) |
| 525 end | 579 end |
