diff 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
line wrap: on
line diff
--- a/Devian.lua	Sun Dec 27 03:51:17 2015 -0500
+++ b/Devian.lua	Sun Dec 27 08:19:45 2015 -0500
@@ -8,6 +8,7 @@
 Devian = LibStub("AceAddon-3.0"):NewAddon("Devian", "AceConsole-3.0", "AceEvent-3.0")
 local MAJOR, MINOR = 'Devian-1.3', 'r@project-revision@'
 local D = _G.Devian
+local MSG_NEED_DEV_MODE = 'Must be in development mode to use this function.'
 local WORKSPACE_ON, WORKSPACE_OFF = 1, 2
 local PLAYER_REALM = UnitName("player") .. '-' .. GetRealmName()
 local print = _G.print
@@ -27,18 +28,19 @@
   headergrad = {'VERTICAL', 0, 0, 0, 0.5, 0.1, 0.1, 0.1, 0.3}, -- header info
   headerdrop = {1,1,1,1},
   headeralpha = 1,
-  backdrop = {0,0,0,1},                                        -- background frame info
+  headerfontcolor = {1,0.2,0.2,1},
+  backdrop = {1,1,1,1},                                        -- background frame info
   backgrad = {'VERTICAL', 0.1, 0.1, 0.1, 0.3, 0, 0, 0, 0.5},
   backblend = 'MOD',
   backalpha = 0.7,
   backborder = {0,0,1,0.75},
-  frontdrop = {0,0,0,1},                                       -- foreground frame info
-  frontgrad = {'VERTICAL', 0.1, 0.1, 0.1, 0.9, 0, 0, 0, 0.9},
+  frontdrop = {1,1,1,1},                                       -- foreground frame info
+  frontgrad = {'VERTICAL', 0.1, 0.1, 0.1, 0.8, 0, 0, 0, 0.6},
   frontblend = 'MOD',
   frontalpha = 1,
   frontborder = {1,0,0,1},
   tagcolor = {},   -- tag color repository
-  workspace = 1,   -- current profile
+  workspace = 2,   -- current profile
   last_workspace = 2 -- default workspace to alternate with when just "/dvn" is issued
 }
 
@@ -114,18 +116,30 @@
       return D:Print(MSG_NEED_DEV_MODE)
     end
 
+    local sig
     if tag ~= nil and dest ~= nil then
+      --@debug@
+      print(tag, dest)
+      --@end-debug@
+
       -- convert to ID
-      if tonumber(dest) == nil and D.sigID[dest] then
-        dest = db.channels[D.sigID[dest]].index
+      if tonumber(dest) == nil then
+        if D.sigID[dest] then
+          dest = db.channels[D.sigID[dest]].index
+        else
+          sig = dest
+        end
       end
+      print('2 tag,dest,sig', tag, dest, sig)
 
       -- make a new channel?
+      local channel
       if not db.channels[dest] then
-        dest = db.max_channel + 1
-        D:Print('Creating a new channel for '.. tag)
-        D:SetChannel(tag, dest)
+        dest = D.max_channel + 1
+        D:Print('Created channel |cFF88FFFF'.. (sig and (dest..':'..sig) or dest ) .. '|r')
+        channel = D:SetChannel(sig or tag,dest)
       end
+      print('3',tag, dest)
 
       if db.tags[tag] and db.tags[tag][dest] then
         db.tags[tag][dest] = nil
@@ -165,6 +179,13 @@
   end
 
   -- start the iterating
+  if not db[PLAYER_REALM][list_state] then
+    db[PLAYER_REALM][list_state] = {}
+  end
+  if not db.global[list_state] then
+    db.global[list_state] = {}
+    end
+
   local char_list, global_list = db[PLAYER_REALM][list_state], db.global[list_state]
   local playername = UnitName("player")
 
@@ -332,23 +353,25 @@
     }
     ReloadUI()
     end)
+  local blocked = {global = true, [PLAYER_REALM] = true}
   self:RegisterChatCommand("resetdvn", function(args)
     for k,v in pairs(DevianDB) do
-      if k ~= 'global' then
+      if not blocked[k] then
         DevianDB[k] = nil
       end
     end
-
+    for k,v in pairs(defaults) do
+      if not blocked[k] then
+        DevianDB[k] = v
+      end
+    end
     DevianDB.load_message = "Non-user SavedVars have been reset."
-    for k,v in pairs(defaults) do
-      DevianDB[k] = v
-    end
     ReloadUI()
   end)
   local cmdlist = {
     ['dvn'] = ScanAddOnList,
     ['devian'] = ScanAddOnList,
-    ['dvc'] = Console_Toggle,
+    ['dvc'] = "Console_Toggle",
   }
   for cmd, func in pairs(cmdlist) do
     self:RegisterChatCommand(cmd, func, true)
@@ -398,6 +421,7 @@
     self.num_channels = self.num_channels + 1
   end
 
+
   for i, channel in pairs(db.channels) do
     if type(channel.docked) == 'table' then
       oldprint('docking',i, unpack(channel.docked))
@@ -413,4 +437,50 @@
   print = function(...)
     _G.print('Dvn', ...)
   end
+end
+
+--- Console frame toggler
+-- @paramsig [...]
+-- @param ... one or more space-seperated channel keys
+function D:Console_Toggle(input)
+  oldprint(input)
+  if db.workspace == 1 then
+    return self:Print(MSG_NEED_DEV_MODE)
+  end
+  local search = {}
+  local n = 0
+  if self:GetArgs(input,1) then
+    repeat
+      local key, n = self:GetArgs(input,1,n)
+      if self.sig[key] then
+        table.insert(search, self.sigID[key])
+      elseif self.console[key] then
+        table.insert(search, tonumber(key))
+      end
+    until n == 1e9
+  else
+    search = self.sigID
+  end
+
+  db.enabled = (not db.enabled) and true or nil
+  for i, id in pairs(search) do
+    oldprint(i, id)
+    local c = self.console[id]
+    if db.enabled then
+      c.enabled = true
+      c:Show()
+      if db.current_channel == c.index then
+        c:ToFront()
+      end
+      c:Save()
+    else
+      c:Hide()
+    end
+  end
+
+  if db.enabled then
+    self:Print('toggled on: '..table.concat(search, ', '))
+  else
+    self:Print('toggled off: '..table.concat(search, ', '))
+  end
 end
\ No newline at end of file