Skip to content

Commit

Permalink
Core: auto disable countdowns based on combat status when arg is present
Browse files Browse the repository at this point in the history
  • Loading branch information
Zidras committed Dec 27, 2023
1 parent ecdfb56 commit 0695624
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions DBM-Core/DBM-Core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ local function currentFullDate()
end

DBM = {
Revision = parseCurseDate("20231226233100"),
Revision = parseCurseDate("20231227192103"),
DisplayVersion = "10.1.10 alpha", -- the string that is shown as version
ReleaseRevision = releaseDate(2023, 12, 26) -- the date of the latest stable version that is available, optionally pass hours, minutes, and seconds for multiple releases in one day
}
Expand Down Expand Up @@ -9816,15 +9816,16 @@ do
end
end

local function playCountSound(timerId, path)
local function playCountSound(timerId, path, requiresCombat)
DBM:Debug("playCountSound originated from timer: "..(timerId or "nil").." with path: "..(path or "nil"), 3) -- doubling this here to confirm sound provenance on debug logs
if requiresCombat and not (InCombatLockdown() or UnitAffectingCombat("player")) then return end
DBM:PlaySoundFile(path)
end

local function playCountdown(timerId, timer, voice, count)
local function playCountdown(timerId, timer, voice, count, requiresCombat)
if DBM.Options.DontPlayCountdowns then return end
timer = timer or 10
count = count or 5
count = count or 4
voice = voice or 1
if timer <= count then count = floor(timer) end
if not countpath1 or not countpath2 or not countpath3 then
Expand Down Expand Up @@ -9855,13 +9856,13 @@ do
if count == 0 then--If a count of 0 is passed,then it's a "Countout" timer, not "Countdown"
for i = 1, timer do
if i < maxCount then
DBM:Schedule(i, playCountSound, timerId, path..i..".ogg")
DBM:Schedule(i, playCountSound, timerId, path..i..".ogg", requiresCombat)
end
end
else
for i = count, 1, -1 do
if i <= maxCount then
DBM:Schedule(timer-i, playCountSound, timerId, path..i..".ogg")
DBM:Schedule(timer-i, playCountSound, timerId, path..i..".ogg", requiresCombat)
end
end
end
Expand Down Expand Up @@ -9985,7 +9986,7 @@ do
countVoice = self.mod.Options[self.option .. "CVoice"]
if not self.fade and (type(countVoice) == "string" or countVoice > 0) then--Started without faded and has count voice assigned
DBM:Unschedule(playCountSound, id) -- Prevents count sound if timer is started again before timer expires
playCountdown(id, timer, countVoice, countVoiceMax)--timerId, timer, voice, count
playCountdown(id, timer, countVoice, countVoiceMax, self.requiresCombat)--timerId, timer, voice, count
end
end
local bar = DBT:CreateBar(timer, id, self.icon, nil, nil, nil, nil, colorId, nil, self.keep, self.fade, countVoice, countVoiceMax)
Expand Down Expand Up @@ -10079,7 +10080,7 @@ do
local countVoice = self.mod.Options[self.option .. "CVoice"] or 0
if (type(countVoice) == "string" or countVoice > 0) then--Unfading bar, start countdown
DBM:Unschedule(playCountSound, id)
playCountdown(id, bar.timer, countVoice, bar.countdownMax)--timerId, timer, voice, count
playCountdown(id, bar.timer, countVoice, bar.countdownMax, bar.requiresCombat)--timerId, timer, voice, count
DBM:Debug("Re-enabling a countdown on bar ID: "..id.." after a SetFade disable call")
end
end
Expand Down Expand Up @@ -10251,7 +10252,7 @@ do
DBM:Unschedule(playCountSound, id)
if not bar.fade then--Don't start countdown voice if it's faded bar
if newRemaining > 2 then
playCountdown(id, newRemaining, countVoice, bar.countdownMax)--timerId, timer, voice, count
playCountdown(id, newRemaining, countVoice, bar.countdownMax, bar.requiresCombat)--timerId, timer, voice, count
DBM:Debug("Updating a countdown after a timer Update call for timer ID:"..id)
end
end
Expand Down Expand Up @@ -10282,7 +10283,7 @@ do
if (type(countVoice) == "string" or countVoice > 0) then
DBM:Unschedule(playCountSound, id)
if not bar.fade then--Don't start countdown voice if it's faded bar
playCountdown(id, newRemaining, countVoice, bar.countdownMax)--timerId, timer, voice, count
playCountdown(id, newRemaining, countVoice, bar.countdownMax, bar.requiresCombat)--timerId, timer, voice, count
DBM:Debug("Updating a countdown after a timer AddTime call for timer ID:"..id)
end
end
Expand Down Expand Up @@ -10319,7 +10320,7 @@ do
if (type(countVoice) == "string" or countVoice > 0) then
if not bar.fade then--Don't start countdown voice if it's faded bar
if newRemaining > 2 then
playCountdown(id, newRemaining, countVoice, bar.countdownMax)--timerId, timer, voice, count
playCountdown(id, newRemaining, countVoice, bar.countdownMax, bar.requiresCombat)--timerId, timer, voice, count
DBM:Debug("Updating a countdown after a timer RemoveTime call for timer ID:"..id)
end
end
Expand Down Expand Up @@ -10363,7 +10364,7 @@ do
if self.option and not bar.fade then
local countVoice = self.mod.Options[self.option .. "CVoice"] or 0
if (type(countVoice) == "string" or countVoice > 0) then
playCountdown(id, remaining, countVoice, bar.countdownMax)--timerId, timer, voice, count
playCountdown(id, remaining, countVoice, bar.countdownMax, bar.requiresCombat)--timerId, timer, voice, count
DBM:Debug("Updating a countdown after a timer Resume call for timer ID:"..id)
end
end
Expand Down Expand Up @@ -10422,7 +10423,7 @@ do
end

--If a new countdown default is added to a NewTimer object, change optionName of timer to reset a new default
function bossModPrototype:NewTimer(timer, name, texture, optionDefault, optionName, colorType, inlineIcon, keep, countdown, countdownMax, r, g, b, spellId)
function bossModPrototype:NewTimer(timer, name, texture, optionDefault, optionName, colorType, inlineIcon, keep, countdown, countdownMax, r, g, b, spellId, requiresCombat)
if r and type(r) == "string" then
DBM:Debug("|cffff0000r probably has inline icon in it and needs to be fixed for |r"..name..r)
r = nil--Fix it for users
Expand All @@ -10446,6 +10447,7 @@ do
r = r,
g = g,
b = b,
requiresCombat = requiresCombat,
startedTimers = {},
mod = self,
},
Expand All @@ -10459,7 +10461,7 @@ do
-- new constructor for the new auto-localized timer types
-- note that the function might look unclear because it needs to handle different timer types, especially achievement timers need special treatment
-- If a new countdown is added to an existing timer that didn't have one before, use optionName (number) to force timer to reset defaults by assigning it a new variable
local function newTimer(self, timerType, timer, spellId, timerText, optionDefault, optionName, colorType, texture, inlineIcon, keep, countdown, countdownMax, r, g, b)
local function newTimer(self, timerType, timer, spellId, timerText, optionDefault, optionName, colorType, texture, inlineIcon, keep, countdown, countdownMax, r, g, b, requiresCombat)
if type(timer) == "string" and timer:match("OptionVersion") then
DBM:Debug("|cffff0000OptionVersion hack depricated, remove it from: |r"..spellId)
return
Expand Down Expand Up @@ -10532,6 +10534,7 @@ do
r = r,
g = g,
b = b,
requiresCombat = requiresCombat,
allowdouble = allowdouble,
startedTimers = {},
mod = self,
Expand Down

0 comments on commit 0695624

Please sign in to comment.