-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelfCastSetter.lua
More file actions
161 lines (117 loc) · 5.15 KB
/
SelfCastSetter.lua
File metadata and controls
161 lines (117 loc) · 5.15 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
--------------------------------------------------------------------------------
-- global local vars
--------------------------------------------------------------------------------
local addonName, addonVars = ...
--------------------------------------------------------------------------------
-- event handler frame
--------------------------------------------------------------------------------
SelfCastSetter = CreateFrame("Frame")
--------------------------------------------------------------------------------
-- slash commands
--------------------------------------------------------------------------------
function SelfCastSetter:ExecuteCommand(pCommand)
local startIndex, endIndex, command, parameter = string.find(pCommand, "(%w+) ?(.*)")
if not command then
self:help(self, parameter)
return
end
command = command:lower()
if self[command] then
self[command](self, parameter)
end
end
function SelfCastSetter:help()
addonVars:NoteMessage(HIGHLIGHT_FONT_COLOR_CODE.."/scs help"..NORMAL_FONT_COLOR_CODE..": Shows this list")
addonVars:NoteMessage(HIGHLIGHT_FONT_COLOR_CODE.."/scs enable"..NORMAL_FONT_COLOR_CODE..": Enables self casting on the current spec")
addonVars:NoteMessage(HIGHLIGHT_FONT_COLOR_CODE.."/scs disable"..NORMAL_FONT_COLOR_CODE..": Disables self casting on the current spec")
addonVars:NoteMessage(HIGHLIGHT_FONT_COLOR_CODE.."/scs show"..NORMAL_FONT_COLOR_CODE..": Shows the saved setting for the current spec")
end
function SelfCastSetter:enable(parameter)
self:setSelfCasting(true)
end
function SelfCastSetter:disable(parameter)
self:setSelfCasting(false)
end
function SelfCastSetter:show(parameter)
self:showSelfCasting()
end
--------------------------------------------------------------------------------
-- local vars
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- local functions
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- class methods
--------------------------------------------------------------------------------
-- generate defaults for db
function SelfCastSetter:generateDefaults()
self.defaults = {
}
end
function SelfCastSetter:setSelfCasting(enable)
local specID, specName, _, _, _ = GetSpecializationInfo(GetSpecialization())
self.db[specID] = enable
self:handleSpecChange(specID, specName)
end
function SelfCastSetter:showSelfCasting()
local specID, specName, _, _, _ = GetSpecializationInfo(GetSpecialization())
selfCast = self.db[specID]
if selfCast ~= nil then
addonVars:NoteMessage(NORMAL_FONT_COLOR_CODE..": Self casting on "..specName.." set to "..tostring(selfCast))
else
addonVars:NoteMessage(NORMAL_FONT_COLOR_CODE..": No saved setting for "..specName)
end
end
--------------------------------------------------------------------------------
-- event handler methods
--------------------------------------------------------------------------------
function SelfCastSetter:handleSpecChange(specID, specName)
local enable = self.db[specID]
if enable ~= nil then
local selfCast
if enable then
selfCast = 1
else
selfCast = 0
end
SetCVar("autoSelfCast", selfCast)
addonVars:NoteMessage(NORMAL_FONT_COLOR_CODE..": Self casting set to "..tostring(enable).."!")
else
addonVars:NoteMessage(NORMAL_FONT_COLOR_CODE..": No self casting settings for "..specName.."!")
end
end
--------------------------------------------------------------------------------
-- event handler event methods
--------------------------------------------------------------------------------
function SelfCastSetter:OnEvent(event, ...)
self[event](self, event, ...)
end
function SelfCastSetter:ADDON_LOADED(event, addOnName)
if addOnName == addonName then
print(addOnName, "loaded. Type /scs for help.")
-- initialize saved variables
SelfCastSetterDB = SelfCastSetterDB or {}
self.db = SelfCastSetterDB
self:generateDefaults()
for key, value in pairs(self.defaults) do
if self.db[key] == nil then
self.db[key] = value
end
end
-- slash commands
SlashCmdList.SELFCASTSETTER = function (...) SelfCastSetter:ExecuteCommand(...) end
SLASH_SELFCASTSETTER1, SLASH_SELFCASTSETTER2 = "/scs", "/selfcastsetter"
self:UnregisterEvent(event)
end
end
function SelfCastSetter:ACTIVE_PLAYER_SPECIALIZATION_CHANGED(event, ...)
local specID, specName, _, _, _ = GetSpecializationInfo(GetSpecialization())
self:handleSpecChange(specID, specName)
end
--------------------------------------------------------------------------------
-- register events and listen
--------------------------------------------------------------------------------
SelfCastSetter:RegisterEvent("ADDON_LOADED")
SelfCastSetter:RegisterEvent("ACTIVE_PLAYER_SPECIALIZATION_CHANGED")
SelfCastSetter:SetScript("OnEvent", SelfCastSetter.OnEvent)