-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.lua
More file actions
169 lines (157 loc) · 5.26 KB
/
Copy pathConfig.lua
File metadata and controls
169 lines (157 loc) · 5.26 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
--[[
Arena Helper Configuration
Author: Uberlicious2188
]]--
local addon, ns = ...
ArenaHelper = {}
HelperDB = {}
HelperCharDB = {}
local ArenaHelper=CreateFrame("Frame")
ArenaHelper:SetScript("OnEvent", function(self, event, ...) return self[event] and self[event](self, ...) end)
ArenaHelper:RegisterEvent("ADDON_LOADED")
ArenaHelper:RegisterEvent("PLAYER_LOGIN")
ArenaHelper:RegisterEvent("PLAYER_LOGOUT")
print("Welcome to |cff009cffArenaHelper|r use |CFFFE8A0E/arenahelper|r for Options.")
local defaults = {
NameplateNum = true,
MaxDebuffs = false,
SortTop = false,
SortBot = false,
}
local charDefaults = {
MacroHelper = false,
MacroChar = false,
}
-- On Addon Loaded build tempDB with Defaults and Saved Variables
function ArenaHelper:ADDON_LOADED()
local function initDB(def, tbl, saved)
if type(def) ~= "table" then return {} end
if type(tbl) ~= "table" then tbl = {} end
if type(saved) ~= "table" then return {} end
for k, v in pairs(def) do
if type(v) == "table" then
tbl[k] = initDB(v, tbl[k], saved[k])
elseif type(tbl[k]) ~= type(v) and saved[k] ~= nil then -- If saved value exists use it
tbl[k] = saved[k]
elseif type(tbl[k]) ~= type(v) and saved[k] == nil then -- If saved value does not exist use default
tbl[k] = v
end
end
return tbl
end
HelperDB = initDB(defaults, HelperDB, ArenaHelperDB)
local function initCharDB(def, tbl, saved)
if type(def) ~= "table" then return {} end
if type(tbl) ~= "table" then tbl = {} end
if type(saved) ~= "table" then return {} end
for k, v in pairs(def) do
if type(v) == "table" then
tbl[k] = initCharDB(v, tbl[k], saved[k])
elseif type(tbl[k]) ~= type(v) and saved[k] ~= nil then -- If saved value exists use it
tbl[k] = saved[k]
elseif type(tbl[k]) ~= type(v) and saved[k] == nil then -- If saved value does not exist use default
tbl[k] = v
end
end
return tbl
end
HelperCharDB = initCharDB(charDefaults, HelperCharDB, ArenaHelperCharDB)
self:UnregisterEvent("ADDON_LOADED")
end
-- On Logout Save variables that are not default
function ArenaHelper:PLAYER_LOGOUT()
local function updateSave(def, tbl, saved)
if type(def) ~= "table" then return {} end
if type(tbl) ~= "table" then tbl = {} end
if type(saved) ~= "table" then return {} end
for k,v in pairs(tbl) do
if type(v) == "table" then
saved[k] = updateSave(def[k], v, saved[k])
elseif type(saved[k]) ~= type(v) and v ~= def[k] then -- If temp value does not equal the default, save it
saved[k] = v
elseif type(saved[k]) ~= "table" and v == def[k] and saved[k] ~= def[k] then -- Unset saved value if temp == default and saved value exists
saved[k] = nil
elseif type(saved[k]) ~= "table" and saved[k] == def[k] then -- Cleanup if save value happens to == default
saved[k] = nil
end
end
if (saved) then
for k,v in pairs(saved) do
if type(v) == "table" then
saved[k] = updateSave(def[k], tbl[k], saved)
elseif type(saved[k]) ~= "table" and v ~= def[k] and v ~= tbl[k] then
saved[k] = nil
end
end
end
return saved
end
ArenaHelperDB = updateSave(defaults, HelperDB, ArenaHelperDB)
local function updateCharSave(def, tbl, saved)
if type(def) ~= "table" then return {} end
if type(tbl) ~= "table" then tbl = {} end
if type(saved) ~= "table" then return {} end
for k,v in pairs(tbl) do
if type(v) == "table" then
saved[k] = updateCharSave(def[k], v, saved[k])
elseif type(saved[k]) ~= type(v) and v ~= def[k] then -- If temp value does not equal the default, save it
saved[k] = v
elseif type(saved[k]) ~= "table" and v == def[k] and saved[k] ~= def[k] then -- Unset saved value if temp == default and saved value exists
saved[k] = nil
elseif type(saved[k]) ~= "table" and saved[k] == def[k] then -- Cleanup if save value happens to == default
saved[k] = nil
end
end
if (saved) then
for k,v in pairs(saved) do
if type(v) == "table" then
saved[k] = updateCharSave(def[k], tbl[k], saved)
elseif type(saved[k]) ~= "table" and v ~= def[k] and v ~= tbl[k] then
saved[k] = nil
end
end
end
return saved
end
ArenaHelperCharDB = updateCharSave(charDefaults, HelperCharDB, ArenaHelperCharDB)
end
-- Reset the Temp DB to Defaults
function HelperDB_reset()
local function dbreset(def, tbl)
if type(def) ~= "table" then return {} end
if type(tbl) ~= "table" then tbl = {} end
for k,v in pairs(def) do
if type(v) == "table" then
tbl[k] = dbreset(v, tbl[k])
elseif type(tbl[k]) ~= "table" then
tbl[k] = v
end
end
return tbl
end
HelperDB = dbreset(Defaults, LocalDB)
end
--[[
SLASH COMMANDS
]]--
SlashCmdList.ARENAHELPER = function(msg, editbox)
msg = msg:lower()
if msg == "options" then
Opt_ShowOptions()
elseif msg == "mark" then
PartyMark_markGroup()
elseif msg == "toggle" then
PartyMark_toggleEventListeners()
elseif msg == "pvp" then
PvPMacro_UpdateMacros()
elseif msg == "help" or msg ~= "true" then
print("|cff009cffArenaHelper|r Help")
print("Commands:")
print("|CFFFE8A0E/options|r: Opens options window.")
print("|CFFFE8A0E/ah mark|r: Mark group members.")
print("|CFFFE8A0E/ah toggle|r: Toggle automatic marking mode.")
print("|CFFFE8A0E/ah pvp: Force update Macros (will also set icon).")
end
end
SLASH_ARENAHELPER1 = "/arenahelper"
SLASH_ARENAHELPER2 = "/ah"