comparison 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
comparison
equal deleted inserted replaced
36:a487841050be 37:e84d645c8ab8
87 end 87 end
88 end 88 end
89 89
90 Default.UpdateTracker = function (handler, reason, id, isNew) 90 Default.UpdateTracker = function (handler, reason, id, isNew)
91 local print = tprint 91 local print = tprint
92 local tracker = handler.frame 92 local frame = handler.frame
93 local blockIndex = 0 93 local blockIndex = 0
94 94
95 print(format(' |cFFFF8800UpdateTracker|r(%s): %s', handler.name, reason))
95 handler.updateReason = reason 96 handler.updateReason = reason
96 handler.numWatched = handler:GetNumWatched() 97 local numWatched, numAll, watchTable = handler:GetNumWatched(id, isNew)
97 if handler.numWatched >= 1 then 98
98 99 if numWatched >= 1 then
99 print(' |cFF00FF88GetNumWatched:|r',handler.name, handler.numWatched, 'of', handler.numAll) 100 if watchTable then
100 end 101 print('|cFF00FF00 n ID Obj wID Log Blk')
101 102 for i, w in ipairs(watchTable) do
103 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 '')))
104 end
105 end
106 end
107
108 handler.numWatched = numWatched
109 handler.numAll = numAll
102 handler.numBlocks = 0 110 handler.numBlocks = 0
103 handler.currentBlock = 0 111 handler.currentBlock = 0
104 handler.currentAnchor = tracker.titlebg 112 handler.currentAnchor = frame.titlebg
105 for blockIndex = 1, handler.numWatched do 113 for blockIndex = 1, numWatched do
106 local currentBlock = handler:UpdateBlock(blockIndex, id, isNew) 114 local currentBlock = handler:UpdateBlock(blockIndex, id, isNew)
107 if currentBlock then 115 if currentBlock then
108 handler:AddBlock(currentBlock) 116 handler:AddBlock(currentBlock)
109 else 117 else
110 print(' |cFFFF9900finished|r @', blockIndex) 118 print(' |cFFFF9900finished|r @', blockIndex)
114 122
115 123
116 local numBlocks = handler.numBlocks 124 local numBlocks = handler.numBlocks
117 local used = handler.usedBlocks 125 local used = handler.usedBlocks
118 local free = handler.freeBlocks 126 local free = handler.freeBlocks
119 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)) 127 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))
120 return tracker.numWatched, tracker.numAll 128 return numWatched, numAll
121 end 129 end
122 130
123 Default.UpdateBlock = function (handler, blockIndex, id, added) 131 Default.UpdateBlock = function (handler, index)
124 local print = bprint 132 local print = bprint
125 if not blockIndex then 133 if not index then
126 return 134 return
127 end 135 end
128 local info = handler:GetInfo(blockIndex) -- should match up with whatever the internal watch list has 136 local info = handler.WatchList[index] -- should match up with whatever the internal watch list has
129 if not info then 137 if not info then
130 return 138 return
131 end 139 end
132 print(' Updating |cFF00FF00'..handler.displayName..'|r|cFF00FFFF'..blockIndex..'|r|cFF0099FF', info.id ,'|r') 140 print(' Updating |cFF00FF00'..handler.displayName..'|r|cFF00FFFF'..index..'|r|cFF0099FF', info.id ,'|r')
133 local frame = handler.frame 141 local frame = handler.frame
134 local block = handler:GetBlock(info.id) 142 local block = handler:GetBlock(info.id)
135 143
136 if added then
137 -- do something if the block is being assigned a new thing
138 end
139
140 block.handler = handler 144 block.handler = handler
141 block.info = info 145 block.info = info
142 146
143 info.blockIndex = blockIndex 147 info.blockIndex = index
144 if info.questID then handler.QuestBlock[info.questID] = block end 148 if info.id then
145 if info.logIndex then handler.LogBlock[info.logIndex] = block end 149 print(' storing id', info.id, 'for', block:GetName())
146 if info.watchIndex then handler.WatchBlock[info.watchIndex] = block end 150 handler.InfoBlock[info.id] = block
147 handler.BlockInfo[blockIndex] = info 151 end
148 local newSchema = handler:UpdateObjectives(block) 152 if info.logIndex then
149 if newSchema and newSchema ~= blockSchema then 153 print(' storing logIndex', info.logIndex, 'for', block:GetName())
150 T.UpdateSchema('block', newSchema) 154 handler.LogBlock[info.logIndex] = block
151 end 155 end
156 if info.watchIndex then
157 print(' storing watchIndex', info.watchIndex, 'for', block:GetName())
158 handler.WatchBlock[info.watchIndex] = block
159 end
160 handler.BlockInfo[index] = info
161 handler:UpdateObjectives(block)
152 162
153 block.title:SetText(info.title) 163 block.title:SetText(info.title)
154 164
155 print(' |cFFFFFF00height|r:', block.height) 165 print(' |cFFFFFF00height|r:', block.height)
156 print(' |cFF00FFFF)|r -> ', block, block:GetHeight()) 166 print(' |cFF00FFFF)|r -> ', block, block:GetHeight())
199 tagPoint, tagAnchor, tagRelative = handler:AddTag(block, 'frequencyTag', tagPoint, tagAnchor, tagRelative) 209 tagPoint, tagAnchor, tagRelative = handler:AddTag(block, 'frequencyTag', tagPoint, tagAnchor, tagRelative)
200 tagPoint, tagAnchor, tagRelative = handler:AddTag(block, 'typeTag', tagPoint, tagAnchor, tagRelative) 210 tagPoint, tagAnchor, tagRelative = handler:AddTag(block, 'typeTag', tagPoint, tagAnchor, tagRelative)
201 tagPoint, tagAnchor, tagRelative = handler:AddTag(block, 'completionTag', tagPoint, tagAnchor, tagRelative) 211 tagPoint, tagAnchor, tagRelative = handler:AddTag(block, 'completionTag', tagPoint, tagAnchor, tagRelative)
202 end 212 end
203 213
214 if info.schema then
215 block.schema = info.schema
216 end
217
204 if info.statusKey and (Devian and Devian.InWorkspace()) then 218 if info.statusKey and (Devian and Devian.InWorkspace()) then
205 block.debugText:SetText(info.statusKey) 219 block.debugText:SetText(tostring(info.statusKey) .. ' ' .. tostring(block.posIndex) .. ' '.. tostring(info.logIndex))
206 block.debugText:Show() 220 block.debugText:Show()
207 end 221 end
208 return block 222 return block
209 end 223 end
210 224
211 Default.UpdateObjectives = function(handler, block, block_schema) 225 Default.UpdateObjectives = function(handler, block)
212 local print = lprint 226 local print = lprint
227 local block_schema = block.schema
213 local info = block.info 228 local info = block.info
214 print(' |cFF00FF00default.objectives', block:GetName()) 229 print(' |cFF00FF00default.objectives', block:GetName())
215 -- reset the starting positions 230 -- reset the starting positions
216 block.endPoint = block.titlebg 231 block.endPoint = block.titlebg
217 block.attachmentHeight = 0 232 block.attachmentHeight = 0
269 284
270 Default.Select = function(handler, block) 285 Default.Select = function(handler, block)
271 T:Update() 286 T:Update()
272 end 287 end
273 Default.Open = function(handler, block) 288 Default.Open = function(handler, block)
274 T:Update(handler.watchReasonModule) 289 T:Update(handler.updateReasonModule)
275 end 290 end
276 Default.Remove = function(handler, block) 291 Default.Remove = function(handler, block)
277 T:Update(handler.watchReasonModule) 292 T:Update(handler.updateReasonModule)
278 end 293 end
279 Default.Report = function(handler, block) 294 Default.Report = function(handler, block)
280 print('Stats:', handler.numWatched,'items tracked,', handler.numBlocks,'blocks assigned.') 295 print('Stats:', handler.numWatched,'items tracked,', handler.numBlocks,'blocks assigned.')
281 end 296 end
282 297
294 self.Open(self.handler, self) 309 self.Open(self.handler, self)
295 end 310 end
296 self.initialButton = nil 311 self.initialButton = nil
297 self.modChatLink = nil 312 self.modChatLink = nil
298 self.modQuestWatch = nil 313 self.modQuestWatch = nil
299 T:Update(self.handler.updateReasonModule) 314 --T:Update(self.handler.updateReasonModule)
300 print('|cFFFF8800'..tostring(self:GetName())..':MouseUp()|r') 315 print('|cFFFF8800'..tostring(self:GetName())..':MouseUp()|r')
301 end 316 end
302 Default.OnMouseDown = function(self, button) 317 Default.OnMouseDown = function(self, button)
303 print(self.info.title) 318 print(self.info.title)
304 end 319 end