@@ -16,19 +16,67 @@ local GCD_SPELL_ID = 61304
1616-- how much of a buffer we give finish effets (in seconds)
1717local FINISH_EFFECT_BUFFER = - 0.15
1818
19+ -- is it after Midnight?
20+ local SECRETS_ENABLED = type (canaccessvalue ) == " function"
21+
1922---- ---------------------------------------------------------------------------
2023-- Utility Methods
2124---- ---------------------------------------------------------------------------
2225
2326local IsGCD , GetGCDTimeRemaining
2427
2528-- gcd tests
26- if type (C_Spell ) == " table" and type (C_Spell .GetSpellCooldown ) == " function" then
29+ if SECRETS_ENABLED then
30+ --- @param start number
31+ --- @param duration number
32+ --- @param modRate number
33+ --- @return boolean
34+ IsGCD = function (start , duration , modRate )
35+ if not (start > 0 and duration > 0 and modRate > 0 ) then
36+ return false
37+ end
38+
39+ local gcd = C_Spell .GetSpellCooldown (GCD_SPELL_ID )
40+
41+ if canaccessvalue (gcd ) then
42+ return gcd
43+ and gcd .isEnabled
44+ and start == gcd .startTime
45+ and duration == gcd .duration
46+ and modRate == gcd .modRate
47+ end
48+
49+ return false
50+ end
51+
52+ --- @return number
53+ GetGCDTimeRemaining = function ()
54+ local gcd = C_Spell .GetSpellCooldown (GCD_SPELL_ID )
55+
56+ if canaccessvalue (gcd ) then
57+ if not (gcd and gcd .isEnabled ) then
58+ return 0
59+ end
60+
61+ local start , duration , modRate = gcd .startTime , gcd .duration , gcd .modRate
62+ if not (start > 0 and duration > 0 and modRate > 0 ) then
63+ return 0
64+ end
65+
66+ local remain = (start + duration ) - GetTime ()
67+ if remain > 0 then
68+ return remain / modRate
69+ end
70+ end
71+
72+ return 0
73+ end
74+ elseif type (C_Spell ) == " table" and type (C_Spell .GetSpellCooldown ) == " function" then
2775 --- @param start number
2876 --- @param duration number
2977 --- @param modRate number
3078 --- @return boolean
31- IsGCD = function (start , duration , modRate )
79+ IsGCD = function (start , duration , modRate )
3280 if not (start > 0 and duration > 0 and modRate > 0 ) then
3381 return false
3482 end
@@ -42,6 +90,7 @@ if type(C_Spell) == "table" and type(C_Spell.GetSpellCooldown) == "function" the
4290 and modRate == gcd .modRate
4391 end
4492
93+ --- @return number
4594 GetGCDTimeRemaining = function ()
4695 local gcd = C_Spell .GetSpellCooldown (GCD_SPELL_ID )
4796 if not (gcd and gcd .isEnabled ) then
65114 --- @param duration number
66115 --- @param modRate number
67116 --- @return boolean
68- IsGCD = function (start , duration , modRate )
117+ IsGCD = function (start , duration , modRate )
69118 if not (start > 0 and duration > 0 and modRate > 0 ) then
70119 return false
71120 end
78127 and modRate == gcdModRate
79128 end
80129
130+ --- @return number
81131 GetGCDTimeRemaining = function ()
82132 local start , duration , enabled , modRate = GetSpellCooldown (GCD_SPELL_ID )
83133 if (not enabled and start > 0 and duration > 0 and modRate > 0 ) then
@@ -139,8 +189,15 @@ function Cooldown:CanShowText()
139189 return false
140190 end
141191
142- if self .GetHideCountdownNumbers and not self :GetHideCountdownNumbers () then
143- return false
192+ if SECRETS_ENABLED then
193+ local hide = self :GetHideCountdownNumbers ()
194+ if canaccessvalue (hide ) and not hide then
195+ return false
196+ end
197+ else
198+ if self .GetHideCountdownNumbers and not self :GetHideCountdownNumbers () then
199+ return false
200+ end
144201 end
145202
146203 local elapsed = GetTime () - start
@@ -367,15 +424,18 @@ end
367424
368425--- @param self OmniCCCooldown
369426function Cooldown :Refresh (force )
427+ local start , duration = self :GetCooldownTimes ()
428+ if SECRETS_ENABLED and not canaccessvalue (start ) then
429+ return
430+ end
431+
370432 if force then
371433 self ._occ_start = nil
372434 self ._occ_duration = nil
373435 self ._occ_modRate = nil
374436 end
375437
376438 Cooldown .Initialize (self )
377-
378- local start , duration = self :GetCooldownTimes ()
379439 if start == 0 or duration == 0 then
380440 Cooldown .SetTimer (self , 0 , 0 , 1 )
381441 else
@@ -464,7 +524,11 @@ function Cooldown:OnSetCooldown(start, duration, modRate)
464524 end
465525
466526 Cooldown .Initialize (self )
467- Cooldown .SetTimer (self , start , duration , modRate )
527+ if SECRETS_ENABLED and not canaccessvalue (start ) then
528+ Cooldown .CallWithProxy (self , ' SetCooldown' , start , duration , modRate )
529+ else
530+ Cooldown .SetTimer (self , start or 0 , duration or 0 , modRate or 1 )
531+ end
468532end
469533
470534--- @param self OmniCCCooldown
@@ -476,7 +540,11 @@ function Cooldown:OnSetCooldownDuration(duration, modRate)
476540 end
477541
478542 Cooldown .Initialize (self )
479- Cooldown .SetTimer (self , self :GetCooldownTimes () / 1000 , duration , modRate )
543+ if SECRETS_ENABLED and not canaccessvalue (duration ) then
544+ Cooldown .CallWithProxy (self , ' SetCooldownDuration' , duration , modRate )
545+ else
546+ Cooldown .SetTimer (self , self :GetCooldownTimes () / 1000 , duration , modRate )
547+ end
480548end
481549
482550--- @param self OmniCCCooldown
@@ -541,8 +609,12 @@ function Cooldown:GetTheme()
541609end
542610
543611function Cooldown :OnSetHideCountdownNumbers (hide )
612+ if SECRETS_ENABLED and not canaccessvalue (hide ) then
613+ return
614+ end
615+
544616 local disable = not (hide or self .noCooldownCount or self :IsForbidden ())
545- and Addon .db .global .disableBlizzardCooldownText
617+ and Addon .db .global .disableBlizzardCooldownText
546618
547619 if disable then
548620 self :SetHideCountdownNumbers (true )
@@ -572,5 +644,99 @@ function Cooldown:ForAll(method, ...)
572644 end
573645end
574646
647+ -- This is a hack for Midnight. Cooldowns are secret in combat, but
648+ -- cooldown text is not. So, parse the text to figure out the current
649+ -- duration of a cooldown, to around the nearest second. I also think
650+ -- that its possible to abuse the SetMinimumCountdownDuration method
651+ -- to get a more accurate reading of the cooldown.
652+ if SECRETS_ENABLED then
653+ -- get the text duration, in seconds
654+ local function parseDuration (text )
655+ if text and text ~= " " then
656+ local days , hours , minutes , seconds
657+
658+ seconds = tonumber (text )
659+ if seconds then
660+ return seconds
661+ end
662+
663+ minutes , seconds = text :match (" ^(%d+):(%d+)$" )
664+ if minutes and seconds then
665+ return tonumber (minutes ) * 60 + tonumber (seconds )
666+ end
667+
668+ minutes = text :match (" ^(%d+)m$" )
669+ if minutes then
670+ return tonumber (minutes ) * 60
671+ end
672+
673+ hours = text :match (" ^(%d+)h$" )
674+ if hours then
675+ return tonumber (hours ) * 3600
676+ end
677+
678+ days = text :match (" ^(%d+)d$" )
679+ if days then
680+ return tonumber (days ) * 86400
681+ end
682+ end
683+
684+ return - 1
685+ end
686+
687+ local durations = setmetatable ({}, {
688+ __index = function (self , text )
689+ local value = parseDuration (text )
690+ self [text ] = value
691+ return value
692+ end
693+ })
694+
695+ local function findFirstFontString (...)
696+ for i = 1 , select (" #" , ... ) do
697+ local region = select (i , ... )
698+ if region :GetObjectType () == " FontString" then
699+ return region
700+ end
701+ end
702+ end
703+
704+ function Cooldown :CallWithProxy (method , ...)
705+ local proxy = self ._occ_proxy
706+ if not proxy then
707+ proxy = CreateFrame (' Cooldown' )
708+ proxy .owner = self
709+ proxy .noCooldownCount = true
710+ proxy :SetMinimumCountdownDuration (0 )
711+
712+ proxy .callback = function ()
713+ proxy .scheduled = nil
714+
715+ local fontString = proxy .fontString
716+ if not fontString then
717+ fontString = findFirstFontString (proxy :GetRegions ())
718+ proxy .fontString = fontString
719+ end
720+
721+ if fontString then
722+ local duration = durations [fontString :GetText () or " " ]
723+ if duration > 0 then
724+ Cooldown .SetTimer (proxy .owner , GetTime (), duration , 1 )
725+ end
726+ end
727+ end
728+
729+ self ._occ_proxy = proxy
730+ end
731+
732+ proxy [method ](proxy , ... )
733+
734+ if not proxy .scheduled then
735+ proxy .scheduled = true
736+ C_Timer .After (GetTickTime (), proxy .callback )
737+ end
738+ end
739+ end
740+
575741-- exports
576742Addon .Cooldown = Cooldown
0 commit comments