comparison 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
comparison
equal deleted inserted replaced
20:6bd2102d340b 21:d5ee940de273
31 AutoQuest.LogBlock = {} 31 AutoQuest.LogBlock = {}
32 AutoQuest.QuestBlock = {} 32 AutoQuest.QuestBlock = {}
33 AutoQuest.WatchBlock = {} 33 AutoQuest.WatchBlock = {}
34 function AutoQuest:GetNumWatched () 34 function AutoQuest:GetNumWatched ()
35 print(self.name, self) 35 print(self.name, self)
36 Quest:GetNumWatched()
36 self.numWatched = GetNumAutoQuestPopUps() 37 self.numWatched = GetNumAutoQuestPopUps()
38
37 return self.numWatched 39 return self.numWatched
38 end 40 end
39 AutoQuest.GetInfo = function(self, popupIndex) 41 AutoQuest.GetInfo = function(self, popupIndex)
40 42
41 local questID, type = GetAutoQuestPopUp(popupIndex) 43 local questID, type = GetAutoQuestPopUp(popupIndex)
42 local questIndex = GetQuestLogIndexByID(questID) 44 local questIndex = GetQuestLogIndexByID(questID)
43 local questWatchIndex = GetQuestWatchIndex(questIndex) 45 local title, level, suggestedGroup, isHeader, isCollapsed, isComplete, frequency, questID, startEvent, displayQuestID, isOnMap, hasLocalPOI, isTask, isStory = GetQuestLogTitle(questIndex)
44 46
45 local questInfo = Quest:GetInfo(questWatchIndex)
46 self.Info[questID] = { 47 self.Info[questID] = {
47 title = questInfo.title, 48 title = title,
48 description = type, 49 description = type,
49 popupType = type, 50 popupType = type,
50 questID = questID, 51 questID = questID,
51 questIndex = questIndex, 52 questIndex = questIndex,
52 popupIndex = popupIndex, 53 popupIndex = popupIndex,
53 watchIndex = questWatchIndex,
54 numObjectives = 0
55 } 54 }
55 self.WatchInfo[popupIndex] = self.Info[questID]
56 56
57 57
58 return self.Info[questID] 58 return self.Info[questID]
59 end 59 end
60 60
61 ----------------------------- 61 -----------------------------
62 --- BONUS OBJECTIVE 62 --- BONUS OBJECTIVE
63 Bonus.TasksTable = {} 63 -- The default UI pops them up as you enter their relevant areas, but the data is actually available at all times.
64 Bonus.TasksPOI = {} 64 -- The only requirement is that you've been to said area and progressed any of the objectives.
65 Bonus.TaskScenario = {} 65 -- Blizzard deal with this fact by caching any task data collected during session and masking out whatever gets completed.
66 66 -- For the addon's module structure to work, GetNumWatched method also invokes a tasks table scan.
67 local taskData = {} 67 -- That composes the table searched by GetInfo().
68
69 ------------------------------------------------------------------------------------------
70 --- These functions are copied from Blizzard_BonusObjectiveTracker.lua;
71 -- It's kind of dumb, but this avoids the risk of code taint.
72
73 --- Returns a tasks table modified to include recently completed objectives
74 local completedTasks = {}
75 local InternalGetTasksTable = function()
76 local tasks = GetTasksTable()
77 for questID, data in pairs(completedTasks) do
78 if questID > 0 then
79 local found = false
80 for i = 1, #tasks do
81 if tasks[i] == questID then
82 found = true
83 break
84 end
85 end
86 -- if it's not part of the current table, then try to insert it where it was last found
87 if not found then
88 if data.watchIndex < #tasks then
89 tinsert(tasks, data.watchIndex, data)
90 else
91 tinsert(tasks, data)
92 end
93 end
94 end
95 end
96 return tasks
97 end
98
99 --- Returns an entry from the composed tasks table if possible, otherwise makes an API pull
100 local InternalGetTaskInfo = function(questID)
101 if completedTasks[questID] then
102 return true, true, #completedTasks[questID].objectives
103 else
104 return GetTaskInfo(questID)
105 end
106 end
107
108 --- Same as above but for the objective entries
109 local InternalGetQuestObjectiveInfo = function(questID, objectiveIndex)
110 if ( completedTasks[questID] ) then
111 return completedTasks[questID].objectives[objectiveIndex], completedTasks[questID].objectiveType, true;
112 else
113 return GetQuestObjectiveInfo(questID, objectiveIndex, false);
114 end
115 end
116
117 --- end redundant copy of silliness
118 ------------------------------------------------------------------------------------------
119
120 Bonus.Completed = {}
121 Bonus.POI = {}
122 Bonus.Scenario = {}
68 Bonus.QuestBlock = {} 123 Bonus.QuestBlock = {}
69 Bonus.TaskWatch = {}
70 function Bonus:GetNumWatched () 124 function Bonus:GetNumWatched ()
71 print(self.name, self) 125 print(self.name, self)
72 local tasks = GetTasksTable() 126 local tasks = InternalGetTasksTable()
73 local numTasks = 0 127 local numWatched = 0
74 Bonus.TaskWatch = {} 128 local numAll = 0
129 self.WatchInfo = {}
75 print('|cFFFFFF00Bonus.GetNumWatched()|r', #tasks) 130 print('|cFFFFFF00Bonus.GetNumWatched()|r', #tasks)
76 for i, questID in ipairs(tasks) do 131 for i, questID in ipairs(tasks) do
77 local t = Bonus.StoreTask(questID) 132 local isInArea, isOnMap, numObjectives = InternalGetTaskInfo(questID)
78 print (' taskIndex', i, 'questID', questID) 133 local existingTask = self.QuestBlock[questID]
79 print(' isComplete', t.isComplete) 134 local displayObjectiveHeader = false;
80 if (t.inInArea or t.isOnMap) and not t.isComplete then 135 print (' |cFF00FF00taskIndex', i, 'questID', questID, 'inArea', isInArea, 'onMap', isOnMap, 'existing', (existingTask and 'Y' or 'N'))
81 numTasks = numTasks + 1 136 if isInArea or isOnMap then
82 Bonus.TaskWatch[numTasks] = t 137 self.Info[questID] = self.Info[questID] or {}
83 end 138
84 end 139 local t = self.Info[questID]
85 Bonus.numAll = #Bonus.TasksTable 140 local title = GetQuestLogTitle(questID)
86 Bonus.numWatched = numTasks 141 self.WatchInfo[i] = t
142 t.title = title
143 t.isInArea = isInArea
144 t.isOnMap = isOnMap
145 t.existingTask = existingTask
146 t.questID = questID
147 t.objectives = {}
148 t.taskIndex = i
149
150 local taskFinished = true;
151 for objectiveIndex = 1, numObjectives do
152 local text, objectiveType, finished, displayAsObjective = InternalGetQuestObjectiveInfo(questID, objectiveIndex, false);
153 displayObjectiveHeader = displayObjectiveHeader or displayAsObjective;
154 print(' --', text, objectiveType, finished, displayAsObjective)
155 t.objectives[objectiveIndex] = t.objectives[objectiveIndex] or {}
156 local o = t.objectives[objectiveIndex]
157
158 o.objectiveIndex = objectiveIndex
159 o.text = text
160 o.objectiveType = objectiveType
161 o.finished = finished
162 o.displayAsObjective = displayAsObjective
163 print(' |cFF00FF88*', objectiveIndex, text)
164 end
165 end
166 end
167
168
169 self.numAll = #tasks
170 self.numWatched = #self.WatchInfo
171 print(' stats:', self.numAll, 'active tasks,', self.numWatched, 'nearby or animating')
172 --return #tasks
87 return GetNumQuestLogTasks() 173 return GetNumQuestLogTasks()
88 end 174 end
89 175
90 Bonus.GetInfo = function(self, taskIndex) 176 Bonus.GetInfo = function(self, taskIndex)
91 print(self.name, self) 177 print(self.name, self)
92 return Bonus.TaskWatch[taskIndex] 178 return self.WatchInfo[taskIndex]
93 end 179 end
94 180
95 Bonus.StoreTask = function(questID) 181 Bonus.Store = function(questID)
96 182
97 if not questID then 183 if not questID then
98 print('|cFFFF4400invalid quest ID', questID) 184 print('|cFFFF4400invalid quest ID', questID)
99 return 185 return
100 end 186 end
345 end 431 end
346 end 432 end
347 433
348 434
349 Cheevs.GetNumWatched = function(self) 435 Cheevs.GetNumWatched = function(self)
436 print('|cFF00FF00' .. GetTime())
350 Cheevs.trackedCheevs = {GetTrackedAchievements()} 437 Cheevs.trackedCheevs = {GetTrackedAchievements()}
351 return GetNumTrackedAchievements() 438 return GetNumTrackedAchievements()
352 end 439 end
353 Cheevs.GetInfo = function(self, index) 440 Cheevs.GetInfo = function(self, index)
354 local cheevID = Cheevs.trackedCheevs[index] 441 local cheevID = Cheevs.trackedCheevs[index]
365 c.numObjectives = GetAchievementNumCriteria(cheevID) 452 c.numObjectives = GetAchievementNumCriteria(cheevID)
366 c.objectives = {} 453 c.objectives = {}
367 for i = 1, c.numObjectives do 454 for i = 1, c.numObjectives do
368 local description, type, completed, quantity, requiredQuantity, characterName, flags, assetID, quantityString, criteriaID = GetAchievementCriteriaInfo(cheevID, i) 455 local description, type, completed, quantity, requiredQuantity, characterName, flags, assetID, quantityString, criteriaID = GetAchievementCriteriaInfo(cheevID, i)
369 c.objectives[i] = { 456 c.objectives[i] = {
370 index = i, 457 objectiveIndex = i,
371 cheevID = cheevID, 458 cheevID = cheevID,
372 text = description, 459 text = description,
373 type = type, 460 type = type,
374 finished = completed, 461 finished = completed,
375 value = quantity, 462 value = quantity,