Mercurial > wow > buffalo2
diff ObjectiveInfo.lua @ 21:d5ee940de273
use hardcoded aesthetic manipulations over loadstring cramming
author | Nenue |
---|---|
date | Fri, 08 Apr 2016 06:12:05 -0400 |
parents | 605e8f0e46db |
children | 9b3fa734abff |
line wrap: on
line diff
--- a/ObjectiveInfo.lua Wed Apr 06 07:54:19 2016 -0400 +++ b/ObjectiveInfo.lua Fri Apr 08 06:12:05 2016 -0400 @@ -33,26 +33,26 @@ AutoQuest.WatchBlock = {} function AutoQuest:GetNumWatched () print(self.name, self) + Quest:GetNumWatched() self.numWatched = GetNumAutoQuestPopUps() + return self.numWatched end AutoQuest.GetInfo = function(self, popupIndex) local questID, type = GetAutoQuestPopUp(popupIndex) local questIndex = GetQuestLogIndexByID(questID) - local questWatchIndex = GetQuestWatchIndex(questIndex) + local title, level, suggestedGroup, isHeader, isCollapsed, isComplete, frequency, questID, startEvent, displayQuestID, isOnMap, hasLocalPOI, isTask, isStory = GetQuestLogTitle(questIndex) - local questInfo = Quest:GetInfo(questWatchIndex) self.Info[questID] = { - title = questInfo.title, + title = title, description = type, popupType = type, questID = questID, questIndex = questIndex, popupIndex = popupIndex, - watchIndex = questWatchIndex, - numObjectives = 0 } + self.WatchInfo[popupIndex] = self.Info[questID] return self.Info[questID] @@ -60,39 +60,125 @@ ----------------------------- --- BONUS OBJECTIVE -Bonus.TasksTable = {} -Bonus.TasksPOI = {} -Bonus.TaskScenario = {} +-- The default UI pops them up as you enter their relevant areas, but the data is actually available at all times. +-- The only requirement is that you've been to said area and progressed any of the objectives. +-- Blizzard deal with this fact by caching any task data collected during session and masking out whatever gets completed. +-- For the addon's module structure to work, GetNumWatched method also invokes a tasks table scan. +-- That composes the table searched by GetInfo(). -local taskData = {} +------------------------------------------------------------------------------------------ +--- These functions are copied from Blizzard_BonusObjectiveTracker.lua; +-- It's kind of dumb, but this avoids the risk of code taint. + +--- Returns a tasks table modified to include recently completed objectives +local completedTasks = {} +local InternalGetTasksTable = function() + local tasks = GetTasksTable() + for questID, data in pairs(completedTasks) do + if questID > 0 then + local found = false + for i = 1, #tasks do + if tasks[i] == questID then + found = true + break + end + end + -- if it's not part of the current table, then try to insert it where it was last found + if not found then + if data.watchIndex < #tasks then + tinsert(tasks, data.watchIndex, data) + else + tinsert(tasks, data) + end + end + end + end + return tasks +end + +--- Returns an entry from the composed tasks table if possible, otherwise makes an API pull +local InternalGetTaskInfo = function(questID) + if completedTasks[questID] then + return true, true, #completedTasks[questID].objectives + else + return GetTaskInfo(questID) + end +end + +--- Same as above but for the objective entries +local InternalGetQuestObjectiveInfo = function(questID, objectiveIndex) + if ( completedTasks[questID] ) then + return completedTasks[questID].objectives[objectiveIndex], completedTasks[questID].objectiveType, true; + else + return GetQuestObjectiveInfo(questID, objectiveIndex, false); + end +end + +--- end redundant copy of silliness +------------------------------------------------------------------------------------------ + +Bonus.Completed = {} +Bonus.POI = {} +Bonus.Scenario = {} Bonus.QuestBlock = {} -Bonus.TaskWatch = {} function Bonus:GetNumWatched () print(self.name, self) - local tasks = GetTasksTable() - local numTasks = 0 - Bonus.TaskWatch = {} + local tasks = InternalGetTasksTable() + local numWatched = 0 + local numAll = 0 + self.WatchInfo = {} print('|cFFFFFF00Bonus.GetNumWatched()|r', #tasks) for i, questID in ipairs(tasks) do - local t = Bonus.StoreTask(questID) - print (' taskIndex', i, 'questID', questID) - print(' isComplete', t.isComplete) - if (t.inInArea or t.isOnMap) and not t.isComplete then - numTasks = numTasks + 1 - Bonus.TaskWatch[numTasks] = t + local isInArea, isOnMap, numObjectives = InternalGetTaskInfo(questID) + local existingTask = self.QuestBlock[questID] + local displayObjectiveHeader = false; + print (' |cFF00FF00taskIndex', i, 'questID', questID, 'inArea', isInArea, 'onMap', isOnMap, 'existing', (existingTask and 'Y' or 'N')) + if isInArea or isOnMap then + self.Info[questID] = self.Info[questID] or {} + + local t = self.Info[questID] + local title = GetQuestLogTitle(questID) + self.WatchInfo[i] = t + t.title = title + t.isInArea = isInArea + t.isOnMap = isOnMap + t.existingTask = existingTask + t.questID = questID + t.objectives = {} + t.taskIndex = i + + local taskFinished = true; + for objectiveIndex = 1, numObjectives do + local text, objectiveType, finished, displayAsObjective = InternalGetQuestObjectiveInfo(questID, objectiveIndex, false); + displayObjectiveHeader = displayObjectiveHeader or displayAsObjective; + print(' --', text, objectiveType, finished, displayAsObjective) + t.objectives[objectiveIndex] = t.objectives[objectiveIndex] or {} + local o = t.objectives[objectiveIndex] + + o.objectiveIndex = objectiveIndex + o.text = text + o.objectiveType = objectiveType + o.finished = finished + o.displayAsObjective = displayAsObjective + print(' |cFF00FF88*', objectiveIndex, text) + end end end - Bonus.numAll = #Bonus.TasksTable - Bonus.numWatched = numTasks + + + self.numAll = #tasks + self.numWatched = #self.WatchInfo + print(' stats:', self.numAll, 'active tasks,', self.numWatched, 'nearby or animating') + --return #tasks return GetNumQuestLogTasks() end Bonus.GetInfo = function(self, taskIndex) print(self.name, self) - return Bonus.TaskWatch[taskIndex] + return self.WatchInfo[taskIndex] end -Bonus.StoreTask = function(questID) +Bonus.Store = function(questID) if not questID then print('|cFFFF4400invalid quest ID', questID) @@ -347,6 +433,7 @@ Cheevs.GetNumWatched = function(self) + print('|cFF00FF00' .. GetTime()) Cheevs.trackedCheevs = {GetTrackedAchievements()} return GetNumTrackedAchievements() end @@ -367,7 +454,7 @@ for i = 1, c.numObjectives do local description, type, completed, quantity, requiredQuantity, characterName, flags, assetID, quantityString, criteriaID = GetAchievementCriteriaInfo(cheevID, i) c.objectives[i] = { - index = i, + objectiveIndex = i, cheevID = cheevID, text = description, type = type,