forked from Sidoine/Ovale
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScripts.lua
More file actions
295 lines (271 loc) · 8.76 KB
/
Scripts.lua
File metadata and controls
295 lines (271 loc) · 8.76 KB
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
--[[--------------------------------------------------------------------
Copyright (C) 2013, 2014 Johnny C. Lam.
See the file LICENSE.txt for copying permission.
--]]--------------------------------------------------------------------
-- This addon is a script repository.
local OVALE, Ovale = ...
local OvaleScripts = Ovale:NewModule("OvaleScripts", "AceEvent-3.0")
Ovale.OvaleScripts = OvaleScripts
--<private-static-properties>
local AceConfig = LibStub("AceConfig-3.0")
local AceConfigDialog = LibStub("AceConfigDialog-3.0")
local OvaleOptions = Ovale.OvaleOptions
local L = Ovale.L
-- Forward declarations for module dependencies.
local OvaleEquipment = nil
local OvalePaperDoll = nil
local OvaleSpellBook = nil
local OvaleStance = nil
local format = string.format
local gsub = string.gsub
local pairs = pairs
local strlower = string.lower
-- Name and description of default script.
local DEFAULT_NAME = "Ovale"
local DEFAULT_DESCRIPTION = L["Script défaut"]
-- Name and description of "custom" script.
local CUSTOM_NAME = "custom"
local CUSTOM_DESCRIPTION = L["Script personnalisé"]
-- Name and description of "disabled" script.
local DISABLED_NAME = "Disabled"
local DISABLED_DESCRIPTION = L["Disabled"]
do
local defaultDB = {
code = "",
source = "Ovale", -- The name given to all default class scripts.
showHiddenScripts = false,
}
local actions = {
code = {
name = L["Code"],
type = "execute",
func = function()
local appName = OvaleScripts:GetName()
AceConfigDialog:SetDefaultSize(appName, 700, 550)
AceConfigDialog:Open(appName)
end,
},
}
-- Insert defaults into OvaleOptions.
for k, v in pairs(defaultDB) do
OvaleOptions.defaultDB.profile[k] = v
end
for k, v in pairs(actions) do
OvaleOptions.options.args.actions.args[k] = v
end
OvaleOptions:RegisterOptions(OvaleScripts)
end
--</private-static-properties>
--<public-static-properties>
-- A "script" is a table { type = "scriptType", desc = "description", code = "..." }
-- Table of scripts, indexed by name.
OvaleScripts.script = {}
--</public-static-properties>
--<public-static-methods>
function OvaleScripts:OnInitialize()
-- Resolve module dependencies.
OvaleEquipment = Ovale.OvaleEquipment
OvalePaperDoll = Ovale.OvalePaperDoll
OvaleSpellBook = Ovale.OvaleSpellBook
OvaleStance = Ovale.OvaleStance
self:CreateOptions()
-- Register the default script that triggers the automatic script selection; the body code is ignored.
self:RegisterScript(nil, nil, DEFAULT_NAME, DEFAULT_DESCRIPTION, nil, "script")
-- Register the custom script.
self:RegisterScript(Ovale.playerClass, nil, CUSTOM_NAME, CUSTOM_DESCRIPTION, Ovale.db.profile.code, "script")
-- Register an empty script called "Disabled" that can be used to show no icons.
self:RegisterScript(nil, nil, DISABLED_NAME, DISABLED_DESCRIPTION, nil, "script")
end
function OvaleScripts:OnEnable()
self:RegisterMessage("Ovale_StanceChanged")
end
function OvaleScripts:OnDisable()
self:UnregisterMessage("Ovale_StanceChanged")
end
function OvaleScripts:Ovale_StanceChanged(event, newStance, oldStance)
end
-- Return a table of script descriptions indexed by name.
function OvaleScripts:GetDescriptions(scriptType)
local descriptionsTable = {}
for name, script in pairs(self.script) do
if (not scriptType or script.type == scriptType) and (not script.specialization or OvalePaperDoll:IsSpecialization(script.specialization)) then
if name == DEFAULT_NAME then
descriptionsTable[name] = script.desc .. " (" .. self:GetScriptName(name) .. ")"
else
descriptionsTable[name] = script.desc
end
end
end
return descriptionsTable
end
function OvaleScripts:RegisterScript(class, specialization, name, description, code, scriptType)
if not class or class == Ovale.playerClass then
self.script[name] = self.script[name] or {}
local script = self.script[name]
script.type = scriptType or "script"
script.desc = description or name
script.specialization = specialization
script.code = code or ""
end
end
function OvaleScripts:UnregisterScript(name)
self.script[name] = nil
end
function OvaleScripts:SetScript(name)
local oldSource = Ovale.db.profile.source
if oldSource ~= name then
Ovale.db.profile.source = name
self:SendMessage("Ovale_ScriptChanged")
end
end
function OvaleScripts:GetDefaultScriptName(class, specialization)
local name
-- only override when no default script is found in simulationcraft folder
-- default scripts in the form off "simulationcraft_<class>_<specialization>_t18m"
if class == "DEATHKNIGHT" then
if specialization == "blood" then
name = "icyveins_deathknight_blood"
elseif specialization == "frost" then
name = "simulationcraft_death_knight_frost_t18m"
elseif specialization == "unholy" then
name = "simulationcraft_death_knight_unholy_t18m"
end
elseif class == "DEMONHUNTER" then
if specialization then
name = format("icyveins_demonhunter_%s", specialization)
end
elseif class == "DRUID" then
if specialization == "restoration" then
name = DISABLED_NAME
end
elseif class == "HUNTER" then
local short
if specialization == "beast_mastery" then
short = "bm"
elseif specialization == "marksmanship" then
short = "mm"
elseif specialization == "survival" then
short = "sv"
end
if short then
name = format("simulationcraft_hunter_%s_t18m", short)
end
elseif class == "MONK" then
if specialization == "brewmaster" then
name = DISABLED_NAME
end
elseif class == "PALADIN" then
if specialization == "holy" then
name = DISABLED_NAME
elseif specialization == "protection" then
name = "icyveins_paladin_protection"
end
elseif class == "PRIEST" then
if specialization == "discipline" then
name = DISABLED_NAME
elseif specialization == "holy" then
name = DISABLED_NAME
end
elseif class == "SHAMAN" then
if specialization == "restoration" then
name = DISABLED_NAME
end
elseif class == "WARRIOR" then
if specialization == "fury" then
local weaponType = OvaleEquipment:HasMainHandWeapon(1) and "1h" or "2h"
name = format("simulationcraft_warrior_fury_%s_t18m", weaponType)
elseif specialization == "protection" then
name = DISABLED_NAME
end
end
if not name and specialization then
name = format("simulationcraft_%s_%s_t18m", strlower(class), specialization)
end
if not (name and self.script[name]) then
name = DISABLED_NAME
end
return name
end
function OvaleScripts:GetScriptName(name)
return (name == DEFAULT_NAME) and self:GetDefaultScriptName(Ovale.playerClass, OvalePaperDoll:GetSpecialization()) or name
end
function OvaleScripts:GetScript(name)
name = self:GetScriptName(name)
if name and self.script[name] then
return self.script[name].code
end
end
function OvaleScripts:CreateOptions()
local options = {
name = OVALE .. " " .. L["Script"],
type = "group",
args = {
source = {
order = 10,
type = "select",
name = L["Script"],
width = "double",
values = function(info)
local scriptType = not Ovale.db.profile.showHiddenScripts and "script"
return OvaleScripts:GetDescriptions(scriptType)
end,
get = function(info)
return Ovale.db.profile.source
end,
set = function(info, v)
self:SetScript(v)
end,
},
script = {
order = 20,
type = "input",
multiline = 25,
name = L["Script"],
width = "full",
disabled = function()
return Ovale.db.profile.source ~= CUSTOM_NAME
end,
get = function(info)
local code = OvaleScripts:GetScript(Ovale.db.profile.source)
code = code or ""
-- Substitute spaces for tabs.
return gsub(code, "\t", " ")
end,
set = function(info, v)
OvaleScripts:RegisterScript(Ovale.playerClass, nil, CUSTOM_NAME, CUSTOM_DESCRIPTION, v, "script")
Ovale.db.profile.code = v
self:SendMessage("Ovale_ScriptChanged")
end,
},
copy = {
order = 30,
type = "execute",
name = L["Copier sur Script personnalisé"],
disabled = function()
return Ovale.db.profile.source == CUSTOM_NAME
end,
confirm = function()
return L["Ecraser le Script personnalisé préexistant?"]
end,
func = function()
local code = OvaleScripts:GetScript(Ovale.db.profile.source)
OvaleScripts:RegisterScript(Ovale.playerClass, nil, CUSTOM_NAME, CUSTOM_DESCRIPTION, code, "script")
Ovale.db.profile.source = CUSTOM_NAME
Ovale.db.profile.code = OvaleScripts:GetScript(CUSTOM_NAME)
self:SendMessage("Ovale_ScriptChanged")
end,
},
showHiddenScripts = {
order = 40,
type = "toggle",
name = L["Show hidden"],
get = function(info) return Ovale.db.profile.showHiddenScripts end,
set = function(info, value) Ovale.db.profile.showHiddenScripts = value end
},
},
}
local appName = self:GetName()
AceConfig:RegisterOptionsTable(appName, options)
AceConfigDialog:AddToBlizOptions(appName, L["Script"], OVALE)
end
--</public-static-methods>