forked from Slothpala/RaidFrameSettings
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGroupProfileLoader.lua
More file actions
executable file
·53 lines (47 loc) · 1.82 KB
/
GroupProfileLoader.lua
File metadata and controls
executable file
·53 lines (47 loc) · 1.82 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
--[[Created by Slothpala]]--
local _, addonTable = ...
local addon = addonTable.addon
local class_id = select(3, UnitClass("player"))
-- The data for spec_id and spec_name is sometimes not available at login, so we request it on PLAYER_ENTERING_WORLD.
local spec_id
local spec_name
local group_type = ""
local group_profiles = {
["party"] = "party_profile",
["raid"] = "raid_profile",
["arena"] = "arena_profile",
["battleground"] = "battleground_profile",
}
local function check_group_profile()
local new_group_type = addon:GetGroupType()
if new_group_type == group_type then
return
end
local new_profile = addon.db.global[spec_name][group_profiles[new_group_type]]
local current_profile = addon.db:GetCurrentProfile()
if current_profile == new_profile then
return
end
addon.db:SetProfile(new_profile)
group_type = new_group_type
end
local event_frame = CreateFrame("Frame")
event_frame:RegisterEvent("GROUP_ROSTER_UPDATE")
event_frame:RegisterEvent("PLAYER_ENTERING_WORLD")
event_frame:RegisterUnitEvent("PLAYER_SPECIALIZATION_CHANGED", "player")
event_frame:SetScript("OnEvent", function(_, event, arg1, arg2)
if event == "PLAYER_ENTERING_WORLD" and ( arg1 or arg2 ) then -- arg1 = initial login, arg2 = reloading. Both can be false when zoning out of instance for example.
spec_id = GetSpecialization()
spec_name = select(2, GetSpecializationInfoForClassID(class_id, spec_id))
elseif event == "PLAYER_SPECIALIZATION_CHANGED" then
spec_id = GetSpecialization()
spec_name = select(2, GetSpecializationInfoForClassID(class_id, spec_id))
group_type = "" -- This is done to bypass the check.
end
check_group_profile()
end)
function addon:LoadGroupProfile()
group_type = addon:GetGroupType()
local profile = self.db.global[spec_name][group_profiles[group_type]]
self.db:SetProfile(profile)
end