Repository navigation
Expand file tree
/
Copy pathCore.lua
More file actions
204 lines (169 loc) · 5.53 KB
/
Copy pathCore.lua
File metadata and controls
204 lines (169 loc) · 5.53 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
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
-------------------------------------
-- Slacker's Addon Depot: Core.lua --
-------------------------------------
local appName, app = ...
app.locales = {}
app.api = {}
SlackersAddonDepot = app.api
local api = app.api
local L = app.locales
---------------------------
-- WOW API EVENT HANDLER --
---------------------------
app.Event = CreateFrame("Frame")
app.Event.handlers = {}
function app.Event:Register(eventName, func)
if not self.handlers[eventName] then
self.handlers[eventName] = {}
self:RegisterEvent(eventName)
end
table.insert(self.handlers[eventName], func)
end
app.Event:SetScript("OnEvent", function(self, event, ...)
if self.handlers[event] then
for _, handler in ipairs(self.handlers[event]) do
handler(...)
end
end
end)
-------------
-- ON LOAD --
-------------
app.Event:Register("ADDON_LOADED", function(addOnName, containsBindings)
if addOnName == appName then
if WOW_PROJECT_ID == WOW_PROJECT_MAINLINE then
app.Retail = true
elseif WOW_PROJECT_ID == WOW_PROJECT_CAMELOT then
app.Forever = true
end
SlackersAddonDepot_Data = SlackersAddonDepot_Data or {}
SlackersAddonDepot_Settings = SlackersAddonDepot_Settings or {}
app.Data = SlackersAddonDepot_Data
app.Settings = SlackersAddonDepot_Settings
app.Version = C_AddOns.GetAddOnMetadata(appName, "Version")
app.Flag = {}
C_ChatInfo.RegisterAddonMessagePrefix(app.NamePrefix)
app:CreateSlashCommands()
end
end)
-------------------
-- VERSION COMMS --
-------------------
function app:SendAddonMessage(message)
local messageString = C_EncodingUtil.EncodeBase64(C_EncodingUtil.SerializeCBOR(message))
if IsInRaid(2) or IsInGroup(2) then
ChatThrottleLib:SendAddonMessage("NORMAL", app.NamePrefix, messageString, "INSTANCE_CHAT")
elseif IsInGroup() or IsInRaid() then
ChatThrottleLib:SendAddonMessage("NORMAL", app.NamePrefix, messageString, "RAID")
elseif IsInGuild() then
ChatThrottleLib:SendAddonMessage("NORMAL", app.NamePrefix, messageString, "GUILD")
end
end
app.Event:Register("GROUP_ROSTER_UPDATE", function(category, partyGUID)
app:SendAddonMessage({ version = app.Version })
end)
app.Event:Register("PLAYER_ENTERING_WORLD", function(isInitialLogin, isReloadingUi)
if isInitialLogin or isReloadingUi then
app:SendAddonMessage({ version = app.Version })
end
end)
app.Event:Register("CHAT_MSG_ADDON", function(prefix, text, channel, sender, target, zoneChannelID, localID, name, instanceID)
if prefix ~= app.NamePrefix or app.Flag.VersionCheck then return end
local ok, message = pcall(function()
return C_EncodingUtil.DeserializeCBOR(C_EncodingUtil.DecodeBase64(text))
end)
if not ok or type(message) ~= "table" or not message.version then return end
local otherVersion = tonumber(message.version:match("^v(%d+)$"))
local localVersion = tonumber(app.Version:match("^v(%d+)$"))
if otherVersion and localVersion and otherVersion > localVersion then
app:Print(string.format(L.NEW_VERSION_AVAILABLE, app.NameLong), message.version)
app.Flag.VersionCheck = true
end
end)
--------------------
-- SLASH COMMANDS --
--------------------
function app:CreateSlashCommands()
SLASH_RELOADUI1 = "/rl"
SlashCmdList.RELOADUI = ReloadUI
SLASH_SlackersAddonDepot1 = "/sad"
function SlashCmdList.SlackersAddonDepot(msg, editBox)
local command, rest = msg:match("^(%S*)%s*(.-)$")
if command == "settings" then
app:OpenSettings()
elseif command == "debug" then
if app.Settings.debug then
app.Settings.debug = false
app:Print(L.DEBUG_DISABLED)
else
app.Settings.debug = true
app:Print(L.DEBUG_ENABLED)
end
elseif command == "load" then
api:LoadProfile(rest, false)
elseif command == "forceload" then
api:LoadProfile(rest, true)
elseif command == "" then
api:ToggleAddonList()
else
app:Print(L.INVALID_COMMAND)
end
end
end
-----------------------
-- ADDON COMPARTMENT --
-----------------------
function SlackersAddonDepot_Click(self, button)
if button == "LeftButton" then
api:ToggleAddonList()
elseif button == "RightButton" then
app:OpenSettings()
end
end
function SlackersAddonDepot_Enter(self, button)
GameTooltip:ClearLines()
GameTooltip:SetOwner(type(self) ~= "string" and self or button, "ANCHOR_LEFT")
GameTooltip:AddLine(app.NameLong .. "\n|cffFFFFFF" .. app.IconLMB .. ": " .. L.TOGGLE_ADDON_LIST .. "\n" .. app.IconRMB .. ": " .. L.OPEN_SETTINGS)
GameTooltip:Show()
end
function SlackersAddonDepot_Leave()
GameTooltip:Hide()
end
----------------------
-- HELPER FUNCTIONS --
----------------------
function app:Colour(string)
return "|cff3FC7EB" .. string .. "|r"
end
function app:Debug(...)
if app.Settings.debug then
print(app.NameShort .. app:Colour(" Debug") .. ":", ...)
end
end
function app:Print(...)
print(app.NameShort .. ":", ...)
end
function app:SetBorder(parent, a, b, c, d)
local border = CreateFrame("Frame", nil, parent, "BackdropTemplate")
border:SetPoint("TOPLEFT", parent, a or 0, b or 0)
border:SetPoint("BOTTOMRIGHT", parent, c or 0, d or 0)
border:SetBackdrop({
bgFile = "Interface/Tooltips/UI-Tooltip-Background",
edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
edgeSize = 14,
insets = { left = 4, right = 4, top = 4, bottom = 4 },
})
border:SetBackdropColor(0, 0, 0, 0)
border:SetBackdropBorderColor(0.25, 0.78, 0.92)
end
function app:MakeButton(parent, text, name)
local frame = CreateFrame("Button", name, parent, "UIPanelButtonTemplate")
frame:SetText(text)
frame:SetWidth(frame:GetTextWidth()+20)
app:SetBorder(frame, 0, 0, 0, -1)
return frame
end
function app:UpdateButton(button, text)
button:SetText(text)
button:SetWidth(button:GetTextWidth()+20)
end