annotate Devian.lua @ 89:b3ed963f482d v.2.1.92

- /dvc command needed a pre-defined enclosure to properly work through SlashCmdList - /dvn <profile name> and /dvn save <profile name> should resolve to and update the correct profile. - set some globals indicating the name and index of the workspace in use - DEVIAN_WORKSPACE (bool) - DEVIAN_PNAME (string) - DEVIAN_PID (number)
author Nenue
date Wed, 10 Aug 2016 06:58:27 -0400
parents e80723841888
children bb403e03d82d
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@79 6 --GLOBALS: Devian, DevCon, DevianLoadMessage, DEVIAN_WORKSPACE
Nenue@79 7
Nenue@66 8 local ADDON, D = ...
Nenue@79 9 local MAJOR, MINOR = 'Devian-2.0', 'r@project-revision@'
Nenue@79 10 local D = LibStub("AceAddon-3.0"):NewAddon(D, "Devian", "AceConsole-3.0", "AceEvent-3.0")
Nenue@79 11 local L = D.L
Nenue@79 12 Devian = D
Nenue@72 13 local sub, GetTime, print, _G = string.sub, GetTime, print, _G
Nenue@72 14 local format, setmetatable, getprinthandler, setprinthandler = string.format, setmetatable, getprinthandler, setprinthandler
Nenue@79 15 local tinsert, tremove, rawset = tinsert, tremove, rawset
Nenue@66 16 local currentProfile
Nenue@66 17 local playerName = UnitName("player")
Nenue@66 18 local playerRealm = playerName .. '-' .. GetRealmName()
Nenue@66 19 local num_dock_tabs = 0
Nenue@79 20 DEVIAN_WORKSPACE = false
Nenue@89 21 DEVIAN_PNAME = 'Dvn'
Nenue@89 22 DEVIAN_PID = 0
Nenue@79 23
Nenue@79 24
Nenue@79 25 DevianLoadMessage = setmetatable({}, {
Nenue@79 26 __call = function(t, msg)
Nenue@79 27 rawset(t, #t+1, msg)
Nenue@79 28 end,
Nenue@79 29 __index = function(t)
Nenue@79 30 return #t
Nenue@79 31 end
Nenue@79 32 })
Nenue@79 33
Nenue@66 34 --@debug@
Nenue@66 35 D.debugmode = true
Nenue@66 36 --@end-debug@
Nenue@66 37 D.print = function(...)
Nenue@66 38 if currentProfile and not currentProfile.workspace then
Nenue@66 39 return
Nenue@66 40 end
Nenue@66 41
Nenue@66 42 if D.debugmode then
Nenue@66 43 return print('Dvn', ...)
Nenue@66 44 else
Nenue@66 45 return function() end
Nenue@66 46 end
Nenue@0 47 end
Nenue@66 48 local print = D.print
Nenue@66 49
Nenue@66 50 D.L = setmetatable({}, {
Nenue@66 51 __index= function(t,k)
Nenue@66 52 return k
Nenue@66 53 end,
Nenue@66 54 __call = function(t,k,...)
Nenue@72 55 return format((t[k] or k) , ...)
Nenue@66 56 end
Nenue@66 57 })
Nenue@46 58 D:SetDefaultModuleState(false)
Nenue@66 59 D.oldprint = getprinthandler()
Nenue@66 60 if not _G.oldprint then _G.oldprint = D.oldprint end
Nenue@66 61
Nenue@47 62 local pairs, tostring, tonumber, ipairs, type = pairs, tostring, tonumber, ipairs, type
Nenue@66 63 local max, rand, format, print = max, math.random, string.format, print
Nenue@47 64 local insert, wipe, concat = table.insert, table.wipe, table.concat
Nenue@47 65 local select, unpack = select, unpack
Nenue@47 66 local GetNumAddOns, GetAddOnInfo, GetAddOnEnableState, EnableAddOn = GetNumAddOns, GetAddOnInfo, GetAddOnEnableState, EnableAddOn
Nenue@47 67 local UnitName, DisableAddOn = UnitName, DisableAddOn
Nenue@66 68
Nenue@9 69 local db
Nenue@13 70 local defaults = {
Nenue@66 71 global = {{}, {}},
Nenue@66 72 default_channel = {
Nenue@55 73 signature = 'Main',
Nenue@55 74 x = 100, y = 800,
Nenue@55 75 height = 500, width = 600,
Nenue@66 76 enabled = true},
Nenue@66 77 current_profile = 1,
Nenue@66 78 main_profile = 1,
Nenue@66 79 last_profile = 1,
Nenue@66 80 profilesName = {},
Nenue@66 81 profiles = {
Nenue@45 82 },
Nenue@33 83 font = [[Interface\Addons\Devian\font\SourceCodePro-Regular.ttf]], -- font info
Nenue@13 84 fontsize = 13,
Nenue@13 85 fontoutline = 'NONE',
Nenue@45 86
Nenue@45 87 headergrad = {'VERTICAL', 0, 0, 0, 1,
Nenue@45 88 1, 0.1, 0.1, 1}, -- header info
Nenue@33 89 headerdrop = {1,1,1,1},
Nenue@45 90 headerblend = 'BLEND',
Nenue@33 91 headeralpha = 1,
Nenue@45 92 headerfontcolor = {1,1,1,1},
Nenue@45 93
Nenue@45 94 backdrop = {1,1,1,1}, -- background frame info
Nenue@56 95 backgrad = {'VERTICAL', 0, 0, 0, .75, 0,0,0, .65},
Nenue@55 96 backblend = 'BLEND',
Nenue@45 97 backalpha = 1,
Nenue@45 98 backborder = {.5,.5,.5,1},
Nenue@45 99 backheader = {.25,.25,.25,1},
Nenue@45 100
Nenue@45 101 frontdrop = {1,1,1,1}, -- foreground frame info
Nenue@56 102 frontgrad = {'VERTICAL', 0, 0, 0, 1, 0,0,0, 0.95},
Nenue@55 103 frontblend = 'BLEND',
Nenue@28 104 frontalpha = 1,
Nenue@45 105 frontborder = {.07,.47,1,1},
Nenue@45 106 frontheader = {1,1,1,1},
Nenue@33 107 tagcolor = {}, -- tag color repository
Nenue@36 108 workspace = 2, -- current profile
Nenue@47 109 last_workspace = 2, -- default workspace to alternate with when just "/dvn" is issued
Nenue@47 110
Nenue@47 111 dock_onshow_fade_time = 2.5,
Nenue@47 112 dock_onshow_fade_from = 1,
Nenue@47 113 dock_onshow_fade_to = 0.2,
Nenue@47 114
Nenue@47 115 dock_alpha_on = 1,
Nenue@47 116 dock_alpha_off = 0.2,
Nenue@47 117 dock_fade_in = 0.15,
Nenue@47 118 dock_fade_out = 0.45,
Nenue@47 119 dock_button_alpha_on = 1,
Nenue@47 120 dock_button_alpha_off = 0.2,
Nenue@50 121 dock_button_fade_in = 0.075,
Nenue@55 122 dock_button_fade_out = 0.075,
Nenue@47 123
Nenue@55 124 movement_fade = true,
Nenue@55 125 movement_fade_time = 0.15,
Nenue@60 126 movement_fade_from = 1,
Nenue@60 127 movement_fade_to = 0,
Nenue@60 128 movement_translation_x = 25,
Nenue@60 129 movement_translation_y = 25,
Nenue@13 130 }
Nenue@9 131
Nenue@66 132 D.console = {}
Nenue@66 133 D.max_channel = 0
Nenue@0 134
Nenue@67 135 D.InWorkspace = function ()
Nenue@67 136 return db.profiles[db.current_profile].workspace
Nenue@67 137 end
Nenue@67 138
Nenue@86 139 local profileTemplate = {
Nenue@86 140 name = function(id, name) return name end,
Nenue@86 141 workspace = function(id, name) return (id ~= 1) end,
Nenue@86 142 current_channel = 1,
Nenue@86 143 default_channel = 1,
Nenue@86 144 num_channels = 1,
Nenue@86 145 max_channel = 1, -- the highest created channel id
Nenue@86 146 enabled = true, -- allow enabled consoles to appear
Nenue@86 147 channels = {
Nenue@86 148 {
Nenue@86 149 index = 1,
Nenue@86 150 signature = 'Main',
Nenue@86 151 x = 100, y = 800,
Nenue@86 152 height = 500, width = 600,
Nenue@86 153 enabled = true
Nenue@86 154 }
Nenue@86 155 },
Nenue@86 156 loadouts = {},
Nenue@86 157 global = {},
Nenue@86 158 tags = {},
Nenue@86 159 char = {
Nenue@86 160 [playerRealm] = {}
Nenue@86 161 },
Nenue@86 162 unlisted = {}
Nenue@86 163 }
Nenue@86 164
Nenue@86 165 --- Applies complex template tables
Nenue@86 166 -- If he value is a function, then it will invoke f(...) and use whatever gets returned
Nenue@86 167 function D.DeepCopy(src, dest, ...)
Nenue@86 168
Nenue@86 169 for k,v in pairs(src) do
Nenue@86 170 if not dest[k] then
Nenue@86 171 oldprint('Rebuilding conf value', k)
Nenue@86 172 if type(v) == 'table' then
Nenue@86 173 dest[k] = {}
Nenue@86 174 D.DeepCopy(v, dest[k], ...)
Nenue@86 175
Nenue@86 176 else
Nenue@86 177 if type(v) == 'function' then
Nenue@86 178 v = v(...)
Nenue@86 179 end
Nenue@86 180 dest[k] = v
Nenue@86 181 end
Nenue@86 182 end
Nenue@86 183 end
Nenue@86 184 end
Nenue@86 185
Nenue@66 186 D.Profile = function (id, name)
Nenue@66 187
Nenue@66 188 if name and not id and db.profilesName[name] then
Nenue@66 189 id = db.profilesName[name]
Nenue@66 190 print('ID located by name, |cFF00FF00'..name..'|r is |cFFFFFF00'.. id..'|r')
Nenue@66 191 end
Nenue@66 192
Nenue@66 193 if not id or not db.profiles[id] then
Nenue@66 194 if not id then
Nenue@66 195 id = #db.profiles+1
Nenue@66 196 print('Generated profile ID: |cFFFFFF00'.. id .. '|r')
Nenue@66 197 end
Nenue@66 198
Nenue@66 199 if not name or db.profilesName[name] then
Nenue@66 200 local newName = name or (id == 1 and 'Main' or 'Profile')
Nenue@66 201 local prefix = newName
Nenue@66 202 local i = 2
Nenue@66 203 while db.profilesName[newName] do
Nenue@66 204 i = i + 1
Nenue@66 205 newName = prefix .. i
Nenue@66 206 end
Nenue@66 207 name = newName
Nenue@66 208 print('Generated profile name: |cFF00FF00'..newName..'|r')
Nenue@66 209 end
Nenue@86 210
Nenue@86 211
Nenue@86 212
Nenue@66 213 print('Creating profile')
Nenue@66 214 db.profilesName[name] = id
Nenue@86 215 db.profiles[id] = {}
Nenue@66 216 end
Nenue@66 217
Nenue@86 218
Nenue@86 219
Nenue@66 220 D.currentProfile = db.profiles[id]
Nenue@66 221 currentProfile = D.currentProfile
Nenue@86 222
Nenue@86 223 D.DeepCopy(profileTemplate, currentProfile, id, name)
Nenue@86 224
Nenue@86 225
Nenue@66 226 currentProfile.char[playerRealm] = currentProfile.char[playerRealm] or {}
Nenue@66 227 if currentProfile.workspace then
Nenue@79 228 DEVIAN_WORKSPACE = true
Nenue@89 229 DEVIAN_PNAME = name
Nenue@89 230 DEVIAN_PID = id
Nenue@66 231 setprinthandler(D.Message)
Nenue@66 232 else
Nenue@79 233 DEVIAN_WORKSPACE = false
Nenue@89 234 DEVIAN_PNAME = ''
Nenue@66 235 print = function() end
Nenue@66 236 end
Nenue@89 237 DEVIAN_PID =id
Nenue@66 238
Nenue@66 239 D.unlisted = currentProfile.unlisted
Nenue@66 240 D.channels = currentProfile.channels
Nenue@66 241 D.tags = currentProfile.tags
Nenue@66 242 D.channelinfo = currentProfile.channels
Nenue@66 243 D.char = currentProfile.char[playerRealm]
Nenue@66 244 D.global = currentProfile.global
Nenue@66 245 D.num_channels = currentProfile.num_channels
Nenue@66 246 D.enabled = currentProfile.enabled
Nenue@66 247 D.sig = {}
Nenue@66 248 D.sigID = {}
Nenue@66 249 D.IDsig = {}
Nenue@72 250 D.dock = _G.DevianDock
Nenue@66 251 D.dock.buttons = D.dock.buttons or {}
Nenue@66 252
Nenue@66 253 return id, name
Nenue@66 254 end
Nenue@66 255
Nenue@66 256 local targetGlobal, targetChar
Nenue@86 257 D.Command = function (cmd)
Nenue@66 258 local list_id, scan_func, reload
Nenue@86 259
Nenue@14 260 local args = {}
Nenue@86 261 if cmd then
Nenue@86 262 local i, j = 0, 0
Nenue@86 263 repeat
Nenue@86 264 i, j = cmd:find("%S+", j+1)
Nenue@86 265 if i and j then
Nenue@86 266 tinsert(args, cmd:sub(i, j))
Nenue@86 267 end
Nenue@86 268
Nenue@86 269 until not(i or j)
Nenue@14 270 end
Nenue@14 271 local mode, tag, dest = unpack(args)
Nenue@0 272
Nenue@86 273
Nenue@14 274 -- no args, toggle ui
Nenue@86 275 if mode == 'rc' then
Nenue@86 276 return D.ResetChannels(self, tag)
Nenue@86 277 elseif mode == 'stack' then
Nenue@14 278 return D:StackFrames()
Nenue@14 279 elseif mode == 'grid' then
Nenue@14 280 return D:DistributeFrames()
Nenue@14 281 elseif mode == 'tag' then -- tagging
Nenue@66 282 return D.Tag(self, tag, dest)
Nenue@73 283 elseif mode == 'new' then
Nenue@73 284 return D.New(self, tag)
Nenue@73 285 elseif mode == 'remove' then
Nenue@73 286 return D.Remove(self, tag)
Nenue@89 287 elseif mode ~= nil then
Nenue@89 288 -- profile selector or save command
Nenue@66 289 if mode == 'save' then
Nenue@66 290 list_id = tonumber(tag)
Nenue@89 291 else
Nenue@89 292 list_id = tonumber(mode)
Nenue@89 293 end
Nenue@89 294
Nenue@89 295 if not list_id then
Nenue@89 296 if db.profilesName[tostring(list_id)] then
Nenue@89 297 list_id = db.profilesName[tostring(list_id)]
Nenue@89 298 else
Nenue@89 299
Nenue@89 300 D:Print(L('Unable to resolve profile ID/name', list_id, dest))
Nenue@89 301 return
Nenue@66 302 end
Nenue@89 303 end
Nenue@89 304
Nenue@89 305
Nenue@89 306 if mode == 'save' then
Nenue@66 307 D.Profile(list_id, dest)
Nenue@66 308 scan_func = D.Save
Nenue@89 309
Nenue@89 310
Nenue@89 311 local name = currentProfile.name
Nenue@89 312 if dest then
Nenue@89 313 dest = dest:gsub("$%s+", ''):gsub("%s+^", '')
Nenue@89 314 if dest then
Nenue@89 315 if name then
Nenue@89 316 db.profilesName[name] = nil
Nenue@89 317 end
Nenue@89 318 db.profiles[list_id].name = dest
Nenue@89 319 db.profilesName[dest] = list_id
Nenue@89 320 end
Nenue@89 321 end
Nenue@89 322
Nenue@89 323
Nenue@89 324 D:Print("Profile |cFFFFFF00".. list_id .."|r:|cFF00FFFF".. name .."|r saved.")
Nenue@66 325 else
Nenue@32 326
Nenue@89 327 if db.profiles[list_id] then
Nenue@89 328 D.LoadMessage ("Switched profiles.")
Nenue@89 329 if list_id ~= db.main_profile then
Nenue@89 330 db.last_profile = list_id
Nenue@89 331 end
Nenue@89 332 db.current_profile = list_id
Nenue@89 333 scan_func = D.Load
Nenue@89 334 else
Nenue@89 335 return D:PrintHelp()
Nenue@89 336 end
Nenue@36 337
Nenue@0 338 end
Nenue@32 339 elseif mode == nil then
Nenue@66 340 list_id = (db.current_profile ~= db.main_profile) and db.main_profile or db.last_profile
Nenue@77 341 D.LoadMessage ("Switched between main and recent profile ("..db.current_profile..' and '..list_id..')')
Nenue@66 342 db.current_profile = list_id
Nenue@66 343 scan_func = D.Load
Nenue@32 344 else
Nenue@89 345
Nenue@89 346
Nenue@32 347 return D:PrintHelp()
Nenue@0 348 end
Nenue@77 349
Nenue@77 350 if not db.profiles[list_id] then
Nenue@77 351 db.profiles[list_id] = {global = {}, char = {} }
Nenue@77 352 D.LoadMessage ("Starting profile #|cFF00FFFF".. list_id..'|r')
Nenue@77 353 end
Nenue@67 354 if not db.profiles[list_id].char[playerRealm] then
Nenue@67 355 db.profiles[list_id].char[playerRealm] = {}
Nenue@67 356 end
Nenue@67 357
Nenue@66 358 targetGlobal = db.profiles[list_id].global
Nenue@66 359 targetChar = db.profiles[list_id].char[playerRealm]
Nenue@32 360
Nenue@67 361
Nenue@66 362 if scan_func then
Nenue@66 363 for id, name, enableState, globalState in D.Addons() do
Nenue@66 364 scan_func(id, name, enableState, globalState)
Nenue@0 365 end
Nenue@0 366 end
Nenue@0 367
Nenue@66 368 if scan_func == D.Load then
Nenue@72 369 _G.ReloadUI()
Nenue@66 370 end
Nenue@66 371 D.Profile(db.current_profile)
Nenue@66 372 end
Nenue@66 373
Nenue@66 374 D.Addons = function()
Nenue@66 375 local playername = UnitName("player")
Nenue@66 376 return function(n, i)
Nenue@66 377 if i >= n then
Nenue@66 378 return nil
Nenue@66 379 end
Nenue@66 380
Nenue@66 381 i = i + 1
Nenue@66 382 local name = GetAddOnInfo(i)
Nenue@66 383 local enableState, globalState = GetAddOnEnableState(playername, i), GetAddOnEnableState(nil, i)
Nenue@66 384 return i, name, enableState, globalState
Nenue@66 385 end, GetNumAddOns(), 0
Nenue@66 386 end
Nenue@66 387
Nenue@66 388 D.Load = function(id, name, charState, globalState)
Nenue@66 389 if targetChar[name] or targetGlobal[name] then
Nenue@66 390 if targetGlobal[name] == 2 then
Nenue@66 391 EnableAddOn(id, true)
Nenue@66 392 elseif targetChar[name] == 2 then
Nenue@66 393 EnableAddOn(id, playerName)
Nenue@66 394 else
Nenue@71 395 if targetChar[name] == 2 and targetGlobal[name] ~= 2 then
Nenue@71 396 DisableAddOn(id)
Nenue@71 397 else
Nenue@71 398 DisableAddOn(id, true)
Nenue@71 399 end
Nenue@66 400 end
Nenue@70 401 --print('load', name, 'global =', targetGlobal[name], 'char =', targetChar[name])
Nenue@0 402 else
Nenue@66 403 tinsert(D.unlisted, name)
Nenue@66 404 end
Nenue@66 405 end
Nenue@66 406 D.Save = function(id, name, charState, globalState)
Nenue@70 407 --print('save', id, name, charState, globalState)
Nenue@66 408 targetGlobal[name] = globalState
Nenue@66 409 targetChar[name] = charState
Nenue@66 410 end
Nenue@57 411
Nenue@66 412 D.Tag = function(self, tag, dest)
Nenue@66 413 local sig
Nenue@66 414 if tag ~= nil and dest ~= nil then
Nenue@66 415 --@debug@
Nenue@66 416 --print(tag, dest)
Nenue@66 417 --@end-debug@
Nenue@66 418
Nenue@66 419 -- convert to ID
Nenue@66 420 if tonumber(dest) == nil then
Nenue@66 421 if D.sigID[dest] then
Nenue@66 422 dest = currentProfile.channels[D.sigID[dest]].index
Nenue@66 423 else
Nenue@66 424 sig = dest
Nenue@66 425 end
Nenue@57 426 else
Nenue@66 427 dest = tonumber(dest)
Nenue@32 428 end
Nenue@66 429 --@debug@
Nenue@66 430 --print('2 tag,dest,sig', tag, dest, sig)--@end-debug@
Nenue@66 431
Nenue@66 432 -- make a new channel?
Nenue@66 433 local channel
Nenue@66 434 if not currentProfile.channels[dest] then
Nenue@66 435 dest = D.max_channel + 1
Nenue@66 436 D:Print(L('New channel created', sig and (dest..':'..sig) or dest ))
Nenue@66 437 channel = D:SetChannel(sig or tag,dest)
Nenue@66 438 else
Nenue@66 439 channel = D.channels[dest]
Nenue@66 440 end
Nenue@66 441 --@debug@
Nenue@66 442 --print('3 tag,dest,channel.sig=',tag, dest, channel.signature)--@end-debug@
Nenue@66 443
Nenue@66 444 if not currentProfile.tags[tag] then -- no tag table?
Nenue@66 445 currentProfile.tags[tag] = {}
Nenue@66 446 end
Nenue@66 447
Nenue@66 448 if currentProfile.tags[tag][dest] then -- is tag set?
Nenue@66 449 currentProfile.tags[tag][dest] = nil
Nenue@66 450 D:Print(L('Tag removed from channel', tag, currentProfile.channels[dest].index, currentProfile.channels[dest].signature))
Nenue@66 451 else
Nenue@66 452 currentProfile.tags[tag][dest] = dest
Nenue@66 453 D:Print(L('Tag added to channel', tag, currentProfile.channels[dest].index, currentProfile.channels[dest].signature))
Nenue@66 454 end
Nenue@66 455 D:UpdateDock()
Nenue@66 456 else
Nenue@66 457 D:Print(L['Command tag help'])
Nenue@0 458 end
Nenue@0 459 end
Nenue@0 460
Nenue@86 461 D.ResetChannels = function(self, profile)
Nenue@86 462 currentProfile.current_channel = 1
Nenue@86 463 currentProfile.primary_channel = 1
Nenue@86 464 currentProfile.channels = {}
Nenue@86 465 D.DeepCopy(profileTemplate.channels, currentProfile.channels)
Nenue@86 466 currentProfile.tags = {}
Nenue@86 467 D.LoadMessage('Profile reset.')
Nenue@86 468 ReloadUI()
Nenue@86 469 end
Nenue@86 470
Nenue@73 471 D.New = function(self, tag)
Nenue@73 472 if tag and not self.sigID[tag] then
Nenue@73 473 local id = D.max_channel + 1
Nenue@73 474 D.SetChannel(tag, id)
Nenue@73 475 end
Nenue@73 476 end
Nenue@0 477
Nenue@73 478 D.Remove = function(self, dest)
Nenue@73 479 dest = D.sigID[dest] or tonumber(dest)
Nenue@73 480 if D.console[dest] and D.channels[dest] then
Nenue@73 481 for tag, tagDest in pairs(D.tags) do
Nenue@73 482 for i = #tagDest, 0 do
Nenue@73 483 -- work downward so we aren't skipping entries
Nenue@73 484 if tagDest[i] == dest then
Nenue@73 485 tremove(tagDest, i)
Nenue@73 486 end
Nenue@73 487 end
Nenue@73 488 end
Nenue@73 489 D.console[dest]:Hide()
Nenue@73 490 D.channels[dest] = nil
Nenue@73 491 tremove(D.console, dest)
Nenue@73 492 tremove(D.dock.buttons, dest)
Nenue@73 493 D:UpdateDock()
Nenue@73 494 D:Print('Removed channel #'..dest)
Nenue@73 495 end
Nenue@73 496 end
Nenue@13 497
Nenue@77 498 --- Queue up a message to appear after UI reload
Nenue@77 499 function D.LoadMessage(msg)
Nenue@77 500
Nenue@77 501 tinsert(_G.DevianLoadMessage, msg)
Nenue@77 502 end
Nenue@77 503
Nenue@18 504 --- Creates a Devian-style output.
Nenue@18 505 -- The first argument describes the channel to output on, and the remaining arguments are concatenated in a manner similar to default print()
Nenue@18 506 -- This becomes the print handler when development mode is active. The original print() function is assigned to oldprint().
Nenue@18 507 -- @param Tag, signature, or numeric index of the channel to output on. Defaults to primary channel.
Nenue@18 508 -- @param ... Output contents.
Nenue@72 509
Nenue@66 510 function D.Message(prefix, ...)
Nenue@67 511 if not currentProfile.workspace then
Nenue@23 512 return D.oldprint(prefix, ...)
Nenue@23 513 end
Nenue@57 514 prefix = tostring(prefix)
Nenue@57 515 if prefix == nil then
Nenue@55 516 prefix = 'nil*'
Nenue@1 517 end
Nenue@9 518
Nenue@18 519 local sendq = {}
Nenue@30 520 local tag, id, tagged
Nenue@13 521 local byName = true
Nenue@18 522 if D.tags[prefix] then
Nenue@18 523 for _, id in pairs(D.tags[prefix]) do
Nenue@18 524 if D.console[id] then
Nenue@18 525 sendq[id] = D.console[id]
Nenue@30 526 tagged = true
Nenue@18 527 end
Nenue@18 528 end
Nenue@18 529 end
Nenue@18 530
Nenue@13 531 if D.sig[prefix] then
Nenue@18 532 sendq[D.sig[prefix].index] = D.sig[prefix]
Nenue@13 533 elseif D.console[prefix] then
Nenue@18 534 sendq[D.console[prefix]] = D.console[prefix]
Nenue@30 535 elseif not tagged then
Nenue@18 536 sendq[D.primary_channel] = D.console[D.primary_channel]
Nenue@13 537 end
Nenue@18 538
Nenue@9 539 -- color me timbers
Nenue@9 540 local pcolor
Nenue@18 541 if (not db.tagcolor[prefix]) and byName then
Nenue@86 542 -- numbers, use white
Nenue@86 543 if prefix:match('^%d+%.%d+') then
Nenue@73 544 pcolor = 'FFFFFF'
Nenue@73 545 else
Nenue@73 546 local c = {
Nenue@73 547 rand(64,255), rand(64,255), rand(64,255)
Nenue@73 548 }
Nenue@73 549 if c[1] > 223 and c[2] > 223 and c[3] > 223 then
Nenue@73 550 c[rand(1,3)] = rand(64,223)
Nenue@73 551 end
Nenue@73 552 db.tagcolor[prefix] = format('%02X%02X%02X', unpack(c))
Nenue@73 553 pcolor = db.tagcolor[prefix]
Nenue@0 554 end
Nenue@73 555 else
Nenue@73 556 pcolor = db.tagcolor[prefix]
Nenue@0 557 end
Nenue@0 558
Nenue@55 559 local buffer = {}
Nenue@0 560 for i = 1, select('#',...) do
Nenue@0 561 local var = select(i, ...)
Nenue@0 562
Nenue@0 563 if type(var) == 'table' then
Nenue@20 564 if type(var.GetName) == 'function' then
Nenue@72 565 var = '[table:'..tostring(var:GetName())..']'
Nenue@20 566 else
Nenue@32 567 var = '<'..tostring(var)..'>'
Nenue@20 568 end
Nenue@20 569
Nenue@0 570 elseif type(var) == 'boolean' then
Nenue@75 571 var = var and 'true' or 'false'
Nenue@0 572 elseif type(var) == 'function' then
Nenue@72 573 var = '['..tostring(var)..']'
Nenue@0 574 elseif type(var) == 'nil' then
Nenue@75 575 var = 'nil'
Nenue@60 576 else
Nenue@60 577 var = tostring(var)
Nenue@0 578 end
Nenue@0 579
Nenue@47 580 insert(buffer, var)
Nenue@0 581 end
Nenue@47 582 local message = concat(buffer, ' ')
Nenue@18 583 for id, channel in pairs(sendq) do
Nenue@55 584 if channel.width < 250 then
Nenue@72 585 prefix = sub(prefix, 0,2)
Nenue@55 586 end
Nenue@73 587 --currentProfile.last_channel = channel.index
Nenue@58 588 channel.out:AddMessage('|cFF'.. pcolor..prefix ..'|r ' .. message, 0.8, 0.8, 0.8, nil, nil, prefix, GetTime())
Nenue@58 589 if not D.dock.buttons[id].newMessage then
Nenue@58 590 D.dock.buttons[id].newMessage = true
Nenue@58 591 D.UpdateBeacon(D.dock.buttons[id])
Nenue@58 592 end
Nenue@18 593 end
Nenue@47 594 wipe(buffer)
Nenue@0 595 end
Nenue@0 596
Nenue@14 597
Nenue@32 598
Nenue@14 599
Nenue@32 600 function D:PrintHelp()
Nenue@32 601 D:Print("|cFFFFFF00/dvn|r",
Nenue@32 602 "\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 603 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 604
Nenue@32 605 D:Print("|cFFFFFF00/resetdvn|r", "- Resets all but profile data SavedVariables.")
Nenue@32 606 D:Print("|cFFFFFF00/cleandvn|r", "- Fully resets SavedVariables, profiles and all.")
Nenue@32 607 end
Nenue@32 608
Nenue@66 609 local blocked = {profiles = true, debugmode = true}
Nenue@66 610 D.SetDefaults = function()
Nenue@72 611 local DevianDB = _G.DevianDB
Nenue@66 612 for k,v in pairs(DevianDB) do
Nenue@66 613 if not blocked[k] then
Nenue@66 614 DevianDB[k] = nil
Nenue@60 615 end
Nenue@60 616 end
Nenue@66 617 for k,v in pairs(defaults) do
Nenue@66 618 if not blocked[k] then
Nenue@66 619 DevianDB[k] = v
Nenue@60 620 end
Nenue@60 621 end
Nenue@73 622
Nenue@77 623 D.LoadMessage "Non-user SavedVars have been reset."
Nenue@72 624 _G.ReloadUI()
Nenue@60 625 end
Nenue@66 626 D.SetDefaultsAll = function ()
Nenue@72 627 _G.DevianDB = nil
Nenue@77 628 D.LoadMessage "All SavedVars wiped."
Nenue@72 629 _G.ReloadUI()
Nenue@66 630 end
Nenue@73 631
Nenue@73 632 D.UnsetColors = function()
Nenue@73 633 db.tagcolor = {}
Nenue@73 634 D:Print('Tag color cache cleared.')
Nenue@73 635 end
Nenue@45 636
Nenue@33 637
Nenue@89 638 function D.ConsoleCommand (cmd)
Nenue@89 639 D:Console_Toggle(cmd)
Nenue@89 640 end
Nenue@87 641
Nenue@66 642
Nenue@66 643 function D:OnInitialize()
Nenue@81 644 L = D.L
Nenue@13 645
Nenue@33 646 -- pull defaults
Nenue@9 647 if not _G.DevianDB then
Nenue@13 648 _G.DevianDB = defaults
Nenue@9 649 end
Nenue@9 650 db = _G.DevianDB
Nenue@47 651 self.db = db
Nenue@0 652
Nenue@66 653 ---
Nenue@77 654 if #_G.DevianLoadMessage >= 1 then
Nenue@77 655 for i, msg in ipairs(_G.DevianLoadMessage) do
Nenue@77 656 D:Print(msg)
Nenue@77 657 end
Nenue@77 658
Nenue@77 659 table.wipe(_G.DevianLoadMessage)
Nenue@0 660 end
Nenue@0 661
Nenue@66 662
Nenue@89 663 -- commands
Nenue@89 664 local cmdlist = {
Nenue@89 665 ['dvn'] = "Command",
Nenue@89 666 ['devian'] = "Command",
Nenue@89 667 ['dvc'] = "ConsoleCommand",
Nenue@89 668 ['dvncolors'] = "UnsetColors",
Nenue@89 669 ['cleandvn'] = "SetDefaultsAll",
Nenue@89 670 ['resetdvn'] = "SetDefaults",
Nenue@89 671 }
Nenue@89 672 for cmd, func in pairs(cmdlist) do
Nenue@89 673 local CMD = cmd:upper()
Nenue@89 674 _G['SLASH_' .. CMD .. '1'] = "/"..cmd
Nenue@89 675
Nenue@89 676 if type(func == 'string') then
Nenue@89 677 print('SLASH_' .. CMD .. '1','/'.. cmd, func)
Nenue@89 678 SlashCmdList[CMD] = D[func]
Nenue@89 679 else
Nenue@89 680 print('SLASH_' .. CMD .. '1','/'.. cmd, func)
Nenue@89 681 SlashCmdList[CMD] = func
Nenue@89 682 end
Nenue@89 683 end
Nenue@89 684
Nenue@66 685 --- initialize the current profile
Nenue@66 686 local id, name = D.Profile(db.current_profile or 1)
Nenue@66 687 D:Print('Using profile |cFFFFFF00'.. id ..'|r: |cFF00FF00'..currentProfile.name..'|r')
Nenue@66 688 if currentProfile.workspace then
Nenue@66 689 D:Print('Workspace: '.. (#currentProfile.channels) .. ' channels, ' .. #currentProfile.tags .. ' tags.')
Nenue@86 690 if D.channels[currentProfile.default_channel] then
Nenue@86 691 D:Print('Default channel: |cFFFFFF00'..currentProfile.default_channel..'|r: |cFF00FFFF'.. D.channels[currentProfile.default_channel].signature..'|r')
Nenue@86 692 end
Nenue@0 693 end
Nenue@13 694
Nenue@86 695
Nenue@66 696 for i, cinfo in pairs(D.channels) do
Nenue@14 697 i = tonumber(i)
Nenue@66 698 if not D.primary_channel then
Nenue@66 699 D.primary_channel = i
Nenue@14 700 end
Nenue@66 701 D:SetChannel(cinfo, i)
Nenue@66 702 D.num_channels = D.num_channels + 1
Nenue@32 703 end
Nenue@86 704 D.primary_channel = D.primary_channel or 1
Nenue@32 705
Nenue@66 706 D.max_channel = max(D.max_channel, currentProfile.max_channel)
Nenue@66 707 if currentProfile.max_channel < D.max_channel then
Nenue@66 708 for i = currentProfile.max_channel, D.max_channel do
Nenue@66 709 D.console[i]:Hide()
Nenue@47 710 end
Nenue@36 711 end
Nenue@36 712
Nenue@66 713 if currentProfile.workspace then
Nenue@66 714 if D.console[currentProfile.current_channel] then
Nenue@69 715 --print('bringing', D.console[currentProfile.current_channel].signature, 'to the front')
Nenue@66 716 D.console[currentProfile.current_channel]:ToFront()
Nenue@66 717 -- bring the current channel to the front
Nenue@47 718 end
Nenue@72 719 _G.DevianDock:Show()
Nenue@66 720 D:UpdateDock()
Nenue@36 721 end
Nenue@66 722 end
Nenue@89 723