annotate Devian.lua @ 91:bb403e03d82d

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