Mercurial > wow > buffalo2
diff ObjectiveTracker/Achievements.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 | 69d03f8e293e |
children | 1f8f9cc3d956 |
line wrap: on
line diff
--- a/ObjectiveTracker/Achievements.lua Sun Apr 17 13:00:31 2016 -0400 +++ b/ObjectiveTracker/Achievements.lua Mon Apr 18 07:56:23 2016 -0400 @@ -11,53 +11,66 @@ local GetTime, GetAchievementNumCriteria, GetAchievementCriteriaInfo = GetTime, GetAchievementNumCriteria, GetAchievementCriteriaInfo local GetNumTrackedAchievements, GetTrackedAchievements, GetAchievementInfo = GetNumTrackedAchievements, GetTrackedAchievements, GetAchievementInfo local Default, Cheevs = T.DefaultHandler, T.Cheevs -local print = B.print('Tracker') -local lprint = B.print('Line') -local iprint = B.print('Info') +local wipe = table.wipe +local print, bprint, lprint, iprint = B.print('Tracker'), B.print('Block'), B.print('Line'), B.print('iprint') --- Data retrieval -Cheevs.GetNumWatched = function(self) - print('|cFF00FF00' .. GetTime()) - Cheevs.trackedCheevs = {GetTrackedAchievements()} - return GetNumTrackedAchievements() -end -Cheevs.GetInfo = function(self, watchIndex) - --- step 1: confirm primary data and begin an entry if needed - local cheevID = Cheevs.trackedCheevs[watchIndex] - local id, name, points, completed, month, day, year, description, flags, icon, rewardText, isGuildAch, wasEarnedByMe, earnedBy = GetAchievementInfo(cheevID) - if not id then return false end +Cheevs.GetNumWatched = function(self, targetID, isNew) + local trackedList = {GetTrackedAchievements() } + local numWatched, numAll = #trackedList, #self.WatchList + print(' |cFF00FF88GetNumWatched:|r',self.name, numWatched, ' ('..numAll..' recorded)') + local start = 1 + local limit = max(numAll, #trackedList) + if targetID then + if not isNew and self.Info[targetID] then + -- if it's only an update, we can limit the scope + start = self.Info[targetID].watchIndex + print(' |cFF0088FFGetNumWatched: limit selection to['..start..'-'..limit..']') + if self.InfoBlock[targetID] then + self.InfoBlock[targetID]:Hide() + end - if not self.Info[cheevID] then self.Info[cheevID] = {} end - local c = self.Info[cheevID] - local numObjectives = GetAchievementNumCriteria(cheevID) - - local tagInfo = {} - local objectives = c.objectives or {} - for i = 1, numObjectives do - local description, type, completed, quantity, requiredQuantity, characterName, flags, assetID, quantityString, criteriaID = GetAchievementCriteriaInfo(cheevID, i) - local line = objectives[i] or {} - line.objectiveIndex = i - line.cheevID = cheevID - line.text = description - line.type = type - line.finished = completed - line.value = quantity - line.maxValue = requiredQuantity - line.characterName = characterName - line.flags = flags - line.assetID = assetID - line.quantityString = quantityString - line.criteriaID = criteriaID - objectives[i] = line + end end + for index = start, limit do + if index > numWatched then + self.WatchList[index] = nil + print(' % dropping watch entry #'..index) + else + local cheevID = trackedList[index] + if not self.Info[cheevID] then + self.Info[cheevID] = self:GetInfo(cheevID, index) + else + print(' |cFF00FFBBGetInfo:', cheevID, 'already pulled') + end + self:GetObjectives(cheevID) + local info = self.Info[cheevID] + local watchBlock = self.WatchBlock[cheevID] + + self.Info[cheevID].watchIndex = index + self.WatchList[index] = info + end + end + + numAll = #self.WatchList + return numWatched, numAll, self.WatchList +end +Cheevs.GetInfo = function(self, cheevID, watchIndex) + --- step 1: confirm primary data and begin an entry if needed + local id, name, points, completed, month, day, year, description, flags, icon, rewardText, isGuildAch, wasEarnedByMe, earnedBy = GetAchievementInfo(cheevID) + if not id then return nil end + + print(' |cFF44AAFFGetInfo: pulling', id..',', name, earnedBy) + + + self.Info[cheevID] = self.Info[cheevID] or {} + local c = self.Info[cheevID] local rewards = {} - print(' |cFF0088FFGetInfo|r:', watchIndex, '|cFF00FFFF', name) + c.schema = 'achievement' c.rewardInfo = rewards - c.numObjectives = numObjectives - c.objectives = objectives c.type = 'Cheevs' c.title = name c.points = points @@ -73,44 +86,84 @@ c.wasEarnedByMe = wasEarnedByMe c.earnedBy = earnedBy + local tagInfo = {} c.tagInfo = tagInfo c.watchIndex = watchIndex c.id = cheevID c.cheevID = cheevID + + self.Info[cheevID] = c self.WatchInfo[watchIndex] = c - return self.Info[cheevID] + return c +end + +Cheevs.GetObjectives = function(self, cheevID) + local c = self.Info[cheevID] + c.numObjectives = GetAchievementNumCriteria(cheevID) + c.objectives = c.objectives or {} + for i = 1, c.numObjectives do + local description, type, completed, quantity, requiredQuantity, characterName, flags, assetID, quantityString, criteriaID = GetAchievementCriteriaInfo(cheevID, i) + local line = c.objectives[i] or {} + line.objectiveIndex = i + line.cheevID = cheevID + line.text = description + line.type = type + line.finished = completed + line.value = quantity + line.maxValue = requiredQuantity + line.characterName = characterName + line.flags = flags + line.assetID = assetID + line.quantityString = quantityString + line.criteriaID = criteriaID + c.objectives[i] = line + + print(' |cFF44FFDDGetObjectives:|r', i, type, description, quantityString) + end end --- Content handlers Cheevs.UpdateLine = function(handler, block, line, data) local print = B.print('CheevsLine') local attachment + local text line.progress = 0 print(' ', data.objectiveIndex,'|cFF0088FF-|r', data.objectiveType, data.text) if data.flags then if band(data.flags, 0x00000001) > 0 then line.format = "%d/%d" - line.widget = T.SetWidget(line, data, 'ProgressBar', data.criteriaID) - line.height = line.widget.height + attachment = T.SetWidget(line, data, 'ProgressBar', data.criteriaID) + attachment.value = data.value + attachment.maxValue = data.maxValue + attachment:SetParent(handler.frame) + + print(attachment:GetNumPoints()) + for i = 1, attachment:GetNumPoints() do + print(' ',attachment:GetPoint(i)) + end + attachment.status:SetFormattedText("%d/%d", data.value, data.maxValue) + attachment:SetPoint('TOP', line, 'TOP') + line.height = attachment.height elseif band(data.flags, 0x00000002) then line.widget = nil + text = line.text else line.widget = nil line.displayColor = 'FFFFFF' - line.displayText = line.text + text = line.text end else line.displayText = data.text end - print('line.type =', data.type) - print(' ** qtyStr:', data.quantityString, 'qty:', data.quantity, 'assetID:', data.assetID) - return line.displayText, line.widget + print(' |cFF00DD22UpdateLine:|r', data.type, data.quantityString, 'qty:', data.quantity, 'assetID:', data.assetID) + return text, attachment, 'default' end Cheevs.Select = function(self, block) Cheevs.Link(self, block) + T:Update(self.updateReasonModule, block.info.cheevID) end Cheevs.Remove = function(self, block)