Mercurial > wow > devian
comparison Devian.lua @ 36:bec37163b7fe v2.0-beta
rewrote the blocks for '/dvn tag' and SetChannel to be more predictable; currently follows:
/dvn tag <source> <dest>
if <dest> matches a channel, then the tag for <source> is added or removed
if <dest> is a string and it doesn't match a channel, then that channel is created with <dest> as a signature
if <dest> is a number that doesn't match a channel index, then <dest> is set to <highest valid index + 1>, the channel is created under that, and <source> is used as its signature
SetChannel(cinfo, key)
start with an empty table t_info that is filled in as follows:
if key doesn't match a valid index/signature, then a channel is being created
if key does match a valid index, then a channel is being updated
if cinfo is a string, then only the signature value is imposed
if cinfo is a table, the values from that table are imposed
if a channel is being created, then the new channel info is filled in from primary channel, the index is auto-generated, and the signature value is checked for collision, and the information is passed through CreateConsole to form internal assignments
if a channel is being updated, then t_info is populated from the channel data, and any internal table assignments are switched over to t_info
the old tables sink into garbage collection
| author | Nenue |
|---|---|
| date | Sun, 27 Dec 2015 08:19:45 -0500 |
| parents | 3304455a3f45 |
| children | d432f49e340e |
comparison
equal
deleted
inserted
replaced
| 35:3304455a3f45 | 36:bec37163b7fe |
|---|---|
| 6 print('Something has happened...') | 6 print('Something has happened...') |
| 7 end | 7 end |
| 8 Devian = LibStub("AceAddon-3.0"):NewAddon("Devian", "AceConsole-3.0", "AceEvent-3.0") | 8 Devian = LibStub("AceAddon-3.0"):NewAddon("Devian", "AceConsole-3.0", "AceEvent-3.0") |
| 9 local MAJOR, MINOR = 'Devian-1.3', 'r@project-revision@' | 9 local MAJOR, MINOR = 'Devian-1.3', 'r@project-revision@' |
| 10 local D = _G.Devian | 10 local D = _G.Devian |
| 11 local MSG_NEED_DEV_MODE = 'Must be in development mode to use this function.' | |
| 11 local WORKSPACE_ON, WORKSPACE_OFF = 1, 2 | 12 local WORKSPACE_ON, WORKSPACE_OFF = 1, 2 |
| 12 local PLAYER_REALM = UnitName("player") .. '-' .. GetRealmName() | 13 local PLAYER_REALM = UnitName("player") .. '-' .. GetRealmName() |
| 13 local print = _G.print | 14 local print = _G.print |
| 14 local db | 15 local db |
| 15 local defaults = { | 16 local defaults = { |
| 25 fontsize = 13, | 26 fontsize = 13, |
| 26 fontoutline = 'NONE', | 27 fontoutline = 'NONE', |
| 27 headergrad = {'VERTICAL', 0, 0, 0, 0.5, 0.1, 0.1, 0.1, 0.3}, -- header info | 28 headergrad = {'VERTICAL', 0, 0, 0, 0.5, 0.1, 0.1, 0.1, 0.3}, -- header info |
| 28 headerdrop = {1,1,1,1}, | 29 headerdrop = {1,1,1,1}, |
| 29 headeralpha = 1, | 30 headeralpha = 1, |
| 30 backdrop = {0,0,0,1}, -- background frame info | 31 headerfontcolor = {1,0.2,0.2,1}, |
| 32 backdrop = {1,1,1,1}, -- background frame info | |
| 31 backgrad = {'VERTICAL', 0.1, 0.1, 0.1, 0.3, 0, 0, 0, 0.5}, | 33 backgrad = {'VERTICAL', 0.1, 0.1, 0.1, 0.3, 0, 0, 0, 0.5}, |
| 32 backblend = 'MOD', | 34 backblend = 'MOD', |
| 33 backalpha = 0.7, | 35 backalpha = 0.7, |
| 34 backborder = {0,0,1,0.75}, | 36 backborder = {0,0,1,0.75}, |
| 35 frontdrop = {0,0,0,1}, -- foreground frame info | 37 frontdrop = {1,1,1,1}, -- foreground frame info |
| 36 frontgrad = {'VERTICAL', 0.1, 0.1, 0.1, 0.9, 0, 0, 0, 0.9}, | 38 frontgrad = {'VERTICAL', 0.1, 0.1, 0.1, 0.8, 0, 0, 0, 0.6}, |
| 37 frontblend = 'MOD', | 39 frontblend = 'MOD', |
| 38 frontalpha = 1, | 40 frontalpha = 1, |
| 39 frontborder = {1,0,0,1}, | 41 frontborder = {1,0,0,1}, |
| 40 tagcolor = {}, -- tag color repository | 42 tagcolor = {}, -- tag color repository |
| 41 workspace = 1, -- current profile | 43 workspace = 2, -- current profile |
| 42 last_workspace = 2 -- default workspace to alternate with when just "/dvn" is issued | 44 last_workspace = 2 -- default workspace to alternate with when just "/dvn" is issued |
| 43 } | 45 } |
| 44 | 46 |
| 45 local function ScanAddOnList(cmd, ...) | 47 local function ScanAddOnList(cmd, ...) |
| 46 local list_state | 48 local list_state |
| 112 elseif mode == 'tag' then -- tagging | 114 elseif mode == 'tag' then -- tagging |
| 113 if db.workspace == 1 then | 115 if db.workspace == 1 then |
| 114 return D:Print(MSG_NEED_DEV_MODE) | 116 return D:Print(MSG_NEED_DEV_MODE) |
| 115 end | 117 end |
| 116 | 118 |
| 119 local sig | |
| 117 if tag ~= nil and dest ~= nil then | 120 if tag ~= nil and dest ~= nil then |
| 121 --@debug@ | |
| 122 print(tag, dest) | |
| 123 --@end-debug@ | |
| 124 | |
| 118 -- convert to ID | 125 -- convert to ID |
| 119 if tonumber(dest) == nil and D.sigID[dest] then | 126 if tonumber(dest) == nil then |
| 120 dest = db.channels[D.sigID[dest]].index | 127 if D.sigID[dest] then |
| 121 end | 128 dest = db.channels[D.sigID[dest]].index |
| 129 else | |
| 130 sig = dest | |
| 131 end | |
| 132 end | |
| 133 print('2 tag,dest,sig', tag, dest, sig) | |
| 122 | 134 |
| 123 -- make a new channel? | 135 -- make a new channel? |
| 136 local channel | |
| 124 if not db.channels[dest] then | 137 if not db.channels[dest] then |
| 125 dest = db.max_channel + 1 | 138 dest = D.max_channel + 1 |
| 126 D:Print('Creating a new channel for '.. tag) | 139 D:Print('Created channel |cFF88FFFF'.. (sig and (dest..':'..sig) or dest ) .. '|r') |
| 127 D:SetChannel(tag, dest) | 140 channel = D:SetChannel(sig or tag,dest) |
| 128 end | 141 end |
| 142 print('3',tag, dest) | |
| 129 | 143 |
| 130 if db.tags[tag] and db.tags[tag][dest] then | 144 if db.tags[tag] and db.tags[tag][dest] then |
| 131 db.tags[tag][dest] = nil | 145 db.tags[tag][dest] = nil |
| 132 D:Print('Hiding |cFF88FFFF'..tag..'|r messages in |cFFFFFF00'..db.channels[dest].index ..':'.. db.channels[dest].signature) | 146 D:Print('Hiding |cFF88FFFF'..tag..'|r messages in |cFFFFFF00'..db.channels[dest].index ..':'.. db.channels[dest].signature) |
| 133 else | 147 else |
| 163 else | 177 else |
| 164 return D:PrintHelp() | 178 return D:PrintHelp() |
| 165 end | 179 end |
| 166 | 180 |
| 167 -- start the iterating | 181 -- start the iterating |
| 182 if not db[PLAYER_REALM][list_state] then | |
| 183 db[PLAYER_REALM][list_state] = {} | |
| 184 end | |
| 185 if not db.global[list_state] then | |
| 186 db.global[list_state] = {} | |
| 187 end | |
| 188 | |
| 168 local char_list, global_list = db[PLAYER_REALM][list_state], db.global[list_state] | 189 local char_list, global_list = db[PLAYER_REALM][list_state], db.global[list_state] |
| 169 local playername = UnitName("player") | 190 local playername = UnitName("player") |
| 170 | 191 |
| 171 for i = 1, GetNumAddOns() do | 192 for i = 1, GetNumAddOns() do |
| 172 local name = GetAddOnInfo(i) | 193 local name = GetAddOnInfo(i) |
| 330 DevianDB = { | 351 DevianDB = { |
| 331 load_message = "All SavedVars wiped." | 352 load_message = "All SavedVars wiped." |
| 332 } | 353 } |
| 333 ReloadUI() | 354 ReloadUI() |
| 334 end) | 355 end) |
| 356 local blocked = {global = true, [PLAYER_REALM] = true} | |
| 335 self:RegisterChatCommand("resetdvn", function(args) | 357 self:RegisterChatCommand("resetdvn", function(args) |
| 336 for k,v in pairs(DevianDB) do | 358 for k,v in pairs(DevianDB) do |
| 337 if k ~= 'global' then | 359 if not blocked[k] then |
| 338 DevianDB[k] = nil | 360 DevianDB[k] = nil |
| 339 end | 361 end |
| 340 end | 362 end |
| 341 | 363 for k,v in pairs(defaults) do |
| 364 if not blocked[k] then | |
| 365 DevianDB[k] = v | |
| 366 end | |
| 367 end | |
| 342 DevianDB.load_message = "Non-user SavedVars have been reset." | 368 DevianDB.load_message = "Non-user SavedVars have been reset." |
| 343 for k,v in pairs(defaults) do | |
| 344 DevianDB[k] = v | |
| 345 end | |
| 346 ReloadUI() | 369 ReloadUI() |
| 347 end) | 370 end) |
| 348 local cmdlist = { | 371 local cmdlist = { |
| 349 ['dvn'] = ScanAddOnList, | 372 ['dvn'] = ScanAddOnList, |
| 350 ['devian'] = ScanAddOnList, | 373 ['devian'] = ScanAddOnList, |
| 351 ['dvc'] = Console_Toggle, | 374 ['dvc'] = "Console_Toggle", |
| 352 } | 375 } |
| 353 for cmd, func in pairs(cmdlist) do | 376 for cmd, func in pairs(cmdlist) do |
| 354 self:RegisterChatCommand(cmd, func, true) | 377 self:RegisterChatCommand(cmd, func, true) |
| 355 end | 378 end |
| 356 | 379 |
| 396 self:SetChannel(cinfo, i) | 419 self:SetChannel(cinfo, i) |
| 397 self.max_channel = math.max(i, self.max_channel) | 420 self.max_channel = math.max(i, self.max_channel) |
| 398 self.num_channels = self.num_channels + 1 | 421 self.num_channels = self.num_channels + 1 |
| 399 end | 422 end |
| 400 | 423 |
| 424 | |
| 401 for i, channel in pairs(db.channels) do | 425 for i, channel in pairs(db.channels) do |
| 402 if type(channel.docked) == 'table' then | 426 if type(channel.docked) == 'table' then |
| 403 oldprint('docking',i, unpack(channel.docked)) | 427 oldprint('docking',i, unpack(channel.docked)) |
| 404 self.DockFrame(i, unpack(channel.docked)) | 428 self.DockFrame(i, unpack(channel.docked)) |
| 405 end | 429 end |
| 412 setprinthandler(Message) | 436 setprinthandler(Message) |
| 413 print = function(...) | 437 print = function(...) |
| 414 _G.print('Dvn', ...) | 438 _G.print('Dvn', ...) |
| 415 end | 439 end |
| 416 end | 440 end |
| 441 | |
| 442 --- Console frame toggler | |
| 443 -- @paramsig [...] | |
| 444 -- @param ... one or more space-seperated channel keys | |
| 445 function D:Console_Toggle(input) | |
| 446 oldprint(input) | |
| 447 if db.workspace == 1 then | |
| 448 return self:Print(MSG_NEED_DEV_MODE) | |
| 449 end | |
| 450 local search = {} | |
| 451 local n = 0 | |
| 452 if self:GetArgs(input,1) then | |
| 453 repeat | |
| 454 local key, n = self:GetArgs(input,1,n) | |
| 455 if self.sig[key] then | |
| 456 table.insert(search, self.sigID[key]) | |
| 457 elseif self.console[key] then | |
| 458 table.insert(search, tonumber(key)) | |
| 459 end | |
| 460 until n == 1e9 | |
| 461 else | |
| 462 search = self.sigID | |
| 463 end | |
| 464 | |
| 465 db.enabled = (not db.enabled) and true or nil | |
| 466 for i, id in pairs(search) do | |
| 467 oldprint(i, id) | |
| 468 local c = self.console[id] | |
| 469 if db.enabled then | |
| 470 c.enabled = true | |
| 471 c:Show() | |
| 472 if db.current_channel == c.index then | |
| 473 c:ToFront() | |
| 474 end | |
| 475 c:Save() | |
| 476 else | |
| 477 c:Hide() | |
| 478 end | |
| 479 end | |
| 480 | |
| 481 if db.enabled then | |
| 482 self:Print('toggled on: '..table.concat(search, ', ')) | |
| 483 else | |
| 484 self:Print('toggled off: '..table.concat(search, ', ')) | |
| 485 end | |
| 486 end |
