-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
122 lines (107 loc) · 3.59 KB
/
main.lua
File metadata and controls
122 lines (107 loc) · 3.59 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
-- ======================
-- Achiever - Main File
-- ======================
Achiever = Achiever or {}
local f = CreateFrame("Frame")
local timerFrame = CreateFrame("Frame")
local elapsed = 0
local playDelay = 1 -- seconds
local achievementQueue = {}
local isPlaying = false
-- ================================
-- Achievement Toast + Sound Logic
-- ================================
local function playAchieverSound()
local rareID
for _, achID in ipairs(achievementQueue) do
if Achiever.RareAchievements[achID] then
rareID = achID
break
end
end
if rareID then
Achiever.playsound(Achiever.raresounds)
ShowAchievementToast(rareID, true)
else
local lastID = achievementQueue[#achievementQueue]
Achiever.playsound(Achiever.normalsounds)
ShowAchievementToast(lastID)
end
-- Reset state
achievementQueue = {}
isPlaying = false
elapsed = 0
timerFrame:Hide()
end
timerFrame:SetScript("OnUpdate", function(_, delta)
elapsed = elapsed + delta
if elapsed >= playDelay then
playAchieverSound()
end
end)
timerFrame:Hide()
-- ===========================
-- Achievement Event Handling
-- ===========================
f:RegisterEvent("ACHIEVEMENT_EARNED")
f:RegisterEvent("PLAYER_LOGIN")
f:SetScript("OnEvent", function(_, event, id)
if event == "ACHIEVEMENT_EARNED" then
table.insert(achievementQueue, id)
if not isPlaying then
isPlaying = true
elapsed = 0
timerFrame:Show()
end
elseif event == "PLAYER_LOGIN" then
DEFAULT_CHAT_FRAME:AddMessage("|cff00ff00Achiever Loaded!|r")
if AchieverSettings.lastNotifiedVersion and AchieverSettings.lastNotifiedVersion ~= Achiever.version then
DEFAULT_CHAT_FRAME:AddMessage("Newer Version: " .. AchieverSettings.lastNotifiedVersion .. " available!")
DEFAULT_CHAT_FRAME:AddMessage(
"|cff00ff00"
.. "Download it via https://github.com/Zaphirez/Achiever/releases/latest to stay up to date!"
)
end
if
AchieverSettings.lastNotifiedVersion
and not IsNewerVersion(Achiever.version, AchieverSettings.lastNotifiedVersion)
then
AchieverSettings.lastNotifiedVersion = nil
end
end
end)
-- =================
-- Slash Commands
-- =================
SLASH_ACHIEVER1 = "/achiever"
SlashCmdList["ACHIEVER"] = function(msg)
local cmd, arg = msg:match("^(%S*)%s*(.-)$")
cmd = cmd:lower()
if cmd == "test" and tonumber(arg) then
local id = tonumber(arg)
f:GetScript("OnEvent")(f, "ACHIEVEMENT_EARNED", id, Achiever.playerName)
elseif cmd == "toast" and Achiever.ToggleToast then
Achiever.ToggleToast()
elseif cmd == "status" and Achiever.IsToastEnabled then
print("Toast is currently " .. (Achiever.IsToastEnabled() and "enabled." or "disabled."))
elseif cmd == "version" then
print("|cffaaff00Achiever|r v" .. Achiever.version .. " broadcasting version...")
Achiever:Broadcast("VERSION:" .. Achiever.version)
elseif cmd == "check" then
Achiever:SendVersionCheck()
elseif cmd == "sound" then
Achiever.ToggleSound()
elseif cmd == "settings" then
InterfaceOptionsFrame_OpenToCategory("Achiever")
InterfaceOptionsFrame_OpenToCategory("Achiever")
else
print("|cffffd700Achiever Addon Commands:")
print("|cffffff00/achiever settings|r - Open the Settings Tab.")
print("|cffffff00/achiever test <id>|r - Test achievement popup and sound.")
print("|cffffff00/achiever toast|r - Toggle achievement toast display on/off.")
print("|cffffff00/achiever sound|r - Toggle achievement sound on/off.")
print("|cffffff00/achiever status|r - Check whether toast is enabled.")
print("|cffffff00/achiever check|r - Asks players for their current version.")
print("|cffffff00/achiever version|r - Broadcast your addon version.")
end
end