-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAM.lua
151 lines (117 loc) · 4.13 KB
/
AM.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
-----------------------------------------------------------------------------------------------
-- Client Lua Script for AddonsMonitor
-----------------------------------------------------------------------------------------------
local iAddonVersion = 5
---------------------------------------------------------------------------------------------------
-- addons monitor main class
---------------------------------------------------------------------------------------------------
local AMutils = _G.AddonsManagerStuff.AMutils
local AMdataManager = _G.AddonsManagerStuff.AMdataManager
local AMwindow = _G.AddonsManagerStuff.AMwindow
local AMgrid = _G.AddonsManagerStuff.AMgrid
local AMpanel = _G.AddonsManagerStuff.AMpanel
local AM = {}
AM.fRefreshInterval = 1
AM.iHistoryGroupSeconds = 10
--- public interface below ---
function AM:new()
local o = {}
setmetatable(o, self)
self.__index = self
o:_init()
return o
end
function AM:Toggle(bTurnOn, bShowLivePanel)
self.oAMwindow:Toggle(bTurnOn, bShowLivePanel)
end
--- private methods below ---
function AM:_init()
self.bDataLoaded = false
self.bSettingsLoaded = false
self.iHistoryCleanupToMin = 240 -- 4 hours
self.iHistoryCleanupTo = nil
self.iHistoryCleanupAt = nil
end
function AM:OnLoad()
self.oAMpanel = AMpanel:new()
self.oAMwindow = AMwindow:new()
self.oAMdataManager = AMdataManager:new()
Apollo.RegisterSlashCommand("addons_monitor", "OnToggleFromSlash", self)
Apollo.RegisterSlashCommand("am_max", "OnSetMaxHistory", self)
Apollo.RegisterTimerHandler("AddonsMonitor_LiveRefreshInterval", "OnLiveRefreshInterval", self)
end
function AM:OnSave(eLevel)
local tSettings = {}
tSettings.iAddonVersion = iAddonVersion
if eLevel == GameLib.CodeEnumAddonSaveLevel.General then
tSettings.tData = self.oAMdataManager:GetData()
tSettings.iHistoryCleanupToMin = self.iHistoryCleanupToMin
return tSettings
end
if eLevel == GameLib.CodeEnumAddonSaveLevel.Account then
tSettings.tAMwindowConfig = self.oAMwindow:GetConfiguration()
tSettings.tAMpanelConfig = self.oAMpanel:GetConfiguration()
tSettings.tAMgridLiveConfig = self.oAMwindow:GetLiveGridConfiguration()
return tSettings
end
return nil
end
function AM:OnRestore(eLevel, tConfig)
if eLevel == GameLib.CodeEnumAddonSaveLevel.General then
self.oAMdataManager:SetData(tConfig.tData, tConfig.iAddonVersion)
if tConfig.iHistoryCleanupToMin then
self.iHistoryCleanupToMin = tConfig.iHistoryCleanupToMin
end
self.bDataLoaded = true
self:Initialize()
return
end
if eLevel == GameLib.CodeEnumAddonSaveLevel.Account then
self.oAMwindow:SetConfiguration(tConfig.tAMwindowConfig, tConfig.iAddonVersion)
self.oAMpanel:SetConfiguration(tConfig.tAMpanelConfig, tConfig.iAddonVersion)
self.oAMwindow:SetLiveGridConfiguration(tConfig.tAMgridLiveConfig, tConfig.iAddonVersion)
self.bSettingsLoaded = true
self:Initialize()
return
end
end
function AM:Initialize()
if not self.bDataLoaded or not self.bSettingsLoaded then
return
end
self:UpdateHistoryValues()
self.oAMdataManager:InitializeDataCollection()
self.oAMwindow:InitializeGridView()
Apollo.CreateTimer("AddonsMonitor_LiveRefreshInterval", self.fRefreshInterval, true)
self:OnLiveRefreshInterval(true)
end
function AM:OnToggleFromSlash()
self:Toggle()
end
function AM:OnSetMaxHistory(sCommand, sValue)
local iValue = tonumber(sValue)
self.iHistoryCleanupToMin = iValue
self:UpdateHistoryValues()
RequestReloadUI()
end
function AM:UpdateHistoryValues()
local iGroupsPerMinute = 60 / self.iHistoryGroupSeconds
if self.iHistoryCleanupToMin < 30 then
self.iHistoryCleanupToMin = 30
end
self.iHistoryCleanupTo = self.iHistoryCleanupToMin * iGroupsPerMinute
if self.iHistoryCleanupToMin < 60 then
self.iHistoryCleanupAt = self.iHistoryCleanupTo + iGroupsPerMinute
else
self.iHistoryCleanupAt = self.iHistoryCleanupTo + 10 * iGroupsPerMinute
end
end
function AM:OnLiveRefreshInterval(bIsFirst)
self.oAMdataManager:UpdateStatsLive(bIsFirst == true)
self.oAMwindow:RefreshLiveWindow()
if bIsFirst then
self.oAMwindow:RefreshHistoryWindow()
end
end
_G.AddonsManagerStuff.oAM = AM:new()
Apollo.RegisterAddon(_G.AddonsManagerStuff.oAM)