disable the flight stuff for now, we'll fix it after thanksgiving
[QuestHelper.git] / collect.lua
blob0a7ca99129e2c6502ac3f9923e25b8329faa0b4f
1 QuestHelper_File["collect.lua"] = "Development Version"
3 local QuestHelper_Collector_Version_Current = 3
5 QuestHelper_Collector = {}
6 QuestHelper_Collector_Version = QuestHelper_Collector_Version_Current
8 local EventRegistrar = {}
9 local OnUpdateRegistrar = {}
10 local TooltipRegistrar = {}
12 local frame = CreateFrame("Frame")
14 local function OnEvent(_, event, ...)
15 local tstart = GetTime()
16 for _, v in pairs(EventRegistrar[event]) do
17 v(...)
18 end
19 QH_Timeslice_Increment(GetTime() - tstart, "collect_event")
20 end
22 frame:UnregisterAllEvents()
23 frame:SetScript("OnEvent", OnEvent)
25 frame:Show()
27 function EventHookRegistrar(event, func)
28 QuestHelper:Assert(func)
29 if not EventRegistrar[event] then
30 frame:RegisterEvent(event)
31 EventRegistrar[event] = {}
32 end
33 table.insert(EventRegistrar[event], func)
34 end
36 function OnUpdateHookRegistrar(func)
37 QuestHelper:Assert(func)
38 table.insert(OnUpdateRegistrar, func)
39 end
41 local OriginalScript = GameTooltip:GetScript("OnShow")
42 GameTooltip:SetScript("OnShow", function (self, ...)
43 local tstart = GetTime()
44 for k, v in pairs(TooltipRegistrar) do
45 v(self, ...)
46 end
47 QH_Timeslice_Increment(GetTime() - tstart, "collect_tooltip") -- anything past here is not my fault
48 if OriginalScript then
49 return OriginalScript(Self, ...)
50 end
51 end)
53 function TooltipHookRegistrar(func)
54 QuestHelper:Assert(func)
55 table.insert(TooltipRegistrar, func)
56 end
58 local API = {
59 Registrar_EventHook = EventHookRegistrar,
60 Registrar_OnUpdateHook = OnUpdateHookRegistrar,
61 Registrar_TooltipHook = TooltipHookRegistrar,
62 Callback_RawLocation = function () return QuestHelper:RetrieveRawLocation() end,
65 function QH_Collector_Init()
66 -- First we update shit
67 if QuestHelper_Collector_Version == 1 then
68 -- We basically just want to clobber all our old route data, it's not worth storing - it's all good data, it's just that we don't want to preserve relics of the old location system.
69 for _, v in pairs(QuestHelper_Collector) do
70 v.traveled = nil
71 end
73 QuestHelper_Collector_Version = 2
74 end
76 if QuestHelper_Collector_Version == 2 then
77 -- Originally I split the zones based on locale. Later I just split everything based on locale. Discarding old data rather than doing the gymnastics needed to preserve it.
78 -- This is turning into a routine. :D
79 for _, v in pairs(QuestHelper_Collector) do
80 v.zone = nil
81 end
83 QuestHelper_Collector_Version = 3
84 end
86 QuestHelper: Assert(QuestHelper_Collector_Version == QuestHelper_Collector_Version_Current)
88 local sig = string.format("%s on %s/%s/%d", GetAddOnMetadata("QuestHelper", "Version"), GetBuildInfo(), GetLocale(), QuestHelper:PlayerFaction())
89 if not QuestHelper_Collector[sig] then QuestHelper_Collector[sig] = {} end
90 local QHCData = QuestHelper_Collector[sig]
92 QH_Collect_Location_Init(nil, API) -- Some may actually add their own functions to the API, and should go first. There's no real formalized order, I just know which depend on others. Location's sole job is to provide the standard location bolus. (Yeah. It's a bolus. Deal.)
93 QH_Collect_Merger_Init(nil, API) -- etc
94 QH_Collect_Patterns_Init(nil, API) -- etc
96 QH_Collect_LZW_Init(nil, API) -- Depends on Merger
98 QH_Collect_Achievement_Init(QHCData, API)
99 QH_Collect_Traveled_Init(QHCData, API)
100 QH_Collect_Zone_Init(QHCData, API)
101 QH_Collect_Monster_Init(QHCData, API)
102 QH_Collect_Item_Init(QHCData, API)
103 QH_Collect_Object_Init(QHCData, API)
104 QH_Collect_Flight_Init(QHCData, API)
106 if not QHCData.realms then QHCData.realms = {} end
107 QHCData.realms[GetRealmName()] = (QHCData.realms[GetRealmName()] or 0) + 1 -- I'm not entirely sure why I'm counting
110 function QH_Collector_OnUpdate()
111 local tstart = GetTime()
112 for _, v in pairs(OnUpdateRegistrar) do
115 QH_Timeslice_Increment(GetTime() - tstart, "collect_update")