Skip to content

Commit

Permalink
refactor: update cooldown conditions to utilize TMW.COMMON.Cooldowns
Browse files Browse the repository at this point in the history
  • Loading branch information
ascott18 committed Sep 2, 2024
1 parent 67433bd commit c10dfc7
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 37 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* #2190: Added options to Buff/Debuff icons to source stack count from tooltip numbers.
* Fix: #2197 upstream issue in LibSpellRange-1.0 with range checking in classic/cata.
* Fix: #2201 Don't treat inactive hero talent trees as learned talents
* Fix: #2210 Fix desync of current GCD duration


## v11.0.4
Expand Down
38 changes: 21 additions & 17 deletions Components/Core/Conditions/Categories/Spells.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- --------------------
-- --------------------
-- TellMeWhen
-- Originally by NephMakes

Expand Down Expand Up @@ -34,7 +34,7 @@ local bit_band = bit.band

local COMBATLOG_OBJECT_TYPE_PLAYER = COMBATLOG_OBJECT_TYPE_PLAYER

local GetSpellCooldown = TMW.GetSpellCooldown
local GetSpellCooldown = TMW.COMMON.Cooldowns.GetSpellCooldown
Env.GetSpellCooldown = GetSpellCooldown
local GetSpellName = TMW.GetSpellName
local GetSpellInfo = TMW.GetSpellInfo
Expand All @@ -43,15 +43,17 @@ local GetItemCooldown = GetItemCooldown or (C_Item and C_Item.GetItemCooldown) o

function Env.CooldownDuration(spell, gcdAsUnusable)
if spell == "gcd" then
local start, duration = GetSpellCooldown(TMW.GCDSpell)
return duration == 0 and 0 or (duration - (TMW.time - start)), start, duration
local cooldown = GetSpellCooldown(TMW.GCDSpell)
local duration = cooldown.duration
return duration == 0 and 0 or (duration - (TMW.time - cooldown.startTime))
end

local start, duration = GetSpellCooldown(spell)
if duration then
return ((duration == 0 or (not gcdAsUnusable and OnGCD(duration))) and 0) or (duration - (TMW.time - start)), start, duration
local cooldown = GetSpellCooldown(spell)
if cooldown then
local duration = cooldown.duration
return ((duration == 0 or (not gcdAsUnusable and OnGCD(duration))) and 0) or (duration - (TMW.time - cooldown.startTime))
end
return 0, 0, 0
return 0
end

local GetSpellCharges = TMW.GetSpellCharges
Expand Down Expand Up @@ -105,8 +107,8 @@ ConditionCategory:RegisterCondition(1, "SPELLCD", {
end,
anticipate = function(c)
local str = [[
local start, duration = GetSpellCooldown(c.OwnSpells.First)
local VALUE = duration and start + (duration - c.Level) or huge
local cooldown = GetSpellCooldown(c.OwnSpells.First)
local VALUE = cooldown and cooldown.startTime + (cooldown.duration - c.Level) or huge
]]
if TMW:GetSpells(c.Name).First == "gcd" then
str = str:gsub("c.OwnSpells.First", TMW.GCDSpell)
Expand Down Expand Up @@ -140,16 +142,18 @@ ConditionCategory:RegisterCondition(2, "SPELLCDCOMP", {
end,
anticipate = function(c)
local str = [[
local start, duration = GetSpellCooldown(c.OwnSpells.First)
local start2, duration2 = GetSpellCooldown(c.OwnSpells2.First)
local cooldown = GetSpellCooldown(c.OwnSpells.First)
local cooldown2 = GetSpellCooldown(c.OwnSpells2.First)
local duration = cooldown and cooldown.duration
local duration2 = cooldown2 and cooldown2.duration
local VALUE
if duration and duration2 then
local v1, v2 = start + duration, start2 + duration2
local v1, v2 = cooldown.startTime + duration, cooldown2.startTime + duration2
VALUE = v1 < v2 and v1 or v2
elseif duration then
VALUE = start + duration
VALUE = cooldown.startTime + duration
elseif duration2 then
VALUE = start2 + duration2
VALUE = cooldown2.startTime + duration2
else
VALUE = huge
end
Expand Down Expand Up @@ -542,8 +546,8 @@ ConditionCategory:RegisterCondition(6, "GCD", {
ConditionObject:GenerateNormalEventString("TMW_SPELL_UPDATE_COOLDOWN")
end,
anticipate = [[
local start, duration = GetSpellCooldown(TMW.GCDSpell)
local VALUE = start + duration -- the time at which we need to update again. (when the GCD ends)
local cooldown = GetSpellCooldown(TMW.GCDSpell)
local VALUE = cooldown.startTime + cooldown.duration -- the time at which we need to update again. (when the GCD ends)
]],
})

Expand Down
2 changes: 1 addition & 1 deletion Components/Core/Conditions/ConditionCategory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ end
-- ConditionObject:GenerateNormalEventString("SPELL_UPDATE_USABLE")
-- end,
-- anticipate = [[
-- local _, start, duration = CooldownDuration(c.NameFirst)
-- local start, duration = GetSpellCooldown(c.NameFirst)
-- local VALUE = duration and start + (duration - c.Level) or huge
-- ]],
-- })
Expand Down
1 change: 1 addition & 0 deletions Options/CHANGELOG.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ TMW.CHANGELOG = [==[
* #2190: Added options to Buff/Debuff icons to source stack count from tooltip numbers.
* Fix: #2197 upstream issue in LibSpellRange-1.0 with range checking in classic/cata.
* Fix: #2201 Don't treat inactive hero talent trees as learned talents
* Fix: #2210 Fix desync of current GCD duration
## v11.0.4
Expand Down
20 changes: 1 addition & 19 deletions TellMeWhen.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- ---------------------------------
-- ---------------------------------
-- TellMeWhen
-- Originally by NephMakes

Expand Down Expand Up @@ -390,20 +390,6 @@ else
end
local GetSpellName = TMW.GetSpellName


if _G.GetSpellCooldown then
TMW.GetSpellCooldown = _G.GetSpellCooldown
else
local C_Spell_GetSpellCooldown = C_Spell.GetSpellCooldown
TMW.GetSpellCooldown = function(spellID)
local spellCooldownInfo = C_Spell_GetSpellCooldown(spellID);
if spellCooldownInfo then
return spellCooldownInfo.startTime, spellCooldownInfo.duration, spellCooldownInfo.isEnabled, spellCooldownInfo.modRate;
end
end
end
local GetSpellCooldown = TMW.GetSpellCooldown

---------------------------------
-- Caches
---------------------------------
Expand Down Expand Up @@ -2582,15 +2568,11 @@ function TMW:CpuProfileReset()
end

--- Update variables that are used globally thoughout TMW.
-- This includes TMW.time and TMW.GCD.
-- Call this manually when script execution starts in a context
-- that needs these variables but isn't originating from TMW:OnUpdate().
function TMW:UpdateGlobals()
time = GetTime()
TMW.time = time

_, GCD=GetSpellCooldown(GCDSpell)
TMW.GCD = GCD
end

do -- TMW:OnUpdate()
Expand Down

0 comments on commit c10dfc7

Please sign in to comment.