-
Notifications
You must be signed in to change notification settings - Fork 6
/
SkilletPlugin.lua
258 lines (234 loc) · 8.12 KB
/
SkilletPlugin.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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
local addonName,addonTable = ...
local DA = _G[addonName] -- for DebugAids.lua
--[[
Skillet: A tradeskill window replacement.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
]]--
local L = Skillet.L
Skillet.registeredPlugins = {} -- plugins that have registered a function
Skillet.updatePlugins = {} -- each plugin will register if it has an Update function
Skillet.processQueuePlugins = {} -- each plugin will register if it has a ProcessQueue function
Skillet.displayDetailPlugins = {} -- each plugin will register if it has a GetExtraText function
Skillet.RecipeNamePrefixes = {} -- each plugin will register, only one can be active
Skillet.RecipeNameSuffixes = {} -- each plugin will register, only one can be active
Skillet.pluginsOrder = 2
Skillet.pluginsOptions = {
name = "Plugins",
type = "group",
childGroups = "tree",
args = {
RecipeNamePrefix = {
type = "select",
name = "RecipeNamePrefix",
desc = "Only one plugin can supply prefix text",
order = 1,
get = function()
return Skillet.db.profile.plugins.recipeNamePrefix
end,
set = function(_, value)
Skillet.db.profile.plugins.recipeNamePrefix = value
Skillet:UpdateTradeSkillWindow()
end,
values = {
[" "] = " ",
-- Additional entries filled in dynamically by RegisterRecipeNamePlugin
},
},
RecipeNameSuffix = {
type = "select",
name = "RecipeNameSuffix",
desc = "Only one plugin can supply suffix text",
order = 1,
get = function()
return Skillet.db.profile.plugins.recipeNameSuffix
end,
set = function(_, value)
Skillet.db.profile.plugins.recipeNameSuffix = value
Skillet:UpdateTradeSkillWindow()
end,
values = {
[" "] = " ",
-- Additional entries filled in dynamically by RegisterRecipeNamePlugin
},
},
-- Filled in dynamically by AddPluginOptions
},
}
function Skillet:AddPluginOptions(options)
options.order = Skillet.pluginsOrder
Skillet.pluginsOrder = Skillet.pluginsOrder + 1
Skillet.pluginsOptions.args[options.name] = options
end
function Skillet:RegisterRecipeNamePlugin(moduleName, priority)
DA.DEBUG(0,"RegisterRecipeNamePlugin("..tostring(moduleName)..", "..tostring(priority))
if not priority then priority = 100 end
if type(moduleName) == "string" then
local module = Skillet[moduleName]
if module and type(module) == "table" then
if module.RecipeNamePrefix then
Skillet.RecipeNamePrefixes[moduleName] = module
Skillet.registeredPlugins[moduleName] = module
Skillet.pluginsOptions.args.RecipeNamePrefix.values[module.options.name] = module.options.name
end
if module.RecipeNameSuffix then
Skillet.RecipeNameSuffixes[moduleName] = module
Skillet.registeredPlugins[moduleName] = module
Skillet.pluginsOptions.args.RecipeNameSuffix.values[module.options.name] = module.options.name
end
end
end
end
function Skillet:IsRecipeNamePluginRegistered(moduleName)
if type(moduleName) == "string" then
return Skillet.RecipeNamePlugins[moduleName] ~= nil
end
end
function Skillet:RegisterDisplayDetailPlugin(moduleName, priority)
DA.DEBUG(0,"RegisterDisplayDetailPlugin("..tostring(moduleName)..", "..tostring(priority))
if not priority then priority = 100 end
if type(moduleName) == "string" then
local module = Skillet[moduleName]
if module and type(module) == "table" and module.GetExtraText then
Skillet.displayDetailPlugins[moduleName] = module
Skillet.registeredPlugins[moduleName] = module
end
end
end
function Skillet:IsDisplayDetailPluginRegistered(moduleName)
if type(moduleName) == "string" then
return Skillet.displayDetailPlugins[moduleName] ~= nil
end
end
function Skillet:RegisterUpdatePlugin(moduleName, priority)
DA.DEBUG(0,"RegisterUpdatePlugin("..tostring(moduleName)..", "..tostring(priority))
if not priority then priority = 100 end
if type(moduleName) == "string" then
local module = Skillet[moduleName]
if module and type(module) == "table" and module.Update then
Skillet.updatePlugins[moduleName] = module
Skillet.registeredPlugins[moduleName] = module
end
end
end
function Skillet:IsUpdatePluginRegistered(moduleName)
if type(moduleName) == "string" then
return Skillet.updatePlugins[moduleName] ~= nil
end
end
function Skillet:UpdatePlugins()
--DA.DEBUG(0,"UpdatePlugins()")
for k,v in pairs(Skillet.updatePlugins) do
v.Update()
end
end
function Skillet:RegisterProcessQueuePlugin(moduleName, priority)
DA.DEBUG(0,"RegisterProcessQueuePlugin("..tostring(moduleName)..", "..tostring(priority))
if not priority then priority = 100 end
if type(moduleName) == "string" then
local module = Skillet[moduleName]
if module and type(module) == "table" and module.ProcessQueue then
Skillet.processQueuePlugins[moduleName] = module
Skillet.registeredPlugins[moduleName] = module
end
end
end
function Skillet:IsProcessQueuePluginRegistered(moduleName)
if type(moduleName) == "string" then
return Skillet.processQueuePlugins[moduleName] ~= nil
end
end
function Skillet:ProcessQueuePlugins()
--DA.DEBUG(0,"ProcessQueuePlugins()")
for k,v in pairs(Skillet.processQueuePlugins) do
v.ProcessQueue()
end
end
function Skillet:GetExtraText(skill, recipe)
local output_label, output_text
for k,v in pairs(Skillet.displayDetailPlugins) do
local label,text = v.GetExtraText(skill, recipe)
if label and label ~= "" then
if output_label then
output_label = output_label.."\n\n"
else
output_label = ""
end
output_label = output_label..label
end
if text and text ~= "" then
if output_text then
output_text = output_text.."\n\n"
else
output_text = ""
end
output_text = output_text..text
end
end
return output_label, output_text
end
function Skillet:RecipeNamePrefix(skill, recipe)
local text
local recipeNamePrefix = self.db.profile.plugins.recipeNamePrefix
if recipeNamePrefix and recipeNamePrefix ~= " " then
for k,v in pairs(Skillet.RecipeNamePrefixes) do
--DA.DEBUG(1,"k= "..tostring(k)..", v= "..tostring(v))
if v.RecipeNamePrefix and v.options.name == recipeNamePrefix then
text = v.RecipeNamePrefix(skill, recipe)
--DA.DEBUG(1,"text= "..tostring(text))
break
end
end
end
return text
end
function Skillet:RecipeNameSuffix(skill, recipe)
local text
local recipeNameSuffix = self.db.profile.plugins.recipeNameSuffix
if recipeNameSuffix and recipeNameSuffix ~= " " then
for k,v in pairs(Skillet.RecipeNameSuffixes) do
--DA.DEBUG(1,"k= "..tostring(k)..", v= "..tostring(v))
if v.RecipeNameSuffix and v.options.name == recipeNameSuffix then
text = v.RecipeNameSuffix(skill, recipe)
--DA.DEBUG(1,"text= "..tostring(text))
break
end
end
end
return text
end
function Skillet:InitializePlugins()
DA.DEBUG(0,"InitializePlugins()")
for k,v in pairs(Skillet.registeredPlugins) do
if v and v.OnInitialize then
DA.DEBUG(1,"InitializePlugins: k= "..tostring(k)..", v= "..tostring(v))
v.OnInitialize()
end
end
end
function Skillet:EnablePlugins()
DA.DEBUG(0,"EnablePlugins()")
for k,v in pairs(Skillet.registeredPlugins) do
if v and v.OnEnable then
DA.DEBUG(1,"EnablePlugins: k= "..tostring(k)..", v= "..tostring(v))
v.OnEnable()
end
end
end
function Skillet:DisablePlugins()
DA.DEBUG(0,"DisablePlugins()")
for k,v in pairs(Skillet.registeredPlugins) do
if v and v.OnDisable then
DA.DEBUG(1,"DisablePlugins: k= "..tostring(k)..", v= "..tostring(v))
v.OnDisable()
end
end
end