annotate Devian.lua @ 71:d636ff1b17ce

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