comparison Devian.lua @ 72:da5ff1fc9fb6

- Fixed an issue with creating more than one output channel per UI session. - Cleanup of globals for slightly better performance when printing to a lot of channels at once
author Nenue
date Sat, 09 Apr 2016 05:51:19 -0400
parents d636ff1b17ce
children 3745540e8996
comparison
equal deleted inserted replaced
71:d636ff1b17ce 72:da5ff1fc9fb6
3 -- @project-revision@ @project-hash@ 3 -- @project-revision@ @project-hash@
4 -- @file-revision@ @file-hash@ 4 -- @file-revision@ @file-hash@
5 5
6 --GLOBALS: Devian, DevCon, DevianLoadMessage 6 --GLOBALS: Devian, DevCon, DevianLoadMessage
7 local ADDON, D = ... 7 local ADDON, D = ...
8 8 local sub, GetTime, print, _G = string.sub, GetTime, print, _G
9 local format, setmetatable, getprinthandler, setprinthandler = string.format, setmetatable, getprinthandler, setprinthandler
10 local tinsert = tinsert
9 local currentProfile 11 local currentProfile
10 local playerName = UnitName("player") 12 local playerName = UnitName("player")
11 local playerRealm = playerName .. '-' .. GetRealmName() 13 local playerRealm = playerName .. '-' .. GetRealmName()
12 local num_dock_tabs = 0 14 local num_dock_tabs = 0
13 local in_workspace = false 15 local in_workspace = false
44 D.L = setmetatable({}, { 46 D.L = setmetatable({}, {
45 __index= function(t,k) 47 __index= function(t,k)
46 return k 48 return k
47 end, 49 end,
48 __call = function(t,k,...) 50 __call = function(t,k,...)
49 return string.format((t[k] or k) , ...) 51 return format((t[k] or k) , ...)
50 end 52 end
51 }) 53 })
52 54
53 local MAJOR, MINOR = 'Devian-2.0', 'r@project-revision@' 55 local MAJOR, MINOR = 'Devian-2.0', 'r@project-revision@'
54 local D = LibStub("AceAddon-3.0"):NewAddon(D, "Devian", "AceConsole-3.0", "AceEvent-3.0") 56 local D = LibStub("AceAddon-3.0"):NewAddon(D, "Devian", "AceConsole-3.0", "AceEvent-3.0")
206 D.num_channels = currentProfile.num_channels 208 D.num_channels = currentProfile.num_channels
207 D.enabled = currentProfile.enabled 209 D.enabled = currentProfile.enabled
208 D.sig = {} 210 D.sig = {}
209 D.sigID = {} 211 D.sigID = {}
210 D.IDsig = {} 212 D.IDsig = {}
211 D.dock = DevianDock 213 D.dock = _G.DevianDock
212 D.dock.buttons = D.dock.buttons or {} 214 D.dock.buttons = D.dock.buttons or {}
213 215
214 return id, name 216 return id, name
215 end 217 end
216 218
242 D.Profile(list_id, dest) 244 D.Profile(list_id, dest)
243 scan_func = D.Save 245 scan_func = D.Save
244 D:Print("Profile |cFFFFFF00".. list_id .."|r saved.") 246 D:Print("Profile |cFFFFFF00".. list_id .."|r saved.")
245 else 247 else
246 248
247 DevianLoadMessage = "Switched profiles." 249 _G.DevianLoadMessage = "Switched profiles."
248 250
249 list_id = tonumber(mode) 251 list_id = tonumber(mode)
250 if list_id ~= db.main_profile then 252 if list_id ~= db.main_profile then
251 db.last_profile = list_id 253 db.last_profile = list_id
252 end 254 end
253 db.current_profile = list_id 255 db.current_profile = list_id
254 scan_func = D.Load 256 scan_func = D.Load
255 end 257 end
256 elseif mode == nil then 258 elseif mode == nil then
257 list_id = (db.current_profile ~= db.main_profile) and db.main_profile or db.last_profile 259 list_id = (db.current_profile ~= db.main_profile) and db.main_profile or db.last_profile
258 DevianLoadMessage = "Switched between main and recent profile ("..db.current_profile..' and '..list_id..')' 260 _G.DevianLoadMessage = "Switched between main and recent profile ("..db.current_profile..' and '..list_id..')'
259 db.current_profile = list_id 261 db.current_profile = list_id
260 scan_func = D.Load 262 scan_func = D.Load
261 else 263 else
262 return D:PrintHelp() 264 return D:PrintHelp()
263 end 265 end
274 scan_func(id, name, enableState, globalState) 276 scan_func(id, name, enableState, globalState)
275 end 277 end
276 end 278 end
277 279
278 if scan_func == D.Load then 280 if scan_func == D.Load then
279 ReloadUI() 281 _G.ReloadUI()
280 end 282 end
281 D.Profile(db.current_profile) 283 D.Profile(db.current_profile)
282 end 284 end
283 285
284 D.Addons = function() 286 D.Addons = function()
373 --- Creates a Devian-style output. 375 --- Creates a Devian-style output.
374 -- The first argument describes the channel to output on, and the remaining arguments are concatenated in a manner similar to default print() 376 -- The first argument describes the channel to output on, and the remaining arguments are concatenated in a manner similar to default print()
375 -- This becomes the print handler when development mode is active. The original print() function is assigned to oldprint(). 377 -- This becomes the print handler when development mode is active. The original print() function is assigned to oldprint().
376 -- @param Tag, signature, or numeric index of the channel to output on. Defaults to primary channel. 378 -- @param Tag, signature, or numeric index of the channel to output on. Defaults to primary channel.
377 -- @param ... Output contents. 379 -- @param ... Output contents.
380
378 function D.Message(prefix, ...) 381 function D.Message(prefix, ...)
379 if not currentProfile.workspace then 382 if not currentProfile.workspace then
380 return D.oldprint(prefix, ...) 383 return D.oldprint(prefix, ...)
381 end 384 end
382 prefix = tostring(prefix) 385 prefix = tostring(prefix)
422 for i = 1, select('#',...) do 425 for i = 1, select('#',...) do
423 local var = select(i, ...) 426 local var = select(i, ...)
424 427
425 if type(var) == 'table' then 428 if type(var) == 'table' then
426 if type(var.GetName) == 'function' then 429 if type(var.GetName) == 'function' then
427 var = '<table:'..tostring(var:GetName())..'>' 430 var = '[table:'..tostring(var:GetName())..']'
428 else 431 else
429 var = '<'..tostring(var)..'>' 432 var = '<'..tostring(var)..'>'
430 end 433 end
431 434
432 elseif type(var) == 'boolean' then 435 elseif type(var) == 'boolean' then
433 var = var and 'true' or 'false' 436 var = var and '[true]' or '[false]'
434 elseif type(var) == 'function' then 437 elseif type(var) == 'function' then
435 var = '<funcref>' 438 var = '['..tostring(var)..']'
436 elseif type(var) == 'nil' then 439 elseif type(var) == 'nil' then
437 var = 'nil' 440 var = '[nil]'
438 else 441 else
439 var = tostring(var) 442 var = tostring(var)
440 end 443 end
441 444
442 insert(buffer, var) 445 insert(buffer, var)
443 end 446 end
444 local message = concat(buffer, ' ') 447 local message = concat(buffer, ' ')
445 for id, channel in pairs(sendq) do 448 for id, channel in pairs(sendq) do
446 if channel.width < 250 then 449 if channel.width < 250 then
447 prefix = string.sub(prefix, 0,2) 450 prefix = sub(prefix, 0,2)
448 end 451 end
449 channel.out:AddMessage('|cFF'.. pcolor..prefix ..'|r ' .. message, 0.8, 0.8, 0.8, nil, nil, prefix, GetTime()) 452 channel.out:AddMessage('|cFF'.. pcolor..prefix ..'|r ' .. message, 0.8, 0.8, 0.8, nil, nil, prefix, GetTime())
450 if not D.dock.buttons[id].newMessage then 453 if not D.dock.buttons[id].newMessage then
451 D.dock.buttons[id].newMessage = true 454 D.dock.buttons[id].newMessage = true
452 D.UpdateBeacon(D.dock.buttons[id]) 455 D.UpdateBeacon(D.dock.buttons[id])
467 D:Print("|cFFFFFF00/cleandvn|r", "- Fully resets SavedVariables, profiles and all.") 470 D:Print("|cFFFFFF00/cleandvn|r", "- Fully resets SavedVariables, profiles and all.")
468 end 471 end
469 472
470 local blocked = {profiles = true, debugmode = true} 473 local blocked = {profiles = true, debugmode = true}
471 D.SetDefaults = function() 474 D.SetDefaults = function()
475 local DevianDB = _G.DevianDB
472 for k,v in pairs(DevianDB) do 476 for k,v in pairs(DevianDB) do
473 if not blocked[k] then 477 if not blocked[k] then
474 DevianDB[k] = nil 478 DevianDB[k] = nil
475 end 479 end
476 end 480 end
477 for k,v in pairs(defaults) do 481 for k,v in pairs(defaults) do
478 if not blocked[k] then 482 if not blocked[k] then
479 DevianDB[k] = v 483 DevianDB[k] = v
480 end 484 end
481 end 485 end
482 DevianLoadMessage = "Non-user SavedVars have been reset." 486 _G.DevianLoadMessage = "Non-user SavedVars have been reset."
483 ReloadUI() 487 _G.ReloadUI()
484 end 488 end
485 D.SetDefaultsAll = function () 489 D.SetDefaultsAll = function ()
486 DevianDB = nil 490 _G.DevianDB = nil
487 DevianLoadMessage = "All SavedVars wiped." 491 _G.DevianLoadMessage = "All SavedVars wiped."
488 ReloadUI() 492 _G.ReloadUI()
489 end 493 end
490 D.ConfigCommand = function(self, input) 494 D.ConfigCommand = function(self, input)
491 if not self.config then 495 if not self.config then
492 self.config = DevCon 496 self.config = DevCon
493 self:EnableModule("Config") 497 self:EnableModule("Config")
497 501
498 function D:OnEnable() 502 function D:OnEnable()
499 503
500 -- commands 504 -- commands
501 local cmdlist = { 505 local cmdlist = {
506 ['dfs'] = 'FrameHelper_Update',
502 ['dvn'] = "Command", 507 ['dvn'] = "Command",
503 ['devian'] = "Command", 508 ['devian'] = "Command",
504 ['dvc'] = "Console_Toggle", 509 ['dvc'] = "Console_Toggle",
505 ['cleandvn'] = "SetDefaultsAll", 510 ['cleandvn'] = "SetDefaultsAll",
506 ['resetdvn'] = "SetDefaults", 511 ['resetdvn'] = "SetDefaults",
519 end 524 end
520 db = _G.DevianDB 525 db = _G.DevianDB
521 self.db = db 526 self.db = db
522 527
523 --- 528 ---
524 if DevianLoadMessage then 529 if _G.DevianLoadMessage then
525 D:Print(DevianLoadMessage) 530 D:Print(_G.DevianLoadMessage)
526 DevianLoadMessage = nil 531 _G.DevianLoadMessage = nil
527 end 532 end
528 533
529 534
530 --- initialize the current profile 535 --- initialize the current profile
531 local id, name = D.Profile(db.current_profile or 1) 536 local id, name = D.Profile(db.current_profile or 1)
555 if D.console[currentProfile.current_channel] then 560 if D.console[currentProfile.current_channel] then
556 --print('bringing', D.console[currentProfile.current_channel].signature, 'to the front') 561 --print('bringing', D.console[currentProfile.current_channel].signature, 'to the front')
557 D.console[currentProfile.current_channel]:ToFront() 562 D.console[currentProfile.current_channel]:ToFront()
558 -- bring the current channel to the front 563 -- bring the current channel to the front
559 end 564 end
560 DevianDock:Show() 565 _G.DevianDock:Show()
561 D:UpdateDock() 566 D:UpdateDock()
562 end 567 end
563 end 568 end