-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.lua
209 lines (190 loc) · 7.51 KB
/
core.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
local name = ...;
--- @class MPT_NS
local MPT = select(2, ...);
--@debug@
_G.MythicPlusTweaks = MPT;
if not _G.MPT then _G.MPT = MPT; end
--@end-debug@
--- @class MPT_Main: AceAddon,AceHook-3.0,AceEvent-3.0,AceConsole-3.0
local Main = LibStub('AceAddon-3.0'):NewAddon(name, 'AceConsole-3.0', 'AceHook-3.0', 'AceEvent-3.0');
if not Main then return; end
MPT.Main = Main;
function Main:OnInitialize()
if NumyProfiler then
--- @type NumyProfiler
local NumyProfiler = NumyProfiler;
NumyProfiler:WrapModules(name, 'Main', self);
NumyProfiler:WrapModules(name, 'Util', MPT.Util);
for moduleName, module in self:IterateModules() do
NumyProfiler:WrapModules(name, moduleName, module);
end
end
MythicPlusTweaksDB = MythicPlusTweaksDB or {};
self.db = MythicPlusTweaksDB;
self.version = C_AddOns.GetAddOnMetadata(name, 'Version') or '';
self:InitDefaults();
for moduleName, module in self:IterateModules() do
if self.db.modules[moduleName] == false then
module:Disable();
end
end
self:InitConfig();
self:RegisterChatCommand('mpt', function() self:OpenConfig(); end);
end
function Main:InitDefaults()
local defaults = {
modules = {},
moduleDb = {},
inlineConfig = true,
};
for key, value in pairs(defaults) do
if self.db[key] == nil then
self.db[key] = value;
end
end
end
function Main:InitConfig()
local search = '';
local increment = CreateCounter();
local inline = self.db.inlineConfig;
local function registerOptions()
LibStub('AceConfig-3.0'):RegisterOptionsTable(self.configCategory, self.options);
end
self.options = {
type = 'group',
name = 'Mythic+ Tweaks',
desc = 'Various tweaks related to mythic+',
childGroups = 'tab',
args = {
version = {
order = increment(),
type = 'description',
name = 'Version: ' .. self.version,
},
modules = {
order = increment(),
type = 'group',
name = 'Modules',
childGroups = 'tree',
inline = inline,
args = {
desc = {
order = increment(),
width = 'full',
type = 'description',
name = 'This addon consists of a number of modules, each of which can be enabled or disabled, to fine-tune your experience.',
},
inlineConfig = {
name = 'Show options as a list',
type = 'toggle',
desc = 'Show the module options in one long list, instead of a tree.',
order = increment(),
get = function() return inline; end,
set = function(_, value)
inline = value;
self.db.inlineConfig = value;
self.options.args.modules.inline = value;
registerOptions();
end,
},
filter = {
name = 'Filter',
type = 'input',
desc = 'Search by module name or description, or \'-\' for disabled modules, or \'+\' for enabled modules.',
order = increment(),
hidden = function() return not inline end,
get = function() return search; end,
set = function(_, value) search = value; end
},
clear = {
name = 'Clear',
type = 'execute',
desc = 'Clear the search filter.',
order = increment(),
hidden = function() return not inline end,
func = function() search = ''; end,
width = 0.5,
},
},
},
},
};
local function hiddenFunc(info)
if not inline then return false; end
if 2 ~= #info then return false; end -- prevents the function from running when it's inherited down the option chain
local moduleName = info[#info];
local module = Main:GetModule(moduleName, true);
if not module then return false; end
if '' == search then return false; end
if '+' == search or "'+'" == search then return not Main:IsModuleEnabled(moduleName); end
if '-' == search or "'-'" == search then return Main:IsModuleEnabled(moduleName); end
local displayName = module.GetName and module:GetName() or moduleName;
local desc = module.GetDescription and module:GetDescription() or '';
return not (displayName:lower():find(search:lower()) or desc:lower():find(search:lower()));
end
local subIncrement = CreateCounter();
local defaultModuleOptions = {
type = 'group',
name = function(info)
return info[#info - 1];
end,
hidden = hiddenFunc,
args = {
name = {
order = subIncrement(),
type = 'header',
hidden = function() return inline end,
name = function(info)
return info.options.args.modules.args[info[#info - 1]].name;
end,
},
description = {
order = subIncrement(),
type = 'description',
name = function(info)
local module = Main:GetModule(info[#info - 1]);
return module.GetDescription and module:GetDescription() or '';
end,
hidden = function(info)
return '' == info.option.name(info)
end,
},
enable = {
order = subIncrement(),
name = 'Enable',
desc = 'Enable this module',
type = 'toggle',
get = function(info) return Main:IsModuleEnabled(info[#info - 1]); end,
set = function(info, enabled) Main:SetModuleState(info[#info - 1], enabled); end,
},
},
};
local subIncrementCount = subIncrement();
for moduleName, module in self:IterateModules() do
local copy = CopyTable(defaultModuleOptions);
self.db.moduleDb[moduleName] = self.db.moduleDb[moduleName] or {};
local moduleIncrement = CreateCounter(subIncrementCount);
local moduleOptions = module.GetOptions and module:GetOptions(copy, self.db.moduleDb[moduleName], moduleIncrement) or copy;
moduleOptions.name = module.GetName and module:GetName() or moduleName;
moduleOptions.order = increment();
self.options.args.modules.args[moduleName] = moduleOptions;
end
self.configCategory = 'Mythic+ Tweaks';
registerOptions();
LibStub('AceConfigDialog-3.0'):AddToBlizOptions(self.configCategory);
end
function Main:OpenConfig()
Settings.OpenToCategory(self.configCategory);
end
function Main:SetModuleState(moduleName, enabled)
if enabled then
self:EnableModule(moduleName);
else
self:DisableModule(moduleName);
end
self.db.modules[moduleName] = enabled;
end
function Main:IsModuleEnabled(moduleName)
local module = self:GetModule(moduleName);
return module and module:IsEnabled() or false;
end