-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Main.lua
165 lines (148 loc) · 6.96 KB
/
Main.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
local appName, JDT = ...
local AceConfig = LibStub("AceConfig-3.0")
local AceConfigDialog = LibStub("AceConfigDialog-3.0")
local AceDBOptions = LibStub("AceDBOptions-3.0")
JDT.SharedMediaLib = LibStub("LibSharedMedia-3.0")
---@class MyAddon : AceAddon-3.0, AceConsole-3.0, AceConfig-3.0, AceGUI-3.0, AceConfigDialog-3.0
local DungeonAuraTools = LibStub("AceAddon-3.0"):NewAddon("DungeonAuraTools", "AceConsole-3.0", "AceEvent-3.0")
JDT.AddonVersion = C_AddOns.GetAddOnMetadata(appName, "Version")
JDT.InternalWaVersion = 75 -- version of weakauras addon on creation might need to be updated eventually
JDT.Sharedmedia = JDT.Sharedmedia or {}
JDT.Sharedmedia.font = JDT.Sharedmedia.font or {}
JDT.Sharedmedia.sound= JDT.Sharedmedia.sound or {}
local function SharedMediaSetup(mediatype)
local mediaList = JDT.SharedMediaLib:List(mediatype)
for _,v in pairs(mediaList) do
JDT.Sharedmedia[mediatype][v] = v
end
end
function DungeonAuraTools:OnInitialize()
SharedMediaSetup(JDT.SharedMediaLib.MediaType.FONT)
SharedMediaSetup(JDT.SharedMediaLib.MediaType.SOUND)
-- Called when the addon is loaded
self:Print(JDT.getLocalisation("AccessOptionsMessage"))
self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:RegisterEvent("CHAT_MSG_ADDON")
self:RegisterEvent("ZONE_CHANGED_NEW_AREA")
JDT.self = self
JDT.db = LibStub("AceDB-3.0"):New("DungeonAuraTools",JDT.OptionDefaults, true) -- Generates Saved Variables with default Values (if they don't already exist)
local OptionTable = {
type = "group",
args = {
profile = AceDBOptions:GetOptionsTable(JDT.db),
rest = JDT.options
}}
AceConfig:RegisterOptionsTable(appName,OptionTable) --
AceConfigDialog:AddToBlizOptions(appName, appName)
self:RegisterChatCommand("jdt", "SlashCommand")
self:RegisterChatCommand("Jdt", "SlashCommand")
self:RegisterChatCommand("DAT", "SlashCommand")
self:RegisterChatCommand("Dat", "SlashCommand")
self:RegisterChatCommand("dat", "SlashCommand")
self:RegisterChatCommand("DungeonAuraTools", "SlashCommand")
-- generates Data for Options Table
JDT.db.profile.ToggleAnchor = false -- sets the anchor to hidden on startup
end
function DungeonAuraTools:OnEnable()
-- Called when the addon is enabled
end
function DungeonAuraTools:OnDisable()
-- Called when the addon is disabled
end
function JDT_AddonCompartmentFunction()
DungeonAuraTools:SlashCommand("AddonCompartmentFrame")
end
local VersionCheckPrefix = "DAT_VERSION"
local function sendVersion ()
if IsInRaid() then
C_ChatInfo.SendAddonMessage(VersionCheckPrefix, JDT.AddonVersion, (not IsInRaid(LE_PARTY_CATEGORY_HOME) and IsInRaid(LE_PARTY_CATEGORY_INSTANCE)) and "INSTANCE_CHAT" or "RAID")
elseif IsInGroup() then
C_ChatInfo.SendAddonMessage(VersionCheckPrefix, JDT.AddonVersion, (not IsInGroup(LE_PARTY_CATEGORY_HOME) and IsInGroup(LE_PARTY_CATEGORY_INSTANCE)) and "INSTANCE_CHAT" or "PARTY")
elseif IsInGuild() then
C_ChatInfo.SendAddonMessage(VersionCheckPrefix, JDT.AddonVersion, "GUILD")
end
end
function SharedMediaCallback(name,mediatype,key)
if mediatype == JDT.SharedMediaLib.MediaType.FONT or mediatype == JDT.SharedMediaLib.MediaType.SOUND then
SharedMediaSetup(mediatype)
end
end
function DungeonAuraTools:SlashCommand(msg) -- called when slash command is used
if msg == "export" then
JDT.exportAuras()
elseif msg == "version" then
print(JDT.AddonVersion)
elseif msg == "InternalVersion" then
print(JDT.InternalWaVersion)
else
JDT.createOptionsData()
JDT.CreateOptionsFrame()
end
end
function DungeonAuraTools:PLAYER_ENTERING_WORLD(event, isLogin, isReload)
JDT.SharedMediaLib:RegisterCallback("LibSharedMedia_Registered", function(...)
SharedMediaCallback(...)
end)
if isLogin == true or isReload == true then
if isLogin == true and not IsInInstance() then
JDT.CheckIfAuraUpdates(self)
end
C_ChatInfo.RegisterAddonMessagePrefix(VersionCheckPrefix)
local name,realm = UnitFullName("player")
JDT.PlayerName = name.."-"..realm
sendVersion()
end
end
function DungeonAuraTools:CHAT_MSG_ADDON(event, prefix, version , channel, sender, target, zoneChannelID, localID, name, instanceID)
if prefix == VersionCheckPrefix and sender ~= JDT.PlayerName then
if version and version > JDT.AddonVersion then
self:Print(JDT.getLocalisation("VersionCheckMessage"))
self:Print(JDT.getLocalisation("VersionDetectedMessage").." "..version)
self:Print(JDT.getLocalisation("OwnVersionMessage").." "..JDT.AddonVersion)
end
end
end
local mapidToZone = {}
for expansion in pairs(JDT.SpellList) do
if expansion ~= "Affixes" then
for dungeon in pairs(JDT.SpellList[expansion].Dungeons) do
mapidToZone[JDT.SpellList[expansion].Dungeons[dungeon].zoneId] = {
expansion = expansion,
dungeon = dungeon,
}
end
end
end
---Creates auras for a provided Dungeon
---@param ExpansionKey string
---@param DungeonKey string
---@return table
local CreateAurasForDungeon = function(ExpansionKey,DungeonKey)
local ExportTable = JDT.CreateGroupToExport(DungeonKey,JDT.db.profile.data[ExpansionKey])
for BossNameKey, BossNameValue in pairs(JDT.db.profile.data[ExpansionKey].Dungeons[DungeonKey].Bosses) do
for TypeKey,TypeValue in pairs(BossNameValue.Auras) do -- iterate through all selected spells and generate table accordingly
for k,v in pairs(TypeValue) do
if v.enabled == true then
JDT.buildAura(ExportTable,JDT.db.profile.data[ExpansionKey].Dungeons[DungeonKey],BossNameValue,TypeKey,v,JDT.db.profile.data[ExpansionKey],ExpansionKey)
end
end
end
end
table.sort(ExportTable.c, JDT.sortExportAuraChildren)
return ExportTable
end
function DungeonAuraTools:ZONE_CHANGED_NEW_AREA(event)
if JDT.db.profile.ExportOnDungeonEntry then
local mapid = C_Map.GetBestMapForUnit("player")
if mapid then
local mapGroupId = C_Map.GetMapGroupID(mapid)
if mapGroupId and mapidToZone["g"..mapGroupId] and not WeakAuras.GetData("DungeonAuras_"..mapidToZone["g"..mapGroupId].dungeon) then
WeakAuras.Import(CreateAurasForDungeon(mapidToZone["g"..mapGroupId].expansion,mapidToZone["g"..mapGroupId].dungeon))
-- ViragDevTool_AddData(JDT.SpellList[mapidToZone["g"..mapGroupId].expansion].Dungeons[mapidToZone["g"..mapGroupId].dungeon])
elseif mapidToZone[mapid] and not WeakAuras.GetData("DungeonAuras_"..mapidToZone[mapid].dungeon) then
WeakAuras.Import(CreateAurasForDungeon(mapidToZone[mapid].expansion,mapidToZone[mapid].dungeon))
-- ViragDevTool_AddData(JDT.SpellList[mapidToZone[mapid].expansion].Dungeons[mapidToZone[mapid].dungeon])
end
end
end
end