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