Skip to content

Commit 6782326

Browse files
committed
Add safety checks for retrieving cooldowns #103
1 parent 99df5f8 commit 6782326

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

gui/GM_Cooldown.lua

+11-9
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,20 @@ end
8080
]]--
8181
function me.UpdateGearSlotCooldown(gearBar, uiSlot, gearSlotMetaData)
8282
local itemId = GetInventoryItemID(RGGM_CONSTANTS.UNIT_ID_PLAYER, gearSlotMetaData.slotId)
83+
local showCooldowns = mod.gearBarManager.IsShowCooldownsEnabled(gearBar.id)
84+
local cooldownOverlay = uiSlot.cooldownOverlay
8385

84-
if itemId ~= nil then
85-
if mod.gearBarManager.IsShowCooldownsEnabled(gearBar.id) then
86-
local startTime, duration = C_Container.GetItemCooldown(itemId)
87-
CooldownFrame_Set(uiSlot.cooldownOverlay, startTime, duration, true)
86+
if not itemId or not showCooldowns then
87+
CooldownFrame_Clear(cooldownOverlay)
88+
return
89+
end
8890

89-
return
90-
else
91-
CooldownFrame_Clear(uiSlot.cooldownOverlay)
92-
end
91+
local startTime, duration = C_Container.GetItemCooldown(itemId)
92+
-- If GetItemCooldown returns 0, 0 (meaning no cooldown), we clear it out
93+
if startTime and duration and (startTime ~= 0 or duration ~= 0) then
94+
CooldownFrame_Set(cooldownOverlay, startTime, duration, true)
9395
else
94-
CooldownFrame_Clear(uiSlot.cooldownOverlay)
96+
CooldownFrame_Clear(cooldownOverlay)
9597
end
9698
end
9799

gui/GM_TrinketMenu.lua

+13-7
Original file line numberDiff line numberDiff line change
@@ -215,16 +215,22 @@ end
215215
Updates the cooldown representations of all items in the trinketMenu
216216
]]--
217217
function me.UpdateTrinketMenuSlotCooldowns()
218-
for _, trinketMenuSlot in pairs(trinketMenuSlots) do
219-
if trinketMenuSlot.itemId ~= nil then
220-
if mod.configuration.IsShowCooldownsEnabled() then
221-
local startTime, duration = C_Container.GetItemCooldown(trinketMenuSlot.itemId)
222-
CooldownFrame_Set(trinketMenuSlot.cooldownOverlay, startTime, duration, true)
218+
local showCooldowns = mod.configuration.IsShowCooldownsEnabled()
219+
220+
for _, slot in pairs(trinketMenuSlots) do
221+
local itemId = slot.itemId
222+
local cooldownOverlay = slot.cooldownOverlay
223+
224+
if itemId and showCooldowns then
225+
local startTime, duration = C_Container.GetItemCooldown(itemId)
226+
-- If GetItemCooldown returns 0, 0 (meaning no cooldown), we clear it out
227+
if startTime and duration and (startTime ~= 0 or duration ~= 0) then
228+
CooldownFrame_Set(cooldownOverlay, startTime, duration, true)
223229
else
224-
CooldownFrame_Clear(trinketMenuSlot.cooldownOverlay)
230+
CooldownFrame_Clear(cooldownOverlay)
225231
end
226232
else
227-
CooldownFrame_Clear(trinketMenuSlot.cooldownOverlay)
233+
CooldownFrame_Clear(cooldownOverlay)
228234
end
229235
end
230236
end

0 commit comments

Comments
 (0)