annotate 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
rev   line source
Nenue@28 1 --- ${PACKAGE_NAME}
Nenue@28 2 -- @file-author@
Nenue@28 3 -- @project-revision@ @project-hash@
Nenue@28 4 -- @file-revision@ @file-hash@
Nenue@28 5 -- Created: 4/13/2016 7:48 PM
Nenue@28 6 local B = select(2,...).frame
Nenue@28 7 local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame')
Nenue@29 8 local band = bit.band
Nenue@30 9 local RemoveTrackedAchievement, GetAchievementLink = RemoveTrackedAchievement, GetAchievementLink
Nenue@29 10 local AchievementFrame_ToggleAchievementFrame, AchievementFrame_SelectAchievement = AchievementFrame_ToggleAchievementFrame, AchievementFrame_SelectAchievement
Nenue@29 11 local GetTime, GetAchievementNumCriteria, GetAchievementCriteriaInfo = GetTime, GetAchievementNumCriteria, GetAchievementCriteriaInfo
Nenue@29 12 local GetNumTrackedAchievements, GetTrackedAchievements, GetAchievementInfo = GetNumTrackedAchievements, GetTrackedAchievements, GetAchievementInfo
Nenue@29 13 local Default, Cheevs = T.DefaultHandler, T.Cheevs
Nenue@37 14 local wipe = table.wipe
Nenue@37 15 local print, bprint, lprint, iprint = B.print('Tracker'), B.print('Block'), B.print('Line'), B.print('iprint')
Nenue@28 16
Nenue@29 17 --- Data retrieval
Nenue@37 18 Cheevs.GetNumWatched = function(self, targetID, isNew)
Nenue@37 19 local trackedList = {GetTrackedAchievements() }
Nenue@37 20 local numWatched, numAll = #trackedList, #self.WatchList
Nenue@37 21 print(' |cFF00FF88GetNumWatched:|r',self.name, numWatched, ' ('..numAll..' recorded)')
Nenue@37 22 local start = 1
Nenue@37 23 local limit = max(numAll, #trackedList)
Nenue@37 24 if targetID then
Nenue@37 25 if not isNew and self.Info[targetID] then
Nenue@37 26 -- if it's only an update, we can limit the scope
Nenue@37 27 start = self.Info[targetID].watchIndex
Nenue@37 28 print(' |cFF0088FFGetNumWatched: limit selection to['..start..'-'..limit..']')
Nenue@37 29 if self.InfoBlock[targetID] then
Nenue@37 30 self.InfoBlock[targetID]:Hide()
Nenue@37 31 end
Nenue@28 32
Nenue@37 33 end
Nenue@34 34 end
Nenue@34 35
Nenue@37 36 for index = start, limit do
Nenue@37 37 if index > numWatched then
Nenue@37 38 self.WatchList[index] = nil
Nenue@37 39 print(' % dropping watch entry #'..index)
Nenue@37 40 else
Nenue@37 41 local cheevID = trackedList[index]
Nenue@37 42 if not self.Info[cheevID] then
Nenue@37 43 self.Info[cheevID] = self:GetInfo(cheevID, index)
Nenue@37 44 else
Nenue@37 45 print(' |cFF00FFBBGetInfo:', cheevID, 'already pulled')
Nenue@37 46 end
Nenue@37 47 self:GetObjectives(cheevID)
Nenue@34 48
Nenue@37 49 local info = self.Info[cheevID]
Nenue@37 50 local watchBlock = self.WatchBlock[cheevID]
Nenue@37 51
Nenue@37 52 self.Info[cheevID].watchIndex = index
Nenue@37 53 self.WatchList[index] = info
Nenue@37 54 end
Nenue@37 55 end
Nenue@37 56
Nenue@37 57 numAll = #self.WatchList
Nenue@37 58 return numWatched, numAll, self.WatchList
Nenue@37 59 end
Nenue@37 60 Cheevs.GetInfo = function(self, cheevID, watchIndex)
Nenue@37 61 --- step 1: confirm primary data and begin an entry if needed
Nenue@37 62 local id, name, points, completed, month, day, year, description, flags, icon, rewardText, isGuildAch, wasEarnedByMe, earnedBy = GetAchievementInfo(cheevID)
Nenue@37 63 if not id then return nil end
Nenue@37 64
Nenue@37 65 print(' |cFF44AAFFGetInfo: pulling', id..',', name, earnedBy)
Nenue@37 66
Nenue@37 67
Nenue@37 68 self.Info[cheevID] = self.Info[cheevID] or {}
Nenue@37 69 local c = self.Info[cheevID]
Nenue@34 70 local rewards = {}
Nenue@34 71
Nenue@37 72 c.schema = 'achievement'
Nenue@34 73 c.rewardInfo = rewards
Nenue@29 74 c.type = 'Cheevs'
Nenue@34 75 c.title = name
Nenue@34 76 c.points = points
Nenue@34 77 c.completed = completed
Nenue@34 78 c.month = month
Nenue@34 79 c.day = day
Nenue@34 80 c.year = year
Nenue@34 81 c.description = description
Nenue@34 82 c.flags = flags
Nenue@34 83 c.icon = icon
Nenue@34 84 c.rewardText = rewardText
Nenue@34 85 c.isGuildAch = isGuildAch
Nenue@34 86 c.wasEarnedByMe = wasEarnedByMe
Nenue@34 87 c.earnedBy = earnedBy
Nenue@34 88
Nenue@37 89 local tagInfo = {}
Nenue@34 90 c.tagInfo = tagInfo
Nenue@34 91 c.watchIndex = watchIndex
Nenue@30 92 c.id = cheevID
Nenue@29 93 c.cheevID = cheevID
Nenue@37 94
Nenue@37 95 self.Info[cheevID] = c
Nenue@34 96 self.WatchInfo[watchIndex] = c
Nenue@37 97 return c
Nenue@37 98 end
Nenue@37 99
Nenue@37 100 Cheevs.GetObjectives = function(self, cheevID)
Nenue@37 101 local c = self.Info[cheevID]
Nenue@37 102 c.numObjectives = GetAchievementNumCriteria(cheevID)
Nenue@37 103 c.objectives = c.objectives or {}
Nenue@37 104 for i = 1, c.numObjectives do
Nenue@37 105 local description, type, completed, quantity, requiredQuantity, characterName, flags, assetID, quantityString, criteriaID = GetAchievementCriteriaInfo(cheevID, i)
Nenue@37 106 local line = c.objectives[i] or {}
Nenue@37 107 line.objectiveIndex = i
Nenue@37 108 line.cheevID = cheevID
Nenue@37 109 line.text = description
Nenue@37 110 line.type = type
Nenue@37 111 line.finished = completed
Nenue@37 112 line.value = quantity
Nenue@37 113 line.maxValue = requiredQuantity
Nenue@37 114 line.characterName = characterName
Nenue@37 115 line.flags = flags
Nenue@37 116 line.assetID = assetID
Nenue@37 117 line.quantityString = quantityString
Nenue@37 118 line.criteriaID = criteriaID
Nenue@37 119 c.objectives[i] = line
Nenue@37 120
Nenue@37 121 print(' |cFF44FFDDGetObjectives:|r', i, type, description, quantityString)
Nenue@37 122 end
Nenue@29 123 end
Nenue@29 124
Nenue@29 125 --- Content handlers
Nenue@28 126 Cheevs.UpdateLine = function(handler, block, line, data)
Nenue@28 127 local print = B.print('CheevsLine')
Nenue@30 128 local attachment
Nenue@37 129 local text
Nenue@28 130 line.progress = 0
Nenue@28 131 print(' ', data.objectiveIndex,'|cFF0088FF-|r', data.objectiveType, data.text)
Nenue@28 132 if data.flags then
Nenue@28 133 if band(data.flags, 0x00000001) > 0 then
Nenue@28 134 line.format = "%d/%d"
Nenue@37 135 attachment = T.SetWidget(line, data, 'ProgressBar', data.criteriaID)
Nenue@37 136 attachment.value = data.value
Nenue@37 137 attachment.maxValue = data.maxValue
Nenue@37 138 attachment:SetParent(handler.frame)
Nenue@37 139
Nenue@37 140 print(attachment:GetNumPoints())
Nenue@37 141 for i = 1, attachment:GetNumPoints() do
Nenue@37 142 print(' ',attachment:GetPoint(i))
Nenue@37 143 end
Nenue@37 144 attachment.status:SetFormattedText("%d/%d", data.value, data.maxValue)
Nenue@37 145 attachment:SetPoint('TOP', line, 'TOP')
Nenue@37 146 line.height = attachment.height
Nenue@28 147 elseif band(data.flags, 0x00000002) then
Nenue@28 148 line.widget = nil
Nenue@37 149 text = line.text
Nenue@28 150 else
Nenue@28 151 line.widget = nil
Nenue@28 152 line.displayColor = 'FFFFFF'
Nenue@37 153 text = line.text
Nenue@28 154
Nenue@28 155 end
Nenue@28 156 else
Nenue@28 157
Nenue@28 158 line.displayText = data.text
Nenue@28 159 end
Nenue@37 160 print(' |cFF00DD22UpdateLine:|r', data.type, data.quantityString, 'qty:', data.quantity, 'assetID:', data.assetID)
Nenue@37 161 return text, attachment, 'default'
Nenue@28 162 end
Nenue@28 163
Nenue@30 164 Cheevs.Select = function(self, block)
Nenue@30 165 Cheevs.Link(self, block)
Nenue@37 166 T:Update(self.updateReasonModule, block.info.cheevID)
Nenue@28 167 end
Nenue@29 168
Nenue@30 169 Cheevs.Remove = function(self, block)
Nenue@28 170
Nenue@30 171 RemoveTrackedAchievement(block.info.cheevID)
Nenue@28 172 end
Nenue@28 173 Cheevs.OnMouseUp = function(self, button)
Nenue@28 174
Nenue@28 175 Default.OnMouseUp(self, button)
Nenue@28 176 end
Nenue@30 177 Cheevs.Link = function(self, block)
Nenue@30 178 local achievementLink = GetAchievementLink(block.info.cheevID);
Nenue@28 179 if ( achievementLink ) then
Nenue@30 180 _G.ChatEdit_InsertLink(achievementLink);
Nenue@28 181 end
Nenue@28 182 end
Nenue@28 183
Nenue@30 184 Cheevs.Open = function(self, block)
Nenue@28 185
Nenue@30 186 if ( not _G.AchievementFrame ) then
Nenue@30 187 _G.AchievementFrame_LoadUI();
Nenue@28 188 end
Nenue@30 189 if ( not _G.AchievementFrame:IsShown() ) then
Nenue@30 190 _G.AchievementFrame_ToggleAchievementFrame();
Nenue@28 191 end
Nenue@30 192 _G.AchievementFrame_SelectAchievement(block.info.cheevID);
Nenue@28 193 end