annotate ObjectiveTracker/BonusObjectives.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
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@37 89 if true then return 0, 0, nil end
Nenue@33 90 local print = iprint
Nenue@29 91 print(self.name, self)
Nenue@29 92
Nenue@29 93 local tasks = InternalGetTasksTable()
Nenue@29 94 local numWatched = 0
Nenue@29 95 local numAll = 0
Nenue@33 96 local existingTasks = {}
Nenue@29 97 self.WatchInfo = {}
Nenue@29 98 print('|cFFFFFF00Bonus.GetNumWatched()|r', #tasks)
Nenue@34 99 print(' |cFF00FFFFInternalGetTaskInfo|r:')
Nenue@29 100 for i, questID in ipairs(tasks) do
Nenue@29 101 local isInArea, isOnMap, numObjectives = InternalGetTaskInfo(questID)
Nenue@29 102 local existingTask = self.QuestBlock[questID]
Nenue@29 103 local displayObjectiveHeader = false;
Nenue@29 104 local test = (isInArea or (isOnMap and existingTask))
Nenue@29 105 --local test = true
Nenue@29 106 if test then
Nenue@29 107 self.Info[questID] = self.Info[questID] or {}
Nenue@29 108
Nenue@29 109 local t = self.Info[questID]
Nenue@33 110 if (isOnMap or isInArea) and existingTask then
Nenue@33 111 t.areaID = GetCurrentMapAreaID()
Nenue@33 112 local _
Nenue@33 113 t.mapName, _, _, t.isMicroDungeon, t.microDungeonMapName = GetMapInfo()
Nenue@33 114 print('|cFF00FF00scooping map info (questID '..questID..'):|r', t.areaID, t.mapName)
Nenue@33 115 end
Nenue@29 116
Nenue@29 117 local taskTitle
Nenue@33 118 t.objectives = {}
Nenue@29 119 local taskFinished = true;
Nenue@29 120 for objectiveIndex = 1, numObjectives do
Nenue@29 121 local text, objectiveType, finished, displayAsObjective = InternalGetQuestObjectiveInfo(questID, objectiveIndex, false);
Nenue@29 122 displayObjectiveHeader = displayObjectiveHeader or displayAsObjective;
Nenue@29 123 if not taskTitle then
Nenue@29 124 if objectiveType == 'progressbar' and not text:match('^%d%+\\%d+') then
Nenue@29 125 taskTitle = text
Nenue@29 126 text = ''
Nenue@29 127 end
Nenue@29 128 end
Nenue@29 129
Nenue@29 130
Nenue@29 131 print(' --', text, objectiveType, finished, displayAsObjective)
Nenue@29 132 t.objectives[objectiveIndex] = t.objectives[objectiveIndex] or {}
Nenue@29 133 local o = t.objectives[objectiveIndex]
Nenue@29 134
Nenue@34 135 o.index = objectiveIndex
Nenue@29 136 o.text = text
Nenue@34 137 o.type = objectiveType
Nenue@29 138 o.finished = finished
Nenue@29 139 o.displayAsObjective = displayAsObjective
Nenue@29 140 end
Nenue@29 141
Nenue@33 142 T.SetRewards(t, questID)
Nenue@33 143
Nenue@29 144 -- didn't get a name from progress bar? what about area name
Nenue@29 145 if not taskTitle then
Nenue@29 146 if isInArea then
Nenue@29 147 taskTitle = GetMapNameByID(GetCurrentMapAreaID())
Nenue@29 148 end
Nenue@29 149 end
Nenue@34 150 t.numObjectives = numObjectives
Nenue@33 151 t.isInArea = isInArea
Nenue@33 152 t.isOnMap = isOnMap
Nenue@33 153 t.existingTask = existingTask
Nenue@33 154 t.questID = questID
Nenue@33 155 t.id = questID
Nenue@33 156 t.taskIndex = i
Nenue@29 157 t.title = taskTitle
Nenue@33 158 self.WatchInfo[i] = t
Nenue@29 159 end
Nenue@29 160
Nenue@29 161 print (' |cFF00FF88#', i, 'questID', questID, 'inArea', isInArea, 'onMap', isOnMap, 'existing', (existingTask and 'Y' or 'N'), (test and '|cFF00FF00show|r' or '|cFFFF0088hide|r'))
Nenue@29 162 end
Nenue@29 163
Nenue@36 164 for i = 1, #self.usedBlocks do
Nenue@36 165 self.usedBlocks[i]:Hide()
Nenue@36 166 end
Nenue@36 167
Nenue@29 168
Nenue@29 169 self.numAll = #tasks
Nenue@29 170 self.numWatched = #self.WatchInfo
Nenue@29 171 print(' stats:', self.numAll, 'active tasks,', self.numWatched, 'nearby or animating')
Nenue@29 172 --return #tasks
Nenue@29 173 return #self.WatchInfo
Nenue@29 174 end
Nenue@29 175
Nenue@29 176 --- info cleanup done when turn-ins are detected
Nenue@33 177 Bonus.OnTurnIn = function(self, block, questID, xp, money)
Nenue@33 178 local info = self.Info[questID]
Nenue@33 179 if info.rewardInfo and #info.rewardInfo >= 1 then
Nenue@33 180 for i, reward in ipairs(info.rewardInfo) do
Nenue@29 181 --[[
Nenue@29 182 type = 'item',
Nenue@29 183 index = i ,
Nenue@29 184 name = name,
Nenue@29 185 texture = texture,
Nenue@29 186 count = count,
Nenue@29 187 quality = quality,
Nenue@29 188 isUsable = isUsable
Nenue@29 189 ]]
Nenue@29 190 print(' reward ', i, ' ', reward.type, reward.name, reward.count)
Nenue@29 191
Nenue@29 192 end
Nenue@29 193 end
Nenue@29 194
Nenue@34 195 print('|cFFFF8800'..block:GetName()..':OnTurnIn call', questID, xp, money)
Nenue@34 196 local savedTasks = B.Conf.TasksLog or {}
Nenue@29 197
Nenue@33 198 info.completedTime = GetTime()
Nenue@33 199 info.animate = true
Nenue@34 200 T.SetAnimate(self.updateReasonModule)
Nenue@34 201 savedTasks[questID] = {
Nenue@34 202 id = questID,
Nenue@34 203 title = info.title,
Nenue@34 204 finished = true,
Nenue@34 205 numObjectives = info.numObjectives,
Nenue@34 206 objectives = info.objectives,
Nenue@34 207 rewardInfo = info.rewardInfo,
Nenue@34 208 }
Nenue@34 209 B.Conf.TasksLog = savedTasks
Nenue@34 210
Nenue@34 211 print(' ## CONF TASKLOG ##')
Nenue@34 212 for i, t in pairs(savedTasks[questID]) do
Nenue@34 213 print(' |cFFFFFF00'.. tostring(i)..'|r', t)
Nenue@34 214
Nenue@34 215 end
Nenue@34 216 for o, j in ipairs(savedTasks[questID].objectives) do
Nenue@34 217 print(' |cFF00FFFF#'.. o ..'|r', j.type, j.finished)
Nenue@34 218 end
Nenue@33 219
Nenue@33 220 print('adding', info.title, 'to cache')
Nenue@29 221 end
Nenue@29 222
Nenue@29 223 Bonus.GetInfo = function(self, taskIndex)
Nenue@29 224 print(self.name, self)
Nenue@29 225 return self.WatchInfo[taskIndex]
Nenue@29 226 end
Nenue@29 227
Nenue@29 228
Nenue@29 229
Nenue@29 230 --- Update hooks
Nenue@27 231 Bonus.UpdateObjectives = function(handler, block)
Nenue@27 232 Default.UpdateObjectives(handler, block)
Nenue@34 233 return 'default'
Nenue@27 234 end
Nenue@27 235
Nenue@33 236 Bonus.UpdateLine = function(handler, block, line, data)
Nenue@27 237 local info = block.info
Nenue@27 238 local print = lprint
Nenue@31 239 local text, attachment = '', nil
Nenue@27 240 line.displayColor = 'FFFFFF'
Nenue@34 241 if data.type == 'progressbar' then
Nenue@27 242 print(' |cFFFF44DDpercent='..tostring(GetQuestProgressBarPercent(info.questID)))
Nenue@33 243 local percent = 100
Nenue@34 244 attachment = T.SetWidget(line, data, 'ProgressBar', info.questID..'-'..data.index)
Nenue@33 245 if not data.finished then
Nenue@33 246 percent = GetQuestProgressBarPercent(info.questID)
Nenue@33 247 end
Nenue@34 248 data.value = percent
Nenue@34 249 data.maxValue = 100
Nenue@34 250
Nenue@34 251 print(attachment:GetNumPoints())
Nenue@34 252 for i = 1, attachment:GetNumPoints() do
Nenue@34 253 print(' ',attachment:GetPoint(i))
Nenue@34 254 end
Nenue@34 255
Nenue@34 256
Nenue@33 257 attachment.value = percent
Nenue@33 258 attachment.maxValue = 100
Nenue@31 259 attachment:SetPoint('TOP', line, 'TOP', 0, 0)
Nenue@34 260 attachment.status:SetFormattedText(PERCENTAGE_STRING, percent)
Nenue@37 261 attachment:SetParent(handler.frame)
Nenue@34 262 print(attachment.status:GetText())
Nenue@27 263 print(' |cFFFF0022** text:|r', data.text, '|cFFFF0022value:|r', data.value, '|cFFFF0022max:|r', data.maxValue)
Nenue@27 264 end
Nenue@34 265 text = data.text
Nenue@31 266 return text, attachment
Nenue@27 267 end
Nenue@27 268
Nenue@33 269 Bonus.Select = function(handler, block)
Nenue@33 270 print(handler, block)
Nenue@33 271 handler:OnTurnIn(block, block.info.questID)
Nenue@27 272 end
Nenue@27 273 Bonus.Remove = function(self)
Nenue@27 274
Nenue@27 275 end