annotate 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
rev   line source
Nenue@50 1 --- Devian - Devian.lua
Nenue@32 2 -- @file-author@
Nenue@32 3 -- @project-revision@ @project-hash@
Nenue@32 4 -- @file-revision@ @file-hash@
Nenue@66 5
Nenue@66 6 --GLOBALS: Devian, DevCon, DevianLoadMessage
Nenue@66 7 local ADDON, D = ...
Nenue@72 8 local sub, GetTime, print, _G = string.sub, GetTime, print, _G
Nenue@72 9 local format, setmetatable, getprinthandler, setprinthandler = string.format, setmetatable, getprinthandler, setprinthandler
Nenue@72 10 local tinsert = tinsert
Nenue@66 11 local currentProfile
Nenue@66 12 local playerName = UnitName("player")
Nenue@66 13 local playerRealm = playerName .. '-' .. GetRealmName()
Nenue@66 14 local num_dock_tabs = 0
Nenue@66 15 local in_workspace = false
Nenue@66 16 --@debug@
Nenue@66 17 D.debugmode = true
Nenue@66 18 --@end-debug@
Nenue@66 19 D.print = function(...)
Nenue@66 20 if currentProfile and not currentProfile.workspace then
Nenue@66 21 return
Nenue@66 22 end
Nenue@66 23
Nenue@66 24 if D.debugmode then
Nenue@66 25 return print('Dvn', ...)
Nenue@66 26 else
Nenue@66 27 return function() end
Nenue@66 28 end
Nenue@0 29 end
Nenue@66 30 local print = D.print
Nenue@66 31
Nenue@66 32 setmetatable(D, {
Nenue@66 33 __call = function(t,k)
Nenue@66 34 if not k then
Nenue@66 35 return t.in_workspace
Nenue@66 36 end
Nenue@66 37
Nenue@66 38 return function(value)
Nenue@66 39 if value then
Nenue@66 40 D[k] = value
Nenue@66 41 end
Nenue@66 42 return D[k]
Nenue@66 43 end
Nenue@66 44 end
Nenue@66 45 })
Nenue@66 46 D.L = setmetatable({}, {
Nenue@66 47 __index= function(t,k)
Nenue@66 48 return k
Nenue@66 49 end,
Nenue@66 50 __call = function(t,k,...)
Nenue@72 51 return format((t[k] or k) , ...)
Nenue@66 52 end
Nenue@66 53 })
Nenue@66 54
Nenue@57 55 local MAJOR, MINOR = 'Devian-2.0', 'r@project-revision@'
Nenue@66 56 local D = LibStub("AceAddon-3.0"):NewAddon(D, "Devian", "AceConsole-3.0", "AceEvent-3.0")
Nenue@66 57 local L = D.L
Nenue@66 58 _G.Devian = D
Nenue@46 59 D:SetDefaultModuleState(false)
Nenue@66 60 D.oldprint = getprinthandler()
Nenue@66 61 if not _G.oldprint then _G.oldprint = D.oldprint end
Nenue@66 62
Nenue@47 63 local pairs, tostring, tonumber, ipairs, type = pairs, tostring, tonumber, ipairs, type
Nenue@66 64 local max, rand, format, print = max, math.random, string.format, print
Nenue@47 65 local insert, wipe, concat = table.insert, table.wipe, table.concat
Nenue@47 66 local select, unpack = select, unpack
Nenue@47 67 local GetNumAddOns, GetAddOnInfo, GetAddOnEnableState, EnableAddOn = GetNumAddOns, GetAddOnInfo, GetAddOnEnableState, EnableAddOn
Nenue@47 68 local UnitName, DisableAddOn = UnitName, DisableAddOn
Nenue@66 69
Nenue@9 70 local db
Nenue@13 71 local defaults = {
Nenue@66 72 global = {{}, {}},
Nenue@66 73 default_channel = {
Nenue@55 74 signature = 'Main',
Nenue@55 75 x = 100, y = 800,
Nenue@55 76 height = 500, width = 600,
Nenue@66 77 enabled = true},
Nenue@66 78 current_profile = 1,
Nenue@66 79 main_profile = 1,
Nenue@66 80 last_profile = 1,
Nenue@66 81 profilesName = {},
Nenue@66 82 profiles = {
Nenue@45 83 },
Nenue@33 84 font = [[Interface\Addons\Devian\font\SourceCodePro-Regular.ttf]], -- font info
Nenue@13 85 fontsize = 13,
Nenue@13 86 fontoutline = 'NONE',
Nenue@45 87
Nenue@45 88 headergrad = {'VERTICAL', 0, 0, 0, 1,
Nenue@45 89 1, 0.1, 0.1, 1}, -- header info
Nenue@33 90 headerdrop = {1,1,1,1},
Nenue@45 91 headerblend = 'BLEND',
Nenue@33 92 headeralpha = 1,
Nenue@45 93 headerfontcolor = {1,1,1,1},
Nenue@45 94
Nenue@45 95 backdrop = {1,1,1,1}, -- background frame info
Nenue@56 96 backgrad = {'VERTICAL', 0, 0, 0, .75, 0,0,0, .65},
Nenue@55 97 backblend = 'BLEND',
Nenue@45 98 backalpha = 1,
Nenue@45 99 backborder = {.5,.5,.5,1},
Nenue@45 100 backheader = {.25,.25,.25,1},
Nenue@45 101
Nenue@45 102 frontdrop = {1,1,1,1}, -- foreground frame info
Nenue@56 103 frontgrad = {'VERTICAL', 0, 0, 0, 1, 0,0,0, 0.95},
Nenue@55 104 frontblend = 'BLEND',
Nenue@28 105 frontalpha = 1,
Nenue@45 106 frontborder = {.07,.47,1,1},
Nenue@45 107 frontheader = {1,1,1,1},
Nenue@33 108 tagcolor = {}, -- tag color repository
Nenue@36 109 workspace = 2, -- current profile
Nenue@47 110 last_workspace = 2, -- default workspace to alternate with when just "/dvn" is issued
Nenue@47 111
Nenue@47 112 dock_onshow_fade_time = 2.5,
Nenue@47 113 dock_onshow_fade_from = 1,
Nenue@47 114 dock_onshow_fade_to = 0.2,
Nenue@47 115
Nenue@47 116 dock_alpha_on = 1,
Nenue@47 117 dock_alpha_off = 0.2,
Nenue@47 118 dock_fade_in = 0.15,
Nenue@47 119 dock_fade_out = 0.45,
Nenue@47 120 dock_button_alpha_on = 1,
Nenue@47 121 dock_button_alpha_off = 0.2,
Nenue@50 122 dock_button_fade_in = 0.075,
Nenue@55 123 dock_button_fade_out = 0.075,
Nenue@47 124
Nenue@55 125 movement_fade = true,
Nenue@55 126 movement_fade_time = 0.15,
Nenue@60 127 movement_fade_from = 1,
Nenue@60 128 movement_fade_to = 0,
Nenue@60 129 movement_translation_x = 25,
Nenue@60 130 movement_translation_y = 25,
Nenue@13 131 }
Nenue@9 132
Nenue@66 133 D.console = {}
Nenue@66 134 D.max_channel = 0
Nenue@0 135
Nenue@67 136 D.InWorkspace = function ()
Nenue@67 137 return db.profiles[db.current_profile].workspace
Nenue@67 138 end
Nenue@67 139
Nenue@66 140 D.Profile = function (id, name)
Nenue@66 141
Nenue@66 142 if name and not id and db.profilesName[name] then
Nenue@66 143 id = db.profilesName[name]
Nenue@66 144 print('ID located by name, |cFF00FF00'..name..'|r is |cFFFFFF00'.. id..'|r')
Nenue@66 145 end
Nenue@66 146
Nenue@66 147 if not id or not db.profiles[id] then
Nenue@66 148 if not id then
Nenue@66 149 id = #db.profiles+1
Nenue@66 150 print('Generated profile ID: |cFFFFFF00'.. id .. '|r')
Nenue@66 151 end
Nenue@66 152
Nenue@66 153 if not name or db.profilesName[name] then
Nenue@66 154 local newName = name or (id == 1 and 'Main' or 'Profile')
Nenue@66 155 local prefix = newName
Nenue@66 156 local i = 2
Nenue@66 157 while db.profilesName[newName] do
Nenue@66 158 i = i + 1
Nenue@66 159 newName = prefix .. i
Nenue@66 160 end
Nenue@66 161 name = newName
Nenue@66 162 print('Generated profile name: |cFF00FF00'..newName..'|r')
Nenue@66 163 end
Nenue@66 164 print('Creating profile')
Nenue@66 165 db.profilesName[name] = id
Nenue@66 166 db.profiles[id] = {
Nenue@66 167 name = name,
Nenue@66 168 workspace = (id ~= 1),
Nenue@66 169 current_channel = 1,
Nenue@66 170 default_channel = 1,
Nenue@66 171 num_channels = 1,
Nenue@66 172 max_channel = 1, -- the highest created channel id
Nenue@66 173 enabled = true, -- allow enabled consoles to appear
Nenue@66 174 channels = {
Nenue@66 175 {
Nenue@66 176 index = 1,
Nenue@66 177 signature = 'Main',
Nenue@66 178 x = 100, y = 800,
Nenue@66 179 height = 500, width = 600,
Nenue@66 180 enabled = true
Nenue@66 181 }
Nenue@66 182 },
Nenue@66 183 loadouts = {},
Nenue@66 184 global = {},
Nenue@66 185 tags = {},
Nenue@66 186 char = {
Nenue@66 187 [playerRealm] = {}
Nenue@66 188 },
Nenue@66 189 unlisted = {}
Nenue@66 190 }
Nenue@66 191 end
Nenue@66 192
Nenue@66 193 D.currentProfile = db.profiles[id]
Nenue@66 194 currentProfile = D.currentProfile
Nenue@66 195 currentProfile.char[playerRealm] = currentProfile.char[playerRealm] or {}
Nenue@66 196 if currentProfile.workspace then
Nenue@66 197 setprinthandler(D.Message)
Nenue@66 198 else
Nenue@66 199 print = function() end
Nenue@66 200 end
Nenue@66 201
Nenue@66 202 D.unlisted = currentProfile.unlisted
Nenue@66 203 D.channels = currentProfile.channels
Nenue@66 204 D.tags = currentProfile.tags
Nenue@66 205 D.channelinfo = currentProfile.channels
Nenue@66 206 D.char = currentProfile.char[playerRealm]
Nenue@66 207 D.global = currentProfile.global
Nenue@66 208 D.num_channels = currentProfile.num_channels
Nenue@66 209 D.enabled = currentProfile.enabled
Nenue@66 210 D.sig = {}
Nenue@66 211 D.sigID = {}
Nenue@66 212 D.IDsig = {}
Nenue@72 213 D.dock = _G.DevianDock
Nenue@66 214 D.dock.buttons = D.dock.buttons or {}
Nenue@66 215
Nenue@66 216 return id, name
Nenue@66 217 end
Nenue@66 218
Nenue@66 219 local targetGlobal, targetChar
Nenue@66 220 D.Command = function (self, cmd, ...)
Nenue@66 221 local list_id, scan_func, reload
Nenue@14 222 local args = {}
Nenue@14 223 local arg, n = D:GetArgs(cmd, 1)
Nenue@14 224 while arg do
Nenue@47 225 insert(args, arg)
Nenue@14 226 arg, n = D:GetArgs(cmd,1,n)
Nenue@14 227 end
Nenue@14 228 local mode, tag, dest = unpack(args)
Nenue@0 229
Nenue@14 230 -- no args, toggle ui
Nenue@57 231 if mode == 'stack' then
Nenue@14 232 return D:StackFrames()
Nenue@14 233 elseif mode == 'grid' then
Nenue@14 234 return D:DistributeFrames()
Nenue@14 235 elseif mode == 'tag' then -- tagging
Nenue@66 236 return D.Tag(self, tag, dest)
Nenue@66 237 elseif tonumber(mode) ~= nil or mode == 'save' then
Nenue@66 238 -- either a number of the save command
Nenue@66 239 if mode == 'save' then
Nenue@66 240 list_id = tonumber(tag)
Nenue@66 241 if list_id == nil then
Nenue@66 242 D:Print(L('Invalid ID from arg', tag))
Nenue@66 243 end
Nenue@66 244 D.Profile(list_id, dest)
Nenue@66 245 scan_func = D.Save
Nenue@66 246 D:Print("Profile |cFFFFFF00".. list_id .."|r saved.")
Nenue@66 247 else
Nenue@32 248
Nenue@72 249 _G.DevianLoadMessage = "Switched profiles."
Nenue@36 250
Nenue@66 251 list_id = tonumber(mode)
Nenue@66 252 if list_id ~= db.main_profile then
Nenue@66 253 db.last_profile = list_id
Nenue@18 254 end
Nenue@66 255 db.current_profile = list_id
Nenue@66 256 scan_func = D.Load
Nenue@0 257 end
Nenue@32 258 elseif mode == nil then
Nenue@66 259 list_id = (db.current_profile ~= db.main_profile) and db.main_profile or db.last_profile
Nenue@72 260 _G.DevianLoadMessage = "Switched between main and recent profile ("..db.current_profile..' and '..list_id..')'
Nenue@66 261 db.current_profile = list_id
Nenue@66 262 scan_func = D.Load
Nenue@32 263 else
Nenue@32 264 return D:PrintHelp()
Nenue@0 265 end
Nenue@67 266 if not db.profiles[list_id].char[playerRealm] then
Nenue@67 267 db.profiles[list_id].char[playerRealm] = {}
Nenue@67 268 end
Nenue@67 269
Nenue@66 270 targetGlobal = db.profiles[list_id].global
Nenue@66 271 targetChar = db.profiles[list_id].char[playerRealm]
Nenue@32 272
Nenue@67 273
Nenue@66 274 if scan_func then
Nenue@66 275 for id, name, enableState, globalState in D.Addons() do
Nenue@66 276 scan_func(id, name, enableState, globalState)
Nenue@0 277 end
Nenue@0 278 end
Nenue@0 279
Nenue@66 280 if scan_func == D.Load then
Nenue@72 281 _G.ReloadUI()
Nenue@66 282 end
Nenue@66 283 D.Profile(db.current_profile)
Nenue@66 284 end
Nenue@66 285
Nenue@66 286 D.Addons = function()
Nenue@66 287 local playername = UnitName("player")
Nenue@66 288 return function(n, i)
Nenue@66 289 if i >= n then
Nenue@66 290 return nil
Nenue@66 291 end
Nenue@66 292
Nenue@66 293 i = i + 1
Nenue@66 294 local name = GetAddOnInfo(i)
Nenue@66 295 local enableState, globalState = GetAddOnEnableState(playername, i), GetAddOnEnableState(nil, i)
Nenue@66 296 return i, name, enableState, globalState
Nenue@66 297 end, GetNumAddOns(), 0
Nenue@66 298 end
Nenue@66 299
Nenue@66 300 D.Load = function(id, name, charState, globalState)
Nenue@66 301 if targetChar[name] or targetGlobal[name] then
Nenue@66 302 if targetGlobal[name] == 2 then
Nenue@66 303 EnableAddOn(id, true)
Nenue@66 304 elseif targetChar[name] == 2 then
Nenue@66 305 EnableAddOn(id, playerName)
Nenue@66 306 else
Nenue@71 307 if targetChar[name] == 2 and targetGlobal[name] ~= 2 then
Nenue@71 308 DisableAddOn(id)
Nenue@71 309 else
Nenue@71 310 DisableAddOn(id, true)
Nenue@71 311 end
Nenue@66 312 end
Nenue@70 313 --print('load', name, 'global =', targetGlobal[name], 'char =', targetChar[name])
Nenue@0 314 else
Nenue@66 315 tinsert(D.unlisted, name)
Nenue@66 316 end
Nenue@66 317 end
Nenue@66 318 D.Save = function(id, name, charState, globalState)
Nenue@70 319 --print('save', id, name, charState, globalState)
Nenue@66 320 targetGlobal[name] = globalState
Nenue@66 321 targetChar[name] = charState
Nenue@66 322 end
Nenue@57 323
Nenue@66 324 D.Tag = function(self, tag, dest)
Nenue@66 325 local sig
Nenue@66 326 if tag ~= nil and dest ~= nil then
Nenue@66 327 --@debug@
Nenue@66 328 --print(tag, dest)
Nenue@66 329 --@end-debug@
Nenue@66 330
Nenue@66 331 -- convert to ID
Nenue@66 332 if tonumber(dest) == nil then
Nenue@66 333 if D.sigID[dest] then
Nenue@66 334 dest = currentProfile.channels[D.sigID[dest]].index
Nenue@66 335 else
Nenue@66 336 sig = dest
Nenue@66 337 end
Nenue@57 338 else
Nenue@66 339 dest = tonumber(dest)
Nenue@32 340 end
Nenue@66 341 --@debug@
Nenue@66 342 --print('2 tag,dest,sig', tag, dest, sig)--@end-debug@
Nenue@66 343
Nenue@66 344 -- make a new channel?
Nenue@66 345 local channel
Nenue@66 346 if not currentProfile.channels[dest] then
Nenue@66 347 dest = D.max_channel + 1
Nenue@66 348 D:Print(L('New channel created', sig and (dest..':'..sig) or dest ))
Nenue@66 349 channel = D:SetChannel(sig or tag,dest)
Nenue@66 350 else
Nenue@66 351 channel = D.channels[dest]
Nenue@66 352 end
Nenue@66 353 --@debug@
Nenue@66 354 --print('3 tag,dest,channel.sig=',tag, dest, channel.signature)--@end-debug@
Nenue@66 355
Nenue@66 356 if not currentProfile.tags[tag] then -- no tag table?
Nenue@66 357 currentProfile.tags[tag] = {}
Nenue@66 358 end
Nenue@66 359
Nenue@66 360 if currentProfile.tags[tag][dest] then -- is tag set?
Nenue@66 361 currentProfile.tags[tag][dest] = nil
Nenue@66 362 D:Print(L('Tag removed from channel', tag, currentProfile.channels[dest].index, currentProfile.channels[dest].signature))
Nenue@66 363 else
Nenue@66 364 currentProfile.tags[tag][dest] = dest
Nenue@66 365 D:Print(L('Tag added to channel', tag, currentProfile.channels[dest].index, currentProfile.channels[dest].signature))
Nenue@66 366 end
Nenue@66 367 D:UpdateDock()
Nenue@66 368 else
Nenue@66 369 D:Print(L['Command tag help'])
Nenue@0 370 end
Nenue@0 371 end
Nenue@0 372
Nenue@0 373
Nenue@13 374
Nenue@18 375 --- Creates a Devian-style output.
Nenue@18 376 -- The first argument describes the channel to output on, and the remaining arguments are concatenated in a manner similar to default print()
Nenue@18 377 -- This becomes the print handler when development mode is active. The original print() function is assigned to oldprint().
Nenue@18 378 -- @param Tag, signature, or numeric index of the channel to output on. Defaults to primary channel.
Nenue@18 379 -- @param ... Output contents.
Nenue@72 380
Nenue@66 381 function D.Message(prefix, ...)
Nenue@67 382 if not currentProfile.workspace then
Nenue@23 383 return D.oldprint(prefix, ...)
Nenue@23 384 end
Nenue@57 385 prefix = tostring(prefix)
Nenue@57 386 if prefix == nil then
Nenue@55 387 prefix = 'nil*'
Nenue@1 388 end
Nenue@9 389
Nenue@18 390 local sendq = {}
Nenue@30 391 local tag, id, tagged
Nenue@13 392 local byName = true
Nenue@18 393 if D.tags[prefix] then
Nenue@18 394 for _, id in pairs(D.tags[prefix]) do
Nenue@18 395 if D.console[id] then
Nenue@18 396 sendq[id] = D.console[id]
Nenue@30 397 tagged = true
Nenue@18 398 end
Nenue@18 399 end
Nenue@18 400 end
Nenue@18 401
Nenue@13 402 if D.sig[prefix] then
Nenue@18 403 sendq[D.sig[prefix].index] = D.sig[prefix]
Nenue@13 404 elseif D.console[prefix] then
Nenue@18 405 sendq[D.console[prefix]] = D.console[prefix]
Nenue@30 406 elseif not tagged then
Nenue@18 407 sendq[D.primary_channel] = D.console[D.primary_channel]
Nenue@13 408 end
Nenue@18 409
Nenue@9 410 -- color me timbers
Nenue@9 411 local pcolor
Nenue@18 412 if (not db.tagcolor[prefix]) and byName then
Nenue@30 413 local c = {
Nenue@47 414 rand(64,255), rand(64,255), rand(64,255)
Nenue@30 415 }
Nenue@30 416 if c[1] > 223 and c[2] > 223 and c[3] > 223 then
Nenue@47 417 c[rand(1,3)] = rand(64,223)
Nenue@0 418 end
Nenue@30 419
Nenue@47 420 db.tagcolor[prefix] = format('%02X%02X%02X', unpack(c))
Nenue@0 421 end
Nenue@18 422 pcolor = db.tagcolor[prefix]
Nenue@0 423
Nenue@55 424 local buffer = {}
Nenue@0 425 for i = 1, select('#',...) do
Nenue@0 426 local var = select(i, ...)
Nenue@0 427
Nenue@0 428 if type(var) == 'table' then
Nenue@20 429 if type(var.GetName) == 'function' then
Nenue@72 430 var = '[table:'..tostring(var:GetName())..']'
Nenue@20 431 else
Nenue@32 432 var = '<'..tostring(var)..'>'
Nenue@20 433 end
Nenue@20 434
Nenue@0 435 elseif type(var) == 'boolean' then
Nenue@72 436 var = var and '[true]' or '[false]'
Nenue@0 437 elseif type(var) == 'function' then
Nenue@72 438 var = '['..tostring(var)..']'
Nenue@0 439 elseif type(var) == 'nil' then
Nenue@72 440 var = '[nil]'
Nenue@60 441 else
Nenue@60 442 var = tostring(var)
Nenue@0 443 end
Nenue@0 444
Nenue@47 445 insert(buffer, var)
Nenue@0 446 end
Nenue@47 447 local message = concat(buffer, ' ')
Nenue@18 448 for id, channel in pairs(sendq) do
Nenue@55 449 if channel.width < 250 then
Nenue@72 450 prefix = sub(prefix, 0,2)
Nenue@55 451 end
Nenue@58 452 channel.out:AddMessage('|cFF'.. pcolor..prefix ..'|r ' .. message, 0.8, 0.8, 0.8, nil, nil, prefix, GetTime())
Nenue@58 453 if not D.dock.buttons[id].newMessage then
Nenue@58 454 D.dock.buttons[id].newMessage = true
Nenue@58 455 D.UpdateBeacon(D.dock.buttons[id])
Nenue@58 456 end
Nenue@18 457 end
Nenue@47 458 wipe(buffer)
Nenue@0 459 end
Nenue@0 460
Nenue@14 461
Nenue@32 462
Nenue@14 463
Nenue@32 464 function D:PrintHelp()
Nenue@32 465 D:Print("|cFFFFFF00/dvn|r",
Nenue@32 466 "\n |cFFFFFF00<number>|r - Loads a saved addon list. List 1 is treated as a gameplay profile and consoles will be disabled by default.")
Nenue@47 467 D:Print("|cFFFFFF00/dvc|r [<key>, ...]", "- Hides and show consoles. A list of channel keys can be passed to specify which ones get toggled.")
Nenue@32 468
Nenue@32 469 D:Print("|cFFFFFF00/resetdvn|r", "- Resets all but profile data SavedVariables.")
Nenue@32 470 D:Print("|cFFFFFF00/cleandvn|r", "- Fully resets SavedVariables, profiles and all.")
Nenue@32 471 end
Nenue@32 472
Nenue@66 473 local blocked = {profiles = true, debugmode = true}
Nenue@66 474 D.SetDefaults = function()
Nenue@72 475 local DevianDB = _G.DevianDB
Nenue@66 476 for k,v in pairs(DevianDB) do
Nenue@66 477 if not blocked[k] then
Nenue@66 478 DevianDB[k] = nil
Nenue@60 479 end
Nenue@60 480 end
Nenue@66 481 for k,v in pairs(defaults) do
Nenue@66 482 if not blocked[k] then
Nenue@66 483 DevianDB[k] = v
Nenue@60 484 end
Nenue@60 485 end
Nenue@72 486 _G.DevianLoadMessage = "Non-user SavedVars have been reset."
Nenue@72 487 _G.ReloadUI()
Nenue@60 488 end
Nenue@66 489 D.SetDefaultsAll = function ()
Nenue@72 490 _G.DevianDB = nil
Nenue@72 491 _G.DevianLoadMessage = "All SavedVars wiped."
Nenue@72 492 _G.ReloadUI()
Nenue@66 493 end
Nenue@70 494 D.ConfigCommand = function(self, input)
Nenue@66 495 if not self.config then
Nenue@66 496 self.config = DevCon
Nenue@66 497 self:EnableModule("Config")
Nenue@66 498 end
Nenue@66 499 self.modules.Config:ChatCommand(input)
Nenue@66 500 end
Nenue@45 501
Nenue@0 502 function D:OnEnable()
Nenue@33 503
Nenue@13 504 -- commands
Nenue@13 505 local cmdlist = {
Nenue@72 506 ['dfs'] = 'FrameHelper_Update',
Nenue@66 507 ['dvn'] = "Command",
Nenue@66 508 ['devian'] = "Command",
Nenue@36 509 ['dvc'] = "Console_Toggle",
Nenue@66 510 ['cleandvn'] = "SetDefaultsAll",
Nenue@66 511 ['resetdvn'] = "SetDefaults",
Nenue@66 512 ['dvg'] = "ConfigCommand"
Nenue@13 513 }
Nenue@13 514 for cmd, func in pairs(cmdlist) do
Nenue@13 515 self:RegisterChatCommand(cmd, func, true)
Nenue@13 516 end
Nenue@66 517 end
Nenue@66 518
Nenue@66 519 function D:OnInitialize()
Nenue@13 520
Nenue@33 521 -- pull defaults
Nenue@9 522 if not _G.DevianDB then
Nenue@13 523 _G.DevianDB = defaults
Nenue@9 524 end
Nenue@9 525 db = _G.DevianDB
Nenue@47 526 self.db = db
Nenue@0 527
Nenue@66 528 ---
Nenue@72 529 if _G.DevianLoadMessage then
Nenue@72 530 D:Print(_G.DevianLoadMessage)
Nenue@72 531 _G.DevianLoadMessage = nil
Nenue@0 532 end
Nenue@0 533
Nenue@66 534
Nenue@66 535 --- initialize the current profile
Nenue@66 536 local id, name = D.Profile(db.current_profile or 1)
Nenue@66 537 D:Print('Using profile |cFFFFFF00'.. id ..'|r: |cFF00FF00'..currentProfile.name..'|r')
Nenue@66 538 if currentProfile.workspace then
Nenue@66 539 D:Print('Workspace: '.. (#currentProfile.channels) .. ' channels, ' .. #currentProfile.tags .. ' tags.')
Nenue@66 540 D:Print('Default channel: |cFFFFFF00'..currentProfile.default_channel..'|r: |cFF00FFFF'.. D.channels[currentProfile.default_channel].signature..'|r')
Nenue@0 541 end
Nenue@13 542
Nenue@66 543 for i, cinfo in pairs(D.channels) do
Nenue@14 544 i = tonumber(i)
Nenue@66 545 if not D.primary_channel then
Nenue@66 546 D.primary_channel = i
Nenue@14 547 end
Nenue@66 548 D:SetChannel(cinfo, i)
Nenue@66 549 D.num_channels = D.num_channels + 1
Nenue@32 550 end
Nenue@32 551
Nenue@66 552 D.max_channel = max(D.max_channel, currentProfile.max_channel)
Nenue@66 553 if currentProfile.max_channel < D.max_channel then
Nenue@66 554 for i = currentProfile.max_channel, D.max_channel do
Nenue@66 555 D.console[i]:Hide()
Nenue@47 556 end
Nenue@36 557 end
Nenue@36 558
Nenue@66 559 if currentProfile.workspace then
Nenue@66 560 if D.console[currentProfile.current_channel] then
Nenue@69 561 --print('bringing', D.console[currentProfile.current_channel].signature, 'to the front')
Nenue@66 562 D.console[currentProfile.current_channel]:ToFront()
Nenue@66 563 -- bring the current channel to the front
Nenue@47 564 end
Nenue@72 565 _G.DevianDock:Show()
Nenue@66 566 D:UpdateDock()
Nenue@36 567 end
Nenue@66 568 end