annotate ObjectiveTracker/BonusObjectives.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 64f2a9bbea79
children a487841050be
rev   line source
Nenue@27 1 --- ${PACKAGE_NAME}
Nenue@27 2 -- @file-author@
Nenue@27 3 -- @project-revision@ @project-hash@
Nenue@27 4 -- @file-revision@ @file-hash@
Nenue@27 5 -- Created: 4/13/2016 7:48 PM
Nenue@27 6 local B = select(2,...).frame
Nenue@27 7 local T = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame')
Nenue@27 8 local Default, Quest = T.DefaultHandler, T.Quest
Nenue@27 9 local print = B.print('Tracker')
Nenue@27 10 local lprint = B.print('Line')
Nenue@33 11 local iprint = B.print('Info')
Nenue@29 12 local Bonus = T.Bonus
Nenue@27 13
Nenue@29 14 local UnitName, GetRealmName, GetQuestObjectiveInfo, GetTasksTable, GetTaskInfo = UnitName, GetRealmName, GetQuestObjectiveInfo, GetTasksTable, GetTaskInfo
Nenue@29 15 local GetMapNameByID, GetCurrentMapAreaID = GetMapNameByID, GetCurrentMapAreaID
Nenue@29 16 local tinsert, ipairs, pairs, tostring = tinsert, ipairs, pairs, tostring
Nenue@29 17 local GetQuestProgressBarPercent, PERCENTAGE_STRING, GetTime = GetQuestProgressBarPercent, PERCENTAGE_STRING, GetTime
Nenue@33 18 local STICKY_TASKS = true
Nenue@29 19
Nenue@29 20 --- Returns a tasks table modified to include recently completed objectives
Nenue@29 21 local InternalGetTasksTable = function()
Nenue@29 22 local savedTasks = T.Conf.TasksLog
Nenue@29 23 local char = UnitName("player")
Nenue@29 24 local realm = GetRealmName()
Nenue@29 25 local tasks = GetTasksTable()
Nenue@29 26
Nenue@29 27 for questID, data in pairs(Bonus.Info) do
Nenue@29 28
Nenue@29 29 print(' -- questID:', questID, #data.objectives)
Nenue@29 30 for i, o in ipairs(data.objectives) do
Nenue@29 31 print(' --', i, o.text)
Nenue@29 32 end
Nenue@29 33
Nenue@29 34 end
Nenue@29 35
Nenue@29 36
Nenue@29 37 for questID, data in pairs(savedTasks) do
Nenue@29 38 if questID > 0 then
Nenue@29 39 local found = false
Nenue@29 40 for i = 1, #tasks do
Nenue@29 41 if tasks[i] == questID then
Nenue@29 42 found = true
Nenue@29 43 break
Nenue@29 44 end
Nenue@29 45 end
Nenue@29 46 -- if it's not part of the current table, then try to insert it where it was last found
Nenue@29 47 if not found then
Nenue@29 48 if data.watchIndex < #tasks then
Nenue@29 49 tinsert(tasks, data.watchIndex, data)
Nenue@29 50 else
Nenue@29 51 tinsert(tasks, data)
Nenue@29 52 end
Nenue@29 53 end
Nenue@29 54 end
Nenue@29 55 end
Nenue@29 56 return tasks
Nenue@29 57 end
Nenue@29 58
Nenue@29 59 --- Returns an entry from the composed tasks table if possible, otherwise makes an API pull
Nenue@29 60 local InternalGetTaskInfo = function(questID)
Nenue@29 61 local completedTasks = T.Conf.TasksLog
Nenue@29 62 if completedTasks[questID] then
Nenue@29 63 return true, true, #completedTasks[questID].objectives
Nenue@29 64 else
Nenue@29 65 return GetTaskInfo(questID)
Nenue@29 66 end
Nenue@29 67 end
Nenue@29 68
Nenue@29 69 --- Same as above but for the objective entries
Nenue@29 70 local InternalGetQuestObjectiveInfo = function(questID, objectiveIndex)
Nenue@29 71 local completedTasks = T.Conf.TasksLog
Nenue@29 72 if ( completedTasks[questID] ) then
Nenue@29 73 print('using internal data')
Nenue@29 74 return completedTasks[questID].objectives[objectiveIndex], completedTasks[questID].objectiveType, true;
Nenue@29 75 else
Nenue@29 76 return GetQuestObjectiveInfo(questID, objectiveIndex, false);
Nenue@29 77 end
Nenue@29 78 end
Nenue@29 79
Nenue@29 80 --- end redundant copy of silliness
Nenue@29 81 ------------------------------------------------------------------------------------------
Nenue@29 82
Nenue@29 83 Bonus.Completed = {}
Nenue@29 84 Bonus.POI = {}
Nenue@29 85 Bonus.Scenario = {}
Nenue@29 86 Bonus.QuestBlock = {}
Nenue@29 87 Bonus.WatchInfo = {}
Nenue@29 88 function Bonus:GetNumWatched ()
Nenue@33 89 local print = iprint
Nenue@29 90 print(self.name, self)
Nenue@29 91
Nenue@29 92 local tasks = InternalGetTasksTable()
Nenue@29 93 local numWatched = 0
Nenue@29 94 local numAll = 0
Nenue@33 95 local existingTasks = {}
Nenue@29 96 self.WatchInfo = {}
Nenue@29 97 print('|cFFFFFF00Bonus.GetNumWatched()|r', #tasks)
Nenue@34 98 print(' |cFF00FFFFInternalGetTaskInfo|r:')
Nenue@29 99 for i, questID in ipairs(tasks) do
Nenue@29 100 local isInArea, isOnMap, numObjectives = InternalGetTaskInfo(questID)
Nenue@29 101 local existingTask = self.QuestBlock[questID]
Nenue@29 102 local displayObjectiveHeader = false;
Nenue@29 103 local test = (isInArea or (isOnMap and existingTask))
Nenue@29 104 --local test = true
Nenue@29 105 if test then
Nenue@29 106 self.Info[questID] = self.Info[questID] or {}
Nenue@29 107
Nenue@29 108 local t = self.Info[questID]
Nenue@33 109 if (isOnMap or isInArea) and existingTask then
Nenue@33 110 t.areaID = GetCurrentMapAreaID()
Nenue@33 111 local _
Nenue@33 112 t.mapName, _, _, t.isMicroDungeon, t.microDungeonMapName = GetMapInfo()
Nenue@33 113 print('|cFF00FF00scooping map info (questID '..questID..'):|r', t.areaID, t.mapName)
Nenue@33 114 end
Nenue@29 115
Nenue@29 116 local taskTitle
Nenue@33 117 t.objectives = {}
Nenue@29 118 local taskFinished = true;
Nenue@29 119 for objectiveIndex = 1, numObjectives do
Nenue@29 120 local text, objectiveType, finished, displayAsObjective = InternalGetQuestObjectiveInfo(questID, objectiveIndex, false);
Nenue@29 121 displayObjectiveHeader = displayObjectiveHeader or displayAsObjective;
Nenue@29 122 if not taskTitle then
Nenue@29 123 if objectiveType == 'progressbar' and not text:match('^%d%+\\%d+') then
Nenue@29 124 taskTitle = text
Nenue@29 125 text = ''
Nenue@29 126 end
Nenue@29 127 end
Nenue@29 128
Nenue@29 129
Nenue@29 130 print(' --', text, objectiveType, finished, displayAsObjective)
Nenue@29 131 t.objectives[objectiveIndex] = t.objectives[objectiveIndex] or {}
Nenue@29 132 local o = t.objectives[objectiveIndex]
Nenue@29 133
Nenue@34 134 o.index = objectiveIndex
Nenue@29 135 o.text = text
Nenue@34 136 o.type = objectiveType
Nenue@29 137 o.finished = finished
Nenue@29 138 o.displayAsObjective = displayAsObjective
Nenue@29 139 end
Nenue@29 140
Nenue@33 141 T.SetRewards(t, questID)
Nenue@33 142
Nenue@29 143 -- didn't get a name from progress bar? what about area name
Nenue@29 144 if not taskTitle then
Nenue@29 145 if isInArea then
Nenue@29 146 taskTitle = GetMapNameByID(GetCurrentMapAreaID())
Nenue@29 147 end
Nenue@29 148 end
Nenue@34 149 t.numObjectives = numObjectives
Nenue@33 150 t.isInArea = isInArea
Nenue@33 151 t.isOnMap = isOnMap
Nenue@33 152 t.existingTask = existingTask
Nenue@33 153 t.questID = questID
Nenue@33 154 t.id = questID
Nenue@33 155 t.taskIndex = i
Nenue@29 156 t.title = taskTitle
Nenue@33 157 self.WatchInfo[i] = t
Nenue@29 158 end
Nenue@29 159
Nenue@29 160 print (' |cFF00FF88#', i, 'questID', questID, 'inArea', isInArea, 'onMap', isOnMap, 'existing', (existingTask and 'Y' or 'N'), (test and '|cFF00FF00show|r' or '|cFFFF0088hide|r'))
Nenue@29 161 end
Nenue@29 162
Nenue@29 163
Nenue@29 164 self.numAll = #tasks
Nenue@29 165 self.numWatched = #self.WatchInfo
Nenue@29 166 print(' stats:', self.numAll, 'active tasks,', self.numWatched, 'nearby or animating')
Nenue@29 167 --return #tasks
Nenue@29 168 return #self.WatchInfo
Nenue@29 169 end
Nenue@29 170
Nenue@29 171 --- info cleanup done when turn-ins are detected
Nenue@33 172 Bonus.OnTurnIn = function(self, block, questID, xp, money)
Nenue@33 173 local info = self.Info[questID]
Nenue@33 174 if info.rewardInfo and #info.rewardInfo >= 1 then
Nenue@33 175 for i, reward in ipairs(info.rewardInfo) do
Nenue@29 176 --[[
Nenue@29 177 type = 'item',
Nenue@29 178 index = i ,
Nenue@29 179 name = name,
Nenue@29 180 texture = texture,
Nenue@29 181 count = count,
Nenue@29 182 quality = quality,
Nenue@29 183 isUsable = isUsable
Nenue@29 184 ]]
Nenue@29 185 print(' reward ', i, ' ', reward.type, reward.name, reward.count)
Nenue@29 186
Nenue@29 187 end
Nenue@29 188 end
Nenue@29 189
Nenue@34 190 print('|cFFFF8800'..block:GetName()..':OnTurnIn call', questID, xp, money)
Nenue@34 191 local savedTasks = B.Conf.TasksLog or {}
Nenue@29 192
Nenue@33 193 info.completedTime = GetTime()
Nenue@33 194 info.animate = true
Nenue@34 195 T.SetAnimate(self.updateReasonModule)
Nenue@34 196 savedTasks[questID] = {
Nenue@34 197 id = questID,
Nenue@34 198 title = info.title,
Nenue@34 199 finished = true,
Nenue@34 200 numObjectives = info.numObjectives,
Nenue@34 201 objectives = info.objectives,
Nenue@34 202 rewardInfo = info.rewardInfo,
Nenue@34 203 }
Nenue@34 204 B.Conf.TasksLog = savedTasks
Nenue@34 205
Nenue@34 206 print(' ## CONF TASKLOG ##')
Nenue@34 207 for i, t in pairs(savedTasks[questID]) do
Nenue@34 208 print(' |cFFFFFF00'.. tostring(i)..'|r', t)
Nenue@34 209
Nenue@34 210 end
Nenue@34 211 for o, j in ipairs(savedTasks[questID].objectives) do
Nenue@34 212 print(' |cFF00FFFF#'.. o ..'|r', j.type, j.finished)
Nenue@34 213 end
Nenue@33 214
Nenue@33 215 print('adding', info.title, 'to cache')
Nenue@29 216 end
Nenue@29 217
Nenue@29 218 Bonus.GetInfo = function(self, taskIndex)
Nenue@29 219 print(self.name, self)
Nenue@29 220 return self.WatchInfo[taskIndex]
Nenue@29 221 end
Nenue@29 222
Nenue@29 223
Nenue@29 224
Nenue@29 225 --- Update hooks
Nenue@27 226 Bonus.UpdateObjectives = function(handler, block)
Nenue@27 227 Default.UpdateObjectives(handler, block)
Nenue@34 228 return 'default'
Nenue@27 229 end
Nenue@27 230
Nenue@33 231 Bonus.UpdateLine = function(handler, block, line, data)
Nenue@27 232 local info = block.info
Nenue@27 233 local print = lprint
Nenue@31 234 local text, attachment = '', nil
Nenue@27 235 line.displayColor = 'FFFFFF'
Nenue@34 236 if data.type == 'progressbar' then
Nenue@27 237 print(' |cFFFF44DDpercent='..tostring(GetQuestProgressBarPercent(info.questID)))
Nenue@33 238 local percent = 100
Nenue@34 239 attachment = T.SetWidget(line, data, 'ProgressBar', info.questID..'-'..data.index)
Nenue@33 240 if not data.finished then
Nenue@33 241 percent = GetQuestProgressBarPercent(info.questID)
Nenue@33 242 end
Nenue@34 243 data.value = percent
Nenue@34 244 data.maxValue = 100
Nenue@34 245
Nenue@34 246 print(attachment:GetNumPoints())
Nenue@34 247 for i = 1, attachment:GetNumPoints() do
Nenue@34 248 print(' ',attachment:GetPoint(i))
Nenue@34 249 end
Nenue@34 250
Nenue@34 251
Nenue@33 252 attachment.value = percent
Nenue@33 253 attachment.maxValue = 100
Nenue@31 254 attachment:SetPoint('TOP', line, 'TOP', 0, 0)
Nenue@34 255 attachment.status:SetFormattedText(PERCENTAGE_STRING, percent)
Nenue@34 256 print(attachment.status:GetText())
Nenue@27 257 print(' |cFFFF0022** text:|r', data.text, '|cFFFF0022value:|r', data.value, '|cFFFF0022max:|r', data.maxValue)
Nenue@27 258 end
Nenue@34 259 text = data.text
Nenue@31 260 return text, attachment
Nenue@27 261 end
Nenue@27 262
Nenue@33 263 Bonus.Select = function(handler, block)
Nenue@33 264 print(handler, block)
Nenue@33 265 handler:OnTurnIn(block, block.info.questID)
Nenue@27 266 end
Nenue@27 267 Bonus.Remove = function(self)
Nenue@27 268
Nenue@27 269 end