Implement throttling sounds and niceify the code a bit

This commit is contained in:
2025-01-09 16:21:59 +01:00
parent b5473e05e7
commit 6bb1cc683c
2 changed files with 65 additions and 16 deletions

View File

@@ -366,7 +366,7 @@ local function init()
alertSoundFile = shared.GetOrDefault(Heimdall_Data, { "config", "minimapTagger", "alertSoundFile" }, alertSoundFile = shared.GetOrDefault(Heimdall_Data, { "config", "minimapTagger", "alertSoundFile" },
"OOF.ogg"), "OOF.ogg"),
combatSoundFile = shared.GetOrDefault(Heimdall_Data, { "config", "minimapTagger", "combatSoundFile" }, combatSoundFile = shared.GetOrDefault(Heimdall_Data, { "config", "minimapTagger", "combatSoundFile" },
"StarScream.mp3"), "StarScream.ogg"),
helpSoundFile = shared.GetOrDefault(Heimdall_Data, { "config", "minimapTagger", "helpSoundFile" }, helpSoundFile = shared.GetOrDefault(Heimdall_Data, { "config", "minimapTagger", "helpSoundFile" },
"MedicGangsterParadise.ogg"), "MedicGangsterParadise.ogg"),
tagSoundThrottle = shared.GetOrDefault(Heimdall_Data, { "config", "minimapTagger", "tagSoundThrottle" }, 0), tagSoundThrottle = shared.GetOrDefault(Heimdall_Data, { "config", "minimapTagger", "tagSoundThrottle" }, 0),

View File

@@ -2,6 +2,9 @@ local addonname, shared = ...
---@cast shared HeimdallShared ---@cast shared HeimdallShared
---@cast addonname string ---@cast addonname string
local ModuleName = "MinimapTagger" local ModuleName = "MinimapTagger"
local HeimdallRoot = "Interface\\AddOns\\Heimdall\\"
local SoundRoot = HeimdallRoot .. "Sounds\\"
local TextureRoot = HeimdallRoot .. "Texture\\"
---@diagnostic disable-next-line: missing-fields ---@diagnostic disable-next-line: missing-fields
shared.MinimapTagger = {} shared.MinimapTagger = {}
@@ -49,11 +52,11 @@ function shared.MinimapTagger.Init()
self:SetScript("OnUpdate", function(self, elapsed) self:SetScript("OnUpdate", function(self, elapsed)
self.custom.progress = self.custom.progress + elapsed self.custom.progress = self.custom.progress + elapsed
local progress = self.custom.progress / ttl local progress = self.custom.progress / ttl
if Heimdall_Data.config.minimapTagger.debug then -- if Heimdall_Data.config.minimapTagger.debug then
print(string.format("[%s] Alert progress%%: %f", ModuleName, progress)) -- print(string.format("[%s] Alert progress%%: %f", ModuleName, progress))
print(string.format("[%s] Alert progress: %f", ModuleName, self.custom.progress)) -- print(string.format("[%s] Alert progress: %f", ModuleName, self.custom.progress))
print(string.format("[%s] Alert ttl: %d", ModuleName, Heimdall_Data.config.minimapTagger.ttl)) -- print(string.format("[%s] Alert ttl: %d", ModuleName, Heimdall_Data.config.minimapTagger.ttl))
end -- end
self:SetAlpha(1 - progress) self:SetAlpha(1 - progress)
if progress >= 1 then if progress >= 1 then
@@ -74,10 +77,10 @@ function shared.MinimapTagger.Init()
frame.custom = { busy = false } frame.custom = { busy = false }
local texture = frame:CreateTexture(nil, "ARTWORK") local texture = frame:CreateTexture(nil, "ARTWORK")
texture:SetAllPoints(frame) texture:SetAllPoints(frame)
texture:SetTexture("Interface\\AddOns\\WeakAuras\\PowerAurasMedia\\Auras\\Aura27") texture:SetTexture(TextureRoot .. "Alert.tga")
--texture:SetTexture("Interface\\AddOns\\Heimdall\\Texture\\Alert")
table.insert(alertFramePool, frame) table.insert(alertFramePool, frame)
end end
local muteAlertUntil = 0
---@param x number ---@param x number
---@param y number ---@param y number
---@param scale number? ---@param scale number?
@@ -96,7 +99,22 @@ function shared.MinimapTagger.Init()
return return
end end
if Heimdall_Data.config.minimapTagger.alertSound then if Heimdall_Data.config.minimapTagger.alertSound then
PlaySoundFile("Interface\\AddOns\\Heimdall\\Sound\\Alert.mp3") if Heimdall_Data.config.minimapTagger.debug then
print(string.format("[%s] Playing alert sound: %s", ModuleName,
Heimdall_Data.config.minimapTagger.alertSoundFile))
end
if muteAlertUntil > GetTime() then
if Heimdall_Data.config.minimapTagger.debug then
print(string.format("[%s] Alert sound is muted until %d", ModuleName, muteAlertUntil))
end
else
muteAlertUntil = GetTime() + Heimdall_Data.config.minimapTagger.alertSoundThrottle
local ok = PlaySoundFile(SoundRoot .. Heimdall_Data.config.minimapTagger.alertSoundFile, "Master")
if not ok and Heimdall_Data.config.minimapTagger.debug then
print(string.format("[%s] Failed to play alert sound: %s", ModuleName,
Heimdall_Data.config.minimapTagger.alertSoundFile))
end
end
end end
PlantFrame(x, y, frame, scale, Heimdall_Data.config.minimapTagger.alertTTL) PlantFrame(x, y, frame, scale, Heimdall_Data.config.minimapTagger.alertTTL)
end end
@@ -109,10 +127,10 @@ function shared.MinimapTagger.Init()
frame.custom = { busy = false } frame.custom = { busy = false }
local texture = frame:CreateTexture(nil, "ARTWORK") local texture = frame:CreateTexture(nil, "ARTWORK")
texture:SetAllPoints(frame) texture:SetAllPoints(frame)
texture:SetTexture("Interface\\AddOns\\WeakAuras\\PowerAurasMedia\\Auras\\Aura11") texture:SetTexture(TextureRoot .. "Tag.tga")
--texture:SetTexture("Interface\\AddOns\\Heimdall\\Texture\\Tag")
table.insert(tagFramePool, frame) table.insert(tagFramePool, frame)
end end
local muteTagUntil = 0
---@param x number ---@param x number
---@param y number ---@param y number
---@param scale number? ---@param scale number?
@@ -131,7 +149,22 @@ function shared.MinimapTagger.Init()
return return
end end
if Heimdall_Data.config.minimapTagger.tagSound then if Heimdall_Data.config.minimapTagger.tagSound then
PlaySoundFile("Interface\\AddOns\\Heimdall\\Sound\\Tag.mp3") if Heimdall_Data.config.minimapTagger.debug then
print(string.format("[%s] Playing tag sound: %s", ModuleName,
Heimdall_Data.config.minimapTagger.tagSoundFile))
end
if muteTagUntil > GetTime() then
if Heimdall_Data.config.minimapTagger.debug then
print(string.format("[%s] Tag sound is muted until %d", ModuleName, muteTagUntil))
end
else
muteTagUntil = GetTime() + Heimdall_Data.config.minimapTagger.tagSoundThrottle
local ok = PlaySoundFile(SoundRoot .. Heimdall_Data.config.minimapTagger.tagSoundFile, "Master")
if not ok and Heimdall_Data.config.minimapTagger.debug then
print(string.format("[%s] Failed to play tag sound: %s", ModuleName,
Heimdall_Data.config.minimapTagger.tagSoundFile))
end
end
end end
PlantFrame(x, y, frame, scale, Heimdall_Data.config.minimapTagger.tagTTL) PlantFrame(x, y, frame, scale, Heimdall_Data.config.minimapTagger.tagTTL)
end end
@@ -144,10 +177,10 @@ function shared.MinimapTagger.Init()
frame.custom = { busy = false } frame.custom = { busy = false }
local texture = frame:CreateTexture(nil, "ARTWORK") local texture = frame:CreateTexture(nil, "ARTWORK")
texture:SetAllPoints(frame) texture:SetAllPoints(frame)
texture:SetTexture("Interface\\AddOns\\WeakAuras\\PowerAurasMedia\\Auras\\Aura19") texture:SetTexture(TextureRoot .. "Fight.tga")
--texture:SetTexture("Interface\\AddOns\\Heimdall\\Texture\\Fight")
table.insert(battleFramePool, frame) table.insert(battleFramePool, frame)
end end
local muteBattleUntil = 0
---@param x number ---@param x number
---@param y number ---@param y number
---@param scale number? ---@param scale number?
@@ -166,7 +199,22 @@ function shared.MinimapTagger.Init()
return return
end end
if Heimdall_Data.config.minimapTagger.combatSound then if Heimdall_Data.config.minimapTagger.combatSound then
PlaySoundFile("Interface\\AddOns\\Heimdall\\Sound\\Fight.mp3") if Heimdall_Data.config.minimapTagger.debug then
print(string.format("[%s] Playing combat sound: %s", ModuleName,
Heimdall_Data.config.minimapTagger.combatSoundFile))
end
if muteBattleUntil > GetTime() then
if Heimdall_Data.config.minimapTagger.debug then
print(string.format("[%s] Combat sound is muted until %d", ModuleName, muteBattleUntil))
end
else
muteBattleUntil = GetTime() + Heimdall_Data.config.minimapTagger.combatSoundThrottle
local ok = PlaySoundFile(SoundRoot .. Heimdall_Data.config.minimapTagger.combatSoundFile, "Master")
if not ok and Heimdall_Data.config.minimapTagger.debug then
print(string.format("[%s] Failed to play combat sound: %s", ModuleName,
Heimdall_Data.config.minimapTagger.combatSoundFile))
end
end
end end
PlantFrame(x, y, frame, scale, Heimdall_Data.config.minimapTagger.combatTTL) PlantFrame(x, y, frame, scale, Heimdall_Data.config.minimapTagger.combatTTL)
end end
@@ -238,7 +286,8 @@ function shared.MinimapTagger.Init()
if channelname ~= Heimdall_Data.config.minimapTagger.masterChannel then if channelname ~= Heimdall_Data.config.minimapTagger.masterChannel then
if Heimdall_Data.config.minimapTagger.debug then if Heimdall_Data.config.minimapTagger.debug then
print(string.format("[%s] Ignoring message from non-master channel: %s, need %s", ModuleName, channelname, Heimdall_Data.config.minimapTagger.masterChannel)) print(string.format("[%s] Ignoring message from non-master channel: %s, need %s", ModuleName, channelname,
Heimdall_Data.config.minimapTagger.masterChannel))
end end
return return
end end