diff Devian.lua @ 18:01c32c98e72a v1.4

LuaDoc info added Removal of release tagged debug output /dvn tag <prefix> <channel> can be applied to multiple channels, and re-using the command will toggle that output off SetChannel data clobbering fixed Message prefix coloring fixed
author Nenue
date Sun, 20 Dec 2015 18:27:26 -0500
parents 48a1d9c14af5
children df098747b31d
line wrap: on
line diff
--- a/Devian.lua	Sun Dec 20 02:26:36 2015 -0500
+++ b/Devian.lua	Sun Dec 20 18:27:26 2015 -0500
@@ -9,9 +9,7 @@
 local STATE_LOW, STATE_HIGH = 1, 2
 local PLAYER_REALM = UnitName("player") .. '-' .. GetRealmName()
 local DEVIAN_FRAME = 'DevianConsole'
-local print = function(...)
-  _G.print('Dvn', ...)
-end
+local print = _G.print
 local db
 local defaults = {
   ['global'] = {[STATE_LOW] = {}, [STATE_HIGH] = {}},
@@ -60,18 +58,18 @@
     return D:DistributeFrames()
   elseif mode == 'tag' then -- tagging
     if tag ~= nil and dest ~= nil then
-      if not D.console[dest] and not D.sig[dest] then
-        local sig = dest:match('%a')
-        local id = dest:match('%d')
-        if not id then
-          id = self.last_channel + 1
-        end
-        if not sig then
-          sig = tag
-        end
-        D:SetChannel(sig, id)
+      local channel = D:SetChannel(dest:match('%a'), dest:match('%d'))
+      if not D.tags[tag] then
+        D.tags[tag] = {}
       end
-      D:Print('Assigning |cFFFFFF00'..tag..'|r to |cFF00FFFF'.. dest .. '|r')
+      if D.tags[tag][channel.index] then
+        D.tags[tag][channel.index] = nil
+        D:Print('Removed |cFFFFFF00'..tag..'|r from |cFF00FFFF'.. dest .. '|r')
+      else
+        D.tags[tag][channel.index] = channel.index
+        D:Print('Assigning |cFFFFFF00'..tag..'|r to |cFF00FFFF'.. dest .. '|r')
+      end
+
     else
       D:Print('Usage: /dvn tag <prefix> <console name or number>')
     end
@@ -232,7 +230,8 @@
     end
 end
 
--- Bring console to the front
+--- Brings the console to the front.
+-- Frame method used to bring a console frame to the front of the display stack.
 local function Console_ToFront(c)
   --print(D.raise_ct, 'Raising', c.signature)
   --print(unpack(db.frontdrop))
@@ -243,6 +242,11 @@
   c.out.backdrop:SetTexture(unpack(db.frontdrop))
   c.out.backdrop:SetGradientAlpha(unpack(db.frontgrad))
   c.out.backdrop:SetBlendMode(db.frontblend)
+  D.current_channel = c.index
+
+  for _, part in pairs(c.border) do
+    part:SetTexture(1,0,0,1)
+  end
 
   for id, bc in pairs(D.console) do
     if id ~= c.index then
@@ -253,15 +257,21 @@
       bc.out.backdrop:SetTexture(unpack(db.backdrop))
       bc.out.backdrop:SetGradientAlpha(unpack(db.backgrad))
       bc.out.backdrop:SetBlendMode(db.backblend)
+
+      for _, part in pairs(bc.border) do
+        part:SetTexture(0,0,0.5,0.6)
       end
+    end
+
   end
 
 end
 
--- Generate a console frame
--- @paramsig id, vars
--- @param id channel number
--- @param vars alternative config, else uses db.channels[id]
+--- Constructs the frame object for a console channel
+-- Initializes the console channel at a specified index.
+-- Configuration data can be overridden by passing a desired settings table.
+-- @param i Numeric index of the channel as it manifests in db.channels
+-- @param vars Optional settings table to be used.
 local function CreateConsole(i, vars)
 
   if not vars then
@@ -302,30 +312,38 @@
   return f
 end
 
--- Print to Devian output
--- @paramsig tag, ...
--- @param tag channel signature or number used to select console
--- @param ... print arguments
+--- Creates a Devian-style output.
+-- The first argument describes the channel to output on, and the remaining arguments are concatenated in a manner similar to default print()
+-- This becomes the print handler when development mode is active. The original print() function is assigned to oldprint().
+-- @param Tag, signature, or numeric index of the channel to output on. Defaults to primary channel.
+-- @param ... Output contents.
 local function Message(prefix, ...)
   if prefix == nil then
     prefix = 1
   end
 
-  local channel
+  local sendq = {}
+  local tag, id
   local byName = true
+  if D.tags[prefix] then
+    for _, id in pairs(D.tags[prefix]) do
+      if D.console[id] then
+        sendq[id] = D.console[id]
+      end
+    end
+  end
+
   if D.sig[prefix] then
-    channel = D.sig[prefix]
+    sendq[D.sig[prefix].index] = D.sig[prefix]
   elseif D.console[prefix] then
-    channel = D.console[prefix]
-    byName = nil
+    sendq[D.console[prefix]] = D.console[prefix]
   else
-    channel = D.console[1]
+    sendq[D.primary_channel] = D.console[D.primary_channel]
   end
+
   -- color me timbers
   local pcolor
-  if D.tags[prefix] then
-    pcolor = db.tags[prefix]
-  elseif byName then
+  if (not db.tagcolor[prefix]) and byName then
     local c  = {0, 0, 0 }
     local max = string.len(prefix)
     for i = 1, max, 3 do
@@ -342,10 +360,11 @@
         c[k] = 255
       end
     end
-    D.tags[prefix] = string.format('%02X%02X%02X', unpack(c))
+    db.tagcolor[prefix] = string.format('%02X%02X%02X', unpack(c))
   end
+  pcolor = db.tagcolor[prefix]
 
-  local buffer = {'|cFF'.. D.tags[prefix]..prefix ..'|r'}
+  local buffer = {'|cFF'.. pcolor..prefix ..'|r'}
   for i = 1, select('#',...) do
     local var = select(i, ...)
 
@@ -361,11 +380,14 @@
 
     table.insert(buffer, var)
   end
-  channel.out:AddMessage(table.concat(buffer, ' '))
+  local message = table.concat(buffer, ' ')
+  for id, channel in pairs(sendq) do
+    channel.out:AddMessage(message)
+  end
   table.wipe(buffer)
 end
 
--- Spaces each frame evenly across the screen
+--- Spaces each frame evenly across the screen.
 function D:DistributeFrames() --
   --print('frame grid:', max, num_side)
   local max = self.num_channels
@@ -387,8 +409,7 @@
 
 end
 
--- Place all frames stacked beneath the primary frame
--- @paramsig
+--- Place all frames stacked beneath the primary frame.
 function D:StackFrames()
   local last
   for i, frame in pairs(self.console) do
@@ -404,32 +425,51 @@
   end
 end
 
--- Creates or updates a console frame
--- @paramsig cinfo [, i]
--- @param cinfo an array from db.channels[x] or the desired string signature
--- @param id when set, the console at that index will be assigned all parameters in cinfo
+--- Updates a console "channel" entry, generating a new one if necessary.
+-- Config data will be take from cinfo. If cinfo is a string, then only channel signature is set. The remaining variables are filled in from the primary channel.
+-- i can be given to select a specific channel table entry to work on. Otherwise, it will just create a new channel and the frame associated with it.
+-- @usage cinfo [, i]
+-- @param cinfo Config variables table, or a string to be used as channel signature
+-- @param i Console index. If valid, settings will be inherited from that channel.
 function D:SetChannel(cinfo, i)
   --print('join:', i , cinfo)
   local t_info = {}
+  local dbvars = db.channels[self.primary_channel]
+  if type(cinfo) == 'string' then
+    local signame = tostring(cinfo)
+    t_info.signature = signame
+  end
+
   if type(cinfo) ~= 'table' then
-    t_info.signature = tostring(cinfo)
     cinfo = {}
   end
-  local srcdb = db.channels[self.primary_channel]
-  if i ~= nil then
+
+  if i then
     i = tonumber(i)
     if db.channels[i] then
-      --print('pull vars from '..db.channels[i].signature)
-      cinfo = db.channels[i]
-      srcdb = cinfo
+      dbvars = db.channels[i]
+    else
+      -- if there is no channels[i], then we need to check for sig collision
+      local sigvar = signame
+      local j = 2
+      while D.sig[sigvar] do
+        sigvar = signame .. j
+        j = j + 1
+      end
+      t_info.signature = sigvar
     end
   end
 
-  for k,v in pairs(srcdb) do
+  if not (cinfo.signature or t_info.signature) then
+    t_info.signature = 'Console'..i
+  end
+
+  for k,v in pairs(dbvars) do
     if not t_info[k] then
       if cinfo[k] then
-        --print('- pulling', k..':',v)
         t_info[k] = cinfo[k]
+      elseif db.channels[self.primary_channel][k] then
+        t_info[k] = db.channels[self.primary_channel][k]
       end
     end
   end
@@ -439,13 +479,16 @@
     t_info.y = t_info.y - 20
     db.channels[i] = t_info
   end
+
   if not self.console[i] then
     self.console[i] = CreateConsole(i, t_info)
   end
+  local channel = self.console[i]
 
-  self.sig[cinfo.signature] = self.console[i]
-  self.sigID[cinfo.signature] = i
-  self.IDsig[i] = cinfo.signature
+  self.sig[t_info.signature] = channel
+  self.sigID[t_info.signature] = i
+  self.IDsig[i] = t_info.signature
+  return channel
 end
 
 function D:OnEnable()
@@ -489,11 +532,11 @@
     end
   end
 
-  -- copy tags
-  self.tags = {}
-  for n, c in pairs(db.tags) do
-    self.tags[n] = c
+
+  if not db.tags then
+    db.tags = {}
   end
+  self.tags = db.tags
   if cherry then
     D:Print(cherry)
   end
@@ -520,6 +563,17 @@
     end
     self.num_channels = self.num_channels + 1
   end
-  setprinthandler(Message)
+
+  if self.console[db.current_channel] then
+    self.console[db.current_channel]:ToFront()
+  end
+
+  -- only do this in dev mode
+  if db.enabled == false then
+    setprinthandler(Message)
+    print = function(...)
+      _G.print('Dvn', ...)
+    end
+  end
   print(MAJOR, MINOR)
 end
\ No newline at end of file