Skip to content

Commit

Permalink
Add safety checks for retrieving cooldowns #103
Browse files Browse the repository at this point in the history
  • Loading branch information
RagedUnicorn committed Jan 8, 2025
1 parent 99df5f8 commit 6782326
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
20 changes: 11 additions & 9 deletions gui/GM_Cooldown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,20 @@ end
]]--
function me.UpdateGearSlotCooldown(gearBar, uiSlot, gearSlotMetaData)
local itemId = GetInventoryItemID(RGGM_CONSTANTS.UNIT_ID_PLAYER, gearSlotMetaData.slotId)
local showCooldowns = mod.gearBarManager.IsShowCooldownsEnabled(gearBar.id)
local cooldownOverlay = uiSlot.cooldownOverlay

if itemId ~= nil then
if mod.gearBarManager.IsShowCooldownsEnabled(gearBar.id) then
local startTime, duration = C_Container.GetItemCooldown(itemId)
CooldownFrame_Set(uiSlot.cooldownOverlay, startTime, duration, true)
if not itemId or not showCooldowns then
CooldownFrame_Clear(cooldownOverlay)
return
end

return
else
CooldownFrame_Clear(uiSlot.cooldownOverlay)
end
local startTime, duration = C_Container.GetItemCooldown(itemId)
-- If GetItemCooldown returns 0, 0 (meaning no cooldown), we clear it out
if startTime and duration and (startTime ~= 0 or duration ~= 0) then
CooldownFrame_Set(cooldownOverlay, startTime, duration, true)
else
CooldownFrame_Clear(uiSlot.cooldownOverlay)
CooldownFrame_Clear(cooldownOverlay)
end
end

Expand Down
20 changes: 13 additions & 7 deletions gui/GM_TrinketMenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,22 @@ end
Updates the cooldown representations of all items in the trinketMenu
]]--
function me.UpdateTrinketMenuSlotCooldowns()
for _, trinketMenuSlot in pairs(trinketMenuSlots) do
if trinketMenuSlot.itemId ~= nil then
if mod.configuration.IsShowCooldownsEnabled() then
local startTime, duration = C_Container.GetItemCooldown(trinketMenuSlot.itemId)
CooldownFrame_Set(trinketMenuSlot.cooldownOverlay, startTime, duration, true)
local showCooldowns = mod.configuration.IsShowCooldownsEnabled()

for _, slot in pairs(trinketMenuSlots) do
local itemId = slot.itemId
local cooldownOverlay = slot.cooldownOverlay

if itemId and showCooldowns then
local startTime, duration = C_Container.GetItemCooldown(itemId)
-- If GetItemCooldown returns 0, 0 (meaning no cooldown), we clear it out
if startTime and duration and (startTime ~= 0 or duration ~= 0) then
CooldownFrame_Set(cooldownOverlay, startTime, duration, true)
else
CooldownFrame_Clear(trinketMenuSlot.cooldownOverlay)
CooldownFrame_Clear(cooldownOverlay)
end
else
CooldownFrame_Clear(trinketMenuSlot.cooldownOverlay)
CooldownFrame_Clear(cooldownOverlay)
end
end
end
Expand Down

0 comments on commit 6782326

Please sign in to comment.