comparison ObjectiveTracker/ObjectiveTracker.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
124 Watched = {}, --- stores whether the given unique ID is tracked 124 Watched = {}, --- stores whether the given unique ID is tracked
125 125
126 freeBlocks = {}, --- blocks hidden due to list shrinkage 126 freeBlocks = {}, --- blocks hidden due to list shrinkage
127 usedBlocks = {}, --- block in use 127 usedBlocks = {}, --- block in use
128 BlockInfo = {}, --- by block creation offset, used by framescript 128 BlockInfo = {}, --- by block creation offset, used by framescript
129 WatchList = {}, --- ordered manifest of watched items
129 130
130 --- Indexes 131 --- Indexes
132 InfoBlock = {}, --- by unique ID
131 LogBlock = {}, --- by API log offset, used by GetBlock if possible 133 LogBlock = {}, --- by API log offset, used by GetBlock if possible
132 WatchBlock = {}, --- block by internal offset, used in GetBlock scope 134 WatchBlock = {}, --- block by internal offset, used in GetBlock scope
133 WatchInfo = {}, --- info by internal offset, used in Update scope 135 WatchInfo = {}, --- info by internal offset, used in Update scope
134 } 136 }
135 137
152 QuestBlock = {}, 154 QuestBlock = {},
153 } 155 }
154 T.Cheevs = { 156 T.Cheevs = {
155 name = "Cheevs", 157 name = "Cheevs",
156 displayName = "Achievements", 158 displayName = "Achievements",
159 schema = 'achievement',
157 updateReasonModule = OBJECTIVE_TRACKER_UPDATE_MODULE_ACHIEVEMENT, 160 updateReasonModule = OBJECTIVE_TRACKER_UPDATE_MODULE_ACHIEVEMENT,
158 updateReasonEvents = OBJECTIVE_TRACKER_UPDATE_ACHIEVEMENT + 161 updateReasonEvents = OBJECTIVE_TRACKER_UPDATE_ACHIEVEMENT +
159 OBJECTIVE_TRACKER_UPDATE_ACHIEVEMENT_ADDED, 162 OBJECTIVE_TRACKER_UPDATE_ACHIEVEMENT_ADDED,
160 } 163 }
161 T.Bonus = { 164 T.Bonus = {
256 Event.QUEST_REMOVED = function(questLogIndex, questID) 259 Event.QUEST_REMOVED = function(questLogIndex, questID)
257 return OBJECTIVE_TRACKER_UPDATE_QUEST, questID, false 260 return OBJECTIVE_TRACKER_UPDATE_QUEST, questID, false
258 end 261 end
259 262
260 Event.QUEST_WATCH_LIST_CHANGED = function(questID, added) 263 Event.QUEST_WATCH_LIST_CHANGED = function(questID, added)
261 if ( added ) then 264 if ( added == true ) then
262 if ( not IsQuestTask(questID) ) then 265 if ( not IsQuestTask(questID) ) then
263 return OBJECTIVE_TRACKER_UPDATE_QUEST_ADDED, questID, added 266 return OBJECTIVE_TRACKER_UPDATE_QUEST_ADDED, questID, added
264 end 267 end
265 else 268 elseif questID then
266 return OBJECTIVE_TRACKER_UPDATE_QUEST, questID, added 269 return OBJECTIVE_TRACKER_UPDATE_QUEST_ADDED, questID, added
267 end 270 end
268 end 271 end
269 272
270 Event.QUEST_POI_UPDATE = function() 273 Event.QUEST_POI_UPDATE = function()
271 QuestPOIUpdateIcons(); 274 QuestPOIUpdateIcons();
272 if ( GetCVar("trackQuestSorting") == "proximity" ) then 275 if ( GetCVar("trackQuestSorting") == "proximity" ) then
273 SortQuestWatches(); 276 SortQuestWatches();
274 end 277 end
275 return OBJECTIVE_TRACKER_UPDATE_ALL 278 return OBJECTIVE_TRACKER_UPDATE_ALL
276 end 279 end
277 Event.SUPER_TRACKED_QUEST_CHANGED = function() 280 Event.SUPER_TRACKED_QUEST_CHANGED = function(questID)
278 return OBJECTIVE_TRACKER_UPDATE_QUEST 281 return OBJECTIVE_TRACKER_UPDATE_QUEST, questID
279 end 282 end
280 Event.ZONE_CHANGED = function() 283 Event.ZONE_CHANGED = function()
281 local inMicroDungeon = IsPlayerInMicroDungeon(); 284 local inMicroDungeon = IsPlayerInMicroDungeon();
282 if ( inMicroDungeon ~= T.inMicroDungeon ) then 285 if ( inMicroDungeon ~= T.inMicroDungeon ) then
283 if ( not WorldMapFrame:IsShown() and GetCVarBool("questPOI") ) then 286 if ( not WorldMapFrame:IsShown() and GetCVarBool("questPOI") ) then
304 end 307 end
305 Event.TRACKED_ACHIEVEMENT_UPDATE = function() 308 Event.TRACKED_ACHIEVEMENT_UPDATE = function()
306 return OBJECTIVE_TRACKER_UPDATE_ACHIEVEMENT 309 return OBJECTIVE_TRACKER_UPDATE_ACHIEVEMENT
307 end 310 end
308 Event.TRACKED_ACHIEVEMENT_LIST_CHANGED = function(achievementID, added) 311 Event.TRACKED_ACHIEVEMENT_LIST_CHANGED = function(achievementID, added)
309 if ( added ) then 312 return OBJECTIVE_TRACKER_UPDATE_ACHIEVEMENT_ADDED, achievementID, added
310 return OBJECTIVE_TRACKER_UPDATE_ACHIEVEMENT_ADDED, achievementID
311 else
312 return OBJECTIVE_TRACKER_UPDATE_ACHIEVEMENT
313 end
314 end 313 end
315 Event.ZONE_CHANGED_NEW_AREA = function () 314 Event.ZONE_CHANGED_NEW_AREA = function ()
316 if ( not WorldMapFrame:IsShown() and GetCVarBool("questPOI") ) then 315 if ( not WorldMapFrame:IsShown() and GetCVarBool("questPOI") ) then
317 SetMapToCurrentZone(); -- update the zone to get the right POI numbers for the tracker 316 SetMapToCurrentZone(); -- update the zone to get the right POI numbers for the tracker
318 end 317 end
450 end 449 end
451 end 450 end
452 451
453 local Play = function(file) if Devian and Devian.InWorkspace() then PlaySoundFile(file) end end 452 local Play = function(file) if Devian and Devian.InWorkspace() then PlaySoundFile(file) end end
454 453
454 local tprint = B.print('Tracker')
455 T.OnHookedFunc = function(name, ...) 455 T.OnHookedFunc = function(name, ...)
456 print('|cFFFF8800securehook:|r', name, '|cFF00FFFFargs:|r', ...) 456 tprint('|cFFFF8800securehook:|r', name, '|cFF00FFFFargs:|r', ...)
457 local updateReason = T[name](...) 457 local updateReason, arg1, arg2, arg3 = T[name](...)
458 if updateReason then 458 if updateReason then
459 print('|cFF00FFFFupdate reason:|r', updateReason) 459 print('|cFF00FFFFupdate reason:|r', updateReason, arg1, arg2, arg3)
460 T:Update(updateReason) 460 T:Update(updateReason, arg1, arg2, arg3)
461 end 461 end
462 end 462 end
463 463
464 function T:OnEvent (event, ...) 464 function T:OnEvent (event, ...)
465 local isHandled 465 local isHandled
466 print('OnEvent(|cFF00FF00'.. event ..'|r):', ...) 466 tprint('OnEvent(|cFF00FF00'.. event ..'|r):', ...)
467 local reason, arg1, arg2, arg3 467 local reason, arg1, arg2, arg3
468 if Event[event] then 468 if Event[event] then
469 if type(Event[event]) == 'function' then 469 if type(Event[event]) == 'function' then
470 Play([[Interface\Addons\SharedMedia_MyMedia\sound\Info.ogg]]) 470 Play([[Interface\Addons\SharedMedia_MyMedia\sound\Info.ogg]])
471 reason, arg1, arg2, arg3 = Event[event](...) 471 reason, arg1, arg2, arg3 = Event[event](...)
472 elseif type(Event[event]) == 'table' then
473 Play([[Interface\Addons\SharedMedia_MyMedia\sound\Link.ogg]])
474 for i, action in ipairs(Event[event]) do
475 if type(action) == 'function' then
476 reason, arg1, arg2, arg3 = action(event, ...)
477 else
478 reason = action
479 end
480
481 if reason then
482 T:Update(reason, arg1, arg2, arg3)
483 end
484 end
485 else 472 else
486 --Play([[Interface\Addons\SharedMedia_MyMedia\sound\Heart.ogg]]) 473 Play([[Interface\Addons\SharedMedia_MyMedia\sound\Heart.ogg]])
487 reason = Event[event] 474 reason = Event[event]
488 end 475 end
489 else 476 else
490 print('no event handler set for', event) 477 print('no event handler set for', event)
491 Play([[Interface\Addons\SharedMedia_MyMedia\sound\IM.ogg]]) 478 Play([[Interface\Addons\SharedMedia_MyMedia\sound\IM.ogg]])