diff ObjectiveTracker/Quests.lua @ 40:03ed70f846de

- move block accessors into a new file - define a tMove function for reconciling the free/used tables as needed - when retrieving an old block frame, confirm ID still matches; resolves multiple watch items on one block - stop any animations when a block is freed; resolves stuck flare graphics
author Nenue
date Sun, 24 Apr 2016 14:15:25 -0400
parents 92534dc793f2
children
line wrap: on
line diff
--- a/ObjectiveTracker/Quests.lua	Thu Apr 21 16:43:37 2016 -0400
+++ b/ObjectiveTracker/Quests.lua	Sun Apr 24 14:15:25 2016 -0400
@@ -13,7 +13,7 @@
 local wipeall = B.wipeall
 local lprint, iprint, tprint = B.print('Line'), B.print('Info'), B.print('Tracker')
 local print = tprint
-
+local fprint = B.print('Frame')
 
 
 local superTrackQuestID, playerMoney, inScenario, showPOIs
@@ -71,7 +71,7 @@
   end
 
   Default.UpdateObjectives(self, block, block_schema, displayObjectives)
-  return block_schema
+  return 0, block_schema
 end
 
 Quest.UpdateLine = function(handler, block, data)
@@ -86,45 +86,6 @@
 Quest.QuestBlock = {}
 Quest.LogBlock = {}
 Quest.LogInfo = {}
-function Quest:FreeBlock (block)
-  local used = Quest.usedBlocks
-  local free = Quest.freeBlocks
-  local reason = ''
-  local doRelease = false
-  local info = block.info
-  local questID = info.questID
-  local logIndex = info.logIndex
-
-  if info.posIndex then
-    if used[info.posIndex] == block then
-      doRelease = true
-      reason = 'posIndex mismatch'
-    end
-  elseif logIndex then
-    if not IsQuestWatched(logIndex) then
-      reason = 'not being watched'
-    elseif not self.LogBlock[logIndex] then
-      doRelease = true
-      reason = 'missing logBlock entry'
-    elseif (self.LogBlock[logIndex] ~= block) then
-      doRelease = true
-      reason = 'different block using index'
-    end
-  elseif info.questID then
-    if not GetQuestLogIndexByID(info.questID) then
-      doRelease = true
-      reason = 'no identifiable quest log entry'
-    end
-  end
-
-
-  if doRelease then
-    print('  |cFF00FF00FreeBlock (' .. block:GetName() .. '):', reason)
-    block:Hide()
-    tremove(used, info.posIndex)
-    tinsert(free, block)
-  end
-end
 
 Quest.OnRemoved = function(block)
 
@@ -139,12 +100,14 @@
 
 local watchesChecked = {}
 local infosChecked = {}
-local blocksChecked = {}
 local GetQuestWatchIndex = GetQuestWatchIndex
 --- Get a total of things to show, and straighten out the index while we're at it
 --- Return the number shown, total in log, and the info table to parse
+local blocksChecked = {}
 Quest.GetNumWatched = function (self, id, added)
   local print = self.print
+  B.print('Block')('########')
+  B.print('Block')('########')
   superTrackQuestID = GetSuperTrackedQuestID()
   playerMoney = GetMoney();
   inScenario = C_Scenario.IsInScenario();
@@ -155,19 +118,20 @@
   print('GetNumWatched', self.name, numWatched, 'of', numAll)
   local start, limit = 1, numAll
 
-  --- start a list of blocks affected by this function
-  wipe(blocksChecked)
   if id and not added then
+    -- if a particular id is supplied, add to checklist
     if self.InfoBlock[id] then
-      tinsert(blocksChecked, self.InfoBlock[id])
+      blocksChecked[self.InfoBlock[id]] = self.InfoBlock[id]
     end
   end
 
+  --- Start complicated frame-recycling bullshit
   for logIndex = start, limit do
     local reason1, reason2 = '', ''
     local title, level, suggestedGroup, isHeader, isCollapsed, isComplete, frequency, questID, startEvent, displayQuestID, isOnMap, hasLocalPOI, isTask, isStory = GetQuestLogTitle(logIndex)
     local watchIndex = GetQuestWatchIndex(logIndex)
 
+    -- check if: the watch data pointers don't match
     if watchIndex and watchIndex >= bottomIndex then
       local watchInfo = self.WatchInfo[watchIndex]
       local watchBlock = self.WatchBlock[watchIndex]
@@ -178,34 +142,39 @@
       if watchBlock and watchBlock.info.questID ~= questID then
         print('GetNumWatched', 'trimming WatchBlock ['..watchIndex..'] =/=', watchBlock:GetName())
         self.WatchBlock[watchIndex] = nil
-        tinsert(blocksChecked, watchBlock)
+        blocksChecked[watchBlock] = watchBlock
       end
     end
 
+    -- check if: the logIndex pointer doesn't match
     local logBlock = self.LogBlock[logIndex]
     if logBlock and logBlock.info.questID ~= questID then
-      --print('    |cFFBBFF00GetNumWatched: trimming LogBlock ['..logIndex..'] =/=', logBlock:GetName())
+      print('GetQuests', 'replace info', logBlock.info.questID, '->', questID)
       self.LogBlock[logIndex] = nil
-      tinsert(blocksChecked, logBlock)
+      blocksChecked[logBlock] = logBlock
     end
 
+    -- add to watch index if: the questID is non-zero
     if questID ~= 0 then
       self.Info[questID] = self:GetInfo(logIndex, watchIndex)
-      --print('    |cFF44BBFFGetNumWatched:|r map', questID, 'to', logIndex, (watchIndex and ('('..watchIndex..')') or ''))
+      print('GetQuests', format('request info |cFF00FF00%2d|r |cFFFFFF00%6d|r |cFFFF4400%3s|r', logIndex, questID, tostring(watchIndex or '')))
     end
   end
 
-  --- remove any orphaned blocks from view and, if possible, free it for re-use
-  for i, block in ipairs(blocksChecked) do
-    if not GetQuestLogIndexByID(block.info.questID, 'player') then
-      print('GetNumWatched', 'iterating a block without an index |cFFBBFF00'.. block:GetName()..'|r')
-      block:Hide()
-      self:FreeBlock(block)
+  --- After GetInfo pass, look for any non-conformant blocks and deal with them
+  for _, block in pairs(blocksChecked) do
+    local logIndex = GetQuestLogIndexByID(block.info.questID, 'player')
+    -- free if: logIndex doesn't resolve
+    if not logIndex then
+      B.print('Block')('GetNumWatched', '|cFFBBFF00block has no index '.. block:GetName()..'|r')
+      self:ClearBlock(block)
+    -- hide if: logIndex isn't being watched
+    elseif not IsQuestWatched(block.info.logIndex) then
+      B.print('Block')('GetNumWatched', '|cFFBBFF00fade from list '.. block:GetName()..'|r')
+      -- todo: figure out why animation gets clobbered
+      self:ClearBlock(block)
     end
-    if not IsQuestWatched(block.info.logIndex) then
-      print('GetNumWatched', 'hiding untracked quest |cFFBBFF00'.. block:GetName()..'|r')
-      block:Hide()
-    end
+    blocksChecked[block] = nil
   end
 
   self.numWatched = numWatched