diff ObjectiveTracker/DefaultTracker.lua @ 37:e84d645c8ab8

- revised the tracker update function to build its complete data list up front and use the values as points of comparison for determining possible out of place blocks, which will be iterated over afterward to remove what wasn't re-used - also entailed revising the exact role of global event handlers and function hooks, limiting their directions of communication so one doesn't end up calling the other multiple or inifinity times - schema handling polish
author Nenue
date Mon, 18 Apr 2016 07:56:23 -0400
parents a487841050be
children 1f8f9cc3d956
line wrap: on
line diff
--- a/ObjectiveTracker/DefaultTracker.lua	Sun Apr 17 13:00:31 2016 -0400
+++ b/ObjectiveTracker/DefaultTracker.lua	Mon Apr 18 07:56:23 2016 -0400
@@ -89,20 +89,28 @@
 
 Default.UpdateTracker = function (handler, reason, id, isNew)
   local print = tprint
-  local tracker = handler.frame
+  local frame = handler.frame
   local blockIndex = 0
 
+  print(format('  |cFFFF8800UpdateTracker|r(%s): %s', handler.name, reason))
   handler.updateReason = reason
-  handler.numWatched = handler:GetNumWatched()
-  if handler.numWatched >= 1 then
+  local numWatched, numAll, watchTable = handler:GetNumWatched(id, isNew)
 
-    print('    |cFF00FF88GetNumWatched:|r',handler.name, handler.numWatched, 'of', handler.numAll)
+  if numWatched >= 1 then
+    if watchTable then
+      print('|cFF00FF00      n     ID    Obj wID Log Blk')
+      for i, w in ipairs(watchTable) do
+        print(format('     %2d => %6d %3d %3d %3s %s', i, w.id, w.numObjectives, w.watchIndex, (w.logIndex or ''), (handler.InfoBlock[w.id] and handler.InfoBlock[w.id]:GetName() or '')))
+      end
+    end
   end
 
+  handler.numWatched = numWatched
+  handler.numAll = numAll
   handler.numBlocks = 0
   handler.currentBlock = 0
-  handler.currentAnchor = tracker.titlebg
-  for blockIndex = 1, handler.numWatched do
+  handler.currentAnchor = frame.titlebg
+  for blockIndex = 1, numWatched do
     local currentBlock = handler:UpdateBlock(blockIndex, id, isNew)
     if currentBlock then
       handler:AddBlock(currentBlock)
@@ -116,39 +124,41 @@
   local numBlocks = handler.numBlocks
   local used = handler.usedBlocks
   local free = handler.freeBlocks
-  print(format('  |cFFFF8800UpdateTracker|r(%s): |cFFFF8800%04X|r --- blocks |cFFFF8800%d|r, (used/free: |cFFFF8800%d|r/|cFFFF8800%d|r)', handler.name, band(reason, handler.updateReasonModule + handler.updateReasonEvents, reason), numBlocks, #used, #free))
-  return tracker.numWatched, tracker.numAll
+  print(format('    (%s): |cFFFF8800%04X|r --- blocks |cFFFF8800%d|r, (used/free: |cFFFF8800%d|r/|cFFFF8800%d|r)', handler.name, band(reason, handler.updateReasonModule + handler.updateReasonEvents, reason), numBlocks, #used, #free))
+  return numWatched, numAll
 end
 
-Default.UpdateBlock = function (handler, blockIndex, id, added)
+Default.UpdateBlock = function (handler, index)
   local print = bprint
-  if not blockIndex then
+  if not index then
     return
   end
-  local info = handler:GetInfo(blockIndex) -- should match up with whatever the internal watch list has
+  local info = handler.WatchList[index] -- should match up with whatever the internal watch list has
   if not info then
     return
   end
-  print('  Updating |cFF00FF00'..handler.displayName..'|r|cFF00FFFF'..blockIndex..'|r|cFF0099FF', info.id ,'|r')
+  print('  Updating |cFF00FF00'..handler.displayName..'|r|cFF00FFFF'..index..'|r|cFF0099FF', info.id ,'|r')
   local frame = handler.frame
   local block = handler:GetBlock(info.id)
 
-  if added then
-    -- do something if the block is being assigned a new thing
-  end
-
   block.handler = handler
   block.info = info
 
-  info.blockIndex = blockIndex
-  if info.questID then handler.QuestBlock[info.questID] = block end
-  if info.logIndex then handler.LogBlock[info.logIndex] = block end
-  if info.watchIndex then handler.WatchBlock[info.watchIndex] = block end
-  handler.BlockInfo[blockIndex] = info
-  local newSchema = handler:UpdateObjectives(block)
-  if newSchema and newSchema ~= blockSchema then
-    T.UpdateSchema('block', newSchema)
+  info.blockIndex = index
+  if info.id then
+    print('  storing id', info.id, 'for', block:GetName())
+    handler.InfoBlock[info.id] = block
   end
+  if info.logIndex then
+    print('  storing logIndex', info.logIndex, 'for', block:GetName())
+    handler.LogBlock[info.logIndex] = block
+  end
+  if info.watchIndex then
+    print('  storing watchIndex', info.watchIndex, 'for', block:GetName())
+    handler.WatchBlock[info.watchIndex] = block
+  end
+  handler.BlockInfo[index] = info
+  handler:UpdateObjectives(block)
 
   block.title:SetText(info.title)
 
@@ -201,15 +211,20 @@
     tagPoint, tagAnchor, tagRelative = handler:AddTag(block, 'completionTag', tagPoint, tagAnchor, tagRelative)
   end
 
+  if info.schema then
+    block.schema = info.schema
+  end
+
   if info.statusKey and (Devian and Devian.InWorkspace()) then
-    block.debugText:SetText(info.statusKey)
+    block.debugText:SetText(tostring(info.statusKey) .. ' ' .. tostring(block.posIndex) .. ' '.. tostring(info.logIndex))
     block.debugText:Show()
   end
   return block
 end
 
-Default.UpdateObjectives = function(handler, block, block_schema)
+Default.UpdateObjectives = function(handler, block)
   local print = lprint
+  local block_schema = block.schema
   local info = block.info
   print('  |cFF00FF00default.objectives', block:GetName())
   -- reset the starting positions
@@ -271,10 +286,10 @@
   T:Update()
 end
 Default.Open = function(handler, block)
-  T:Update(handler.watchReasonModule)
+  T:Update(handler.updateReasonModule)
 end
 Default.Remove = function(handler, block)
-  T:Update(handler.watchReasonModule)
+  T:Update(handler.updateReasonModule)
 end
 Default.Report = function(handler, block)
   print('Stats:', handler.numWatched,'items tracked,', handler.numBlocks,'blocks assigned.')
@@ -296,7 +311,7 @@
   self.initialButton = nil
   self.modChatLink = nil
   self.modQuestWatch = nil
-  T:Update(self.handler.updateReasonModule)
+  --T:Update(self.handler.updateReasonModule)
   print('|cFFFF8800'..tostring(self:GetName())..':MouseUp()|r')
 end
 Default.OnMouseDown = function(self, button)