annotate ObjectiveTracker/Achievements.lua @ 34:9856ebc63fa4

- half solution to Update being fired multiple times during load - change securefunc handlers to dispense a reason code; catch that reason code in the enclosure passed to hooksecurefunc, and decide whether to update or not from there.
author Nenue
date Sun, 17 Apr 2016 00:21:45 -0400
parents 7583684becf4
children 69d03f8e293e
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@28 14 local print = B.print('Tracker')
Nenue@28 15 local lprint = B.print('Line')
Nenue@28 16 local iprint = B.print('Info')
Nenue@28 17
Nenue@29 18 --- Data retrieval
Nenue@29 19 Cheevs.GetNumWatched = function(self)
Nenue@29 20 print('|cFF00FF00' .. GetTime())
Nenue@29 21 Cheevs.trackedCheevs = {GetTrackedAchievements()}
Nenue@29 22 return GetNumTrackedAchievements()
Nenue@29 23 end
Nenue@34 24 Cheevs.GetInfo = function(self, watchIndex)
Nenue@34 25 --- step 1: confirm primary data and begin an entry if needed
Nenue@34 26 local cheevID = Cheevs.trackedCheevs[watchIndex]
Nenue@29 27 local id, name, points, completed, month, day, year, description, flags, icon, rewardText, isGuildAch, wasEarnedByMe, earnedBy = GetAchievementInfo(cheevID)
Nenue@34 28 if not id then return false end
Nenue@28 29
Nenue@34 30 if not self.Info[cheevID] then self.Info[cheevID] = {} end
Nenue@29 31 local c = self.Info[cheevID]
Nenue@34 32 local numObjectives = GetAchievementNumCriteria(cheevID)
Nenue@34 33
Nenue@34 34 local tagInfo = {}
Nenue@34 35 local objectives = c.objectives or {}
Nenue@34 36 for i = 1, numObjectives do
Nenue@34 37 local description, type, completed, quantity, requiredQuantity, characterName, flags, assetID, quantityString, criteriaID = GetAchievementCriteriaInfo(cheevID, i)
Nenue@34 38 local line = objectives[i] or {}
Nenue@34 39 line.objectiveIndex = i
Nenue@34 40 line.cheevID = cheevID
Nenue@34 41 line.text = description
Nenue@34 42 line.type = type
Nenue@34 43 line.finished = completed
Nenue@34 44 line.value = quantity
Nenue@34 45 line.maxValue = requiredQuantity
Nenue@34 46 line.characterName = characterName
Nenue@34 47 line.flags = flags
Nenue@34 48 line.assetID = assetID
Nenue@34 49 line.quantityString = quantityString
Nenue@34 50 line.criteriaID = criteriaID
Nenue@34 51 objectives[i] = line
Nenue@34 52 end
Nenue@34 53
Nenue@34 54
Nenue@34 55 local rewards = {}
Nenue@34 56 print('Cheevs.|cFF0088FFGetInfo|r('..watchIndex..')', 'obj:', GetAchievementNumCriteria(cheevID), name, description)
Nenue@34 57
Nenue@34 58 c.rewardInfo = rewards
Nenue@34 59 c.numObjectives = numObjectives
Nenue@34 60 c.objectives = objectives
Nenue@29 61 c.type = 'Cheevs'
Nenue@34 62 c.title = name
Nenue@34 63 c.points = points
Nenue@34 64 c.completed = completed
Nenue@34 65 c.month = month
Nenue@34 66 c.day = day
Nenue@34 67 c.year = year
Nenue@34 68 c.description = description
Nenue@34 69 c.flags = flags
Nenue@34 70 c.icon = icon
Nenue@34 71 c.rewardText = rewardText
Nenue@34 72 c.isGuildAch = isGuildAch
Nenue@34 73 c.wasEarnedByMe = wasEarnedByMe
Nenue@34 74 c.earnedBy = earnedBy
Nenue@34 75
Nenue@34 76 c.tagInfo = tagInfo
Nenue@34 77 c.watchIndex = watchIndex
Nenue@30 78 c.id = cheevID
Nenue@29 79 c.cheevID = cheevID
Nenue@34 80 self.WatchInfo[watchIndex] = c
Nenue@29 81 return self.Info[cheevID]
Nenue@29 82 end
Nenue@29 83
Nenue@29 84 --- Content handlers
Nenue@28 85 Cheevs.UpdateLine = function(handler, block, line, data)
Nenue@28 86 local print = B.print('CheevsLine')
Nenue@30 87 local attachment
Nenue@28 88 line.progress = 0
Nenue@28 89 print(' ', data.objectiveIndex,'|cFF0088FF-|r', data.objectiveType, data.text)
Nenue@28 90 if data.flags then
Nenue@28 91 if band(data.flags, 0x00000001) > 0 then
Nenue@28 92 line.format = "%d/%d"
Nenue@28 93 line.widget = T.SetWidget(line, data, 'ProgressBar', data.criteriaID)
Nenue@28 94 line.height = line.widget.height
Nenue@28 95 elseif band(data.flags, 0x00000002) then
Nenue@28 96 line.widget = nil
Nenue@28 97 else
Nenue@28 98 line.widget = nil
Nenue@28 99 line.displayColor = 'FFFFFF'
Nenue@28 100 line.displayText = line.text
Nenue@28 101
Nenue@28 102 end
Nenue@28 103 else
Nenue@28 104
Nenue@28 105 line.displayText = data.text
Nenue@28 106 end
Nenue@28 107 print('line.type =', data.type)
Nenue@28 108 print(' ** qtyStr:', data.quantityString, 'qty:', data.quantity, 'assetID:', data.assetID)
Nenue@30 109 return line.displayText, line.widget
Nenue@28 110 end
Nenue@28 111
Nenue@30 112 Cheevs.Select = function(self, block)
Nenue@30 113 Cheevs.Link(self, block)
Nenue@28 114 end
Nenue@29 115
Nenue@30 116 Cheevs.Remove = function(self, block)
Nenue@28 117
Nenue@30 118 RemoveTrackedAchievement(block.info.cheevID)
Nenue@28 119 end
Nenue@28 120 Cheevs.OnMouseUp = function(self, button)
Nenue@28 121
Nenue@28 122 Default.OnMouseUp(self, button)
Nenue@28 123 end
Nenue@30 124 Cheevs.Link = function(self, block)
Nenue@30 125 local achievementLink = GetAchievementLink(block.info.cheevID);
Nenue@28 126 if ( achievementLink ) then
Nenue@30 127 _G.ChatEdit_InsertLink(achievementLink);
Nenue@28 128 end
Nenue@28 129 end
Nenue@28 130
Nenue@30 131 Cheevs.Open = function(self, block)
Nenue@28 132
Nenue@30 133 if ( not _G.AchievementFrame ) then
Nenue@30 134 _G.AchievementFrame_LoadUI();
Nenue@28 135 end
Nenue@30 136 if ( not _G.AchievementFrame:IsShown() ) then
Nenue@30 137 _G.AchievementFrame_ToggleAchievementFrame();
Nenue@28 138 end
Nenue@30 139 _G.AchievementFrame_SelectAchievement(block.info.cheevID);
Nenue@28 140 end