-
Notifications
You must be signed in to change notification settings - Fork 2
/
Init.lua
237 lines (201 loc) · 8.96 KB
/
Init.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
--############################################
-- Namespace
--############################################
local SwitchSwitch = unpack(select(2, ...))
--##########################################################################################################################
-- Default configurations
--##########################################################################################################################
local dbDefaults =
{
global =
{
["Version"] = -1,
["TalentProfiles"] = {},
["TalentSuggestions"] = {}
},
profile =
{
["Version"] = -1,
["debug"] = false,
["talentsSuggestionFrame"] =
{
["location"] =
{
["point"] = "CENTER",
["relativePoint"] = "CENTER",
["frameX"] = 0,
["frameY"] = 0
},
["enabled"] = true,
["fadeTime"] = 15
},
["minimap"] =
{
["hide"] = false,
}
},
char =
{
["Version"] = -1,
["gearSets"] = {},
}
}
--##########################################################################################################################
-- Initialization
--##########################################################################################################################
function SwitchSwitch:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("SwitchSwitchDB", dbDefaults)
-- Register events we will liten to
self:RegisterEvent("ADDON_LOADED")
self:RegisterEvent("PLAYER_SPECIALIZATION_CHANGED")
self:RegisterEvent("TRAIT_CONFIG_UPDATED")
self:RegisterEvent("CHALLENGE_MODE_MAPS_UPDATE")
-- Set up Settings for profiles settings
local aceOptionTable = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
LibStub("AceConfig-3.0"):RegisterOptionsTable("SwitchSwitch", aceOptionTable)
self.db.RegisterCallback(self, "OnProfileChanged", "RefreshConfig")
self.db.RegisterCallback(self, "OnProfileCopied", "RefreshConfig")
self.db.RegisterCallback(self, "OnProfileReset", "RefreshConfig")
self:DebugPrint("Addon Initializing")
--Update the tables in case they are not updated
SwitchSwitch:Update()
self:DebugPrint("Addon Initialized")
end
function SwitchSwitch:RegisterMyticPlusDungeonsDetection()
local detectionModule = self:GetModule("BossDetection")
local seasonID = self:GetCurrentMythicPlusSeason()
if(SwitchSwitch.MythicPlusDungeons[seasonID] == nil) then
self:Print(("No entry for seasonID %d"):format(seasonID))
self:PrintTable(SwitchSwitch.MythicPlusDungeons)
return
end
for _journalID, instanceID in pairs(SwitchSwitch.MythicPlusDungeons[seasonID]) do
detectionModule:RegisterInstance(instanceID, {})
if(self:GetMythicPlusProfileSuggestion(instanceID) ~= nil) then
detectionModule:SetDetectionForInstanceEnabled(instanceID, self.PreMythicPlusDificulty, true)
elseif(self:GetMythicPlusProfileSuggestion(instanceID, -1) ~= nil) then
detectionModule:SetDetectionForInstanceEnabled(instanceID, self.PreMythicPlusDificulty, true)
end
end
end
function SwitchSwitch:OnEnable()
self:DebugPrint("Addon Enabling")
-- Request Mythic+ data from server
C_MythicPlus.RequestMapInfo()
--Load Commands
SwitchSwitch.Commands:Init()
--Init the minimap
SwitchSwitch:InitMinimapIcon()
--Load the UI if not currently loaded
if(not C_AddOns.IsAddOnLoaded("Blizzard_ClassTalentUI")) then
C_AddOns.LoadAddOn("Blizzard_ClassTalentUI")
end
-- Enable Boss detection and register instances
self:RegisterMessage("SWITCHSWITCH_BOSS_DETECTED")
self:RegisterMessage("SWITCHSWITCH_INSTANCE_TYPE_DETECTED")
self:EnableModule("BossDetection")
local detectionModule = self:GetModule("BossDetection")
self:DebugPrint("Starting to register instances")
for expansion, data in pairs(SwitchSwitch.InstancesBossData) do
for contentType, contentData in pairs(data) do
for jurnalID, InstanceData in pairs(contentData) do
-- Register the data with the module
detectionModule:RegisterInstance(InstanceData["instanceID"], InstanceData["bossData"] or {})
-- Check aswell for suggestion to automaticly start detecting them avoids us going over them later
local suggestions = self:GetProfilesSuggestionInstanceData(InstanceData["instanceID"])
for id, _ in pairs(suggestions["difficulties"] or {}) do
detectionModule:SetDetectionForInstanceEnabled(InstanceData["instanceID"], id, true)
end
for id,_ in pairs(suggestions["bosses"] or {}) do
detectionModule:SetDetectionForBossEnabled(id, InstanceData["instanceID"], true)
end
end
end
end
self:RegisterMyticPlusDungeonsDetection()
-- Enable boss detection for pvp and arenas
local data = SwitchSwitch:GetProfilesSuggestionInstanceData("pvp")
SwitchSwitch:GetModule("BossDetection"):SetDetectingInstanceTypeEnabled("pvp", data["all"] ~= nil)
data = SwitchSwitch:GetProfilesSuggestionInstanceData("arena")
SwitchSwitch:GetModule("BossDetection"):SetDetectingInstanceTypeEnabled("arena", data["all"] ~= nil)
data = SwitchSwitch:GetProfilesSuggestionInstanceData("scenario") or {}
SwitchSwitch:GetModule("BossDetection"):SetDetectingInstanceTypeEnabled("scenario", data[208] ~= nil, 208)
-- Lets refresh all the UIS
SwitchSwitch:RefreshCurrentConfigID()
end
function SwitchSwitch:OnDisable()
self:DebugPrint("Addon disabling")
end
--##########################################################################################################################
-- Config Update to never version
--##########################################################################################################################
-- IF version has 2 . it concatenates the last dots so 3.1.1 = 3.11 and 3.0.1 = 3.01 ect
-- 3.0.0 -> 3.0030 (this is release)
-- 3.0.0b -> 3.0020
-- 3.0.0b1 -> 3.0021
-- 3.0.0a -> 3.0010
-- 3.0.0a1 -> 3.0011
local function GetVersionNumber(str)
if(str == nil) then
return 0.0
end
if(type(str) == "string") then
if(str:match('^v%d+%.%d+%.%d+a?b?%d*$') == nil) then
SwitchSwitch:Print("Invalid version string: " .. str)
return -1
end
-- Remove beta and alpha form string and add respective number to the str
local extraNumber = 0.003
local typeMatch, subVer = string.match(str, "([ab])(%d*)")
if(subVer == nil or #subVer == 0) then
subVer = 0
end
if(typeMatch == "b") then
-- The maximum of betas we can have is 9
extraNumber = 0.002 + tonumber('0.000' .. subVer)
str = string.gsub(str, "b(%d*)", "")
elseif(typeMatch == "a") then
extraNumber = 0.001 + tonumber('0.000' .. subVer)
str = string.gsub(str, "a(%d*)", "")
end
-- remove V
str = string.gsub(str, "^v", "")
-- Conver .0.0 to .00
if(SwitchSwitch:Repeats(str, "%.") == 2) then
local index = SwitchSwitch:findLastInString(str, "%.")
str = string.sub( str, 1, index-1) .. string.sub( str, index+1)
end
str = tonumber(str) + extraNumber
end
return str
end
--[===[@non-debug@
SwitchSwitch.InternalVersion = GetVersionNumber("@project-version@")
--@end-non-debug@]===]
--@debug@
SwitchSwitch.InternalVersion = GetVersionNumber("v3.0.0b3")
--@end-debug@
function SwitchSwitch:Update()
--Get old version string
local globalConfigVersion = GetVersionNumber(self.db.global.Version)
local profileConfigVerison = GetVersionNumber(self.db.profile.Version)
local characterConfigVerison = GetVersionNumber(self.db.profile.Version)
--Update Global table
if(globalConfigVersion ~= -1 and globalConfigVersion ~= self.InternalVersion) then
-- Update the tables after 3.0 (dragonflight) as talents changed
if(globalConfigVersion < 3.00) then
self.db.global.TalentProfiles = {}
self.db.global.TalentSuggestions = {}
end
end
-- Update profile table
if(profileConfigVerison ~= -1 and profileConfigVerison ~= self.InternalVersion) then
end
-- Update character table
if(characterConfigVerison ~= -1 and characterConfigVerison ~= self.InternalVersion) then
end
-- Lastly we update the verison of the config
self.db.global.Version = self.InternalVersion
self.db.profile.Version = self.InternalVersion
self.db.char.Version = self.InternalVersion
end