Skip to content

Commit

Permalink
Cleanups, optimizations, and reorganization. More work with UNIT_AURA
Browse files Browse the repository at this point in the history
Miscellaneous cleanups, optimizations, and code reorganizations. Most of this is for clarity, but there are minor improvements throughout with regard to performance. Also, adding a few minor revisions to the previous C_UnitAuras API port from the prior commit.
  • Loading branch information
brittyazel committed Nov 7, 2023
1 parent e11581a commit 609983f
Show file tree
Hide file tree
Showing 26 changed files with 250 additions and 247 deletions.
240 changes: 41 additions & 199 deletions AuraIndicators.lua

Large diffs are not rendered by default.

180 changes: 180 additions & 0 deletions CollectUnitAuras.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
-- Enhanced Raid Frames is a World of Warcraft® user interface addon.
-- Copyright (c) 2017-2023 Britt W. Yazel
-- This code is licensed under the MIT license (see LICENSE for details)

local _, addonTable = ... --make use of the default addon namespace
local EnhancedRaidFrames = addonTable.EnhancedRaidFrames

-------------------------------------------------------------------------
-------------------------------------------------------------------------

EnhancedRaidFrames.unitAuras = {} -- Matrix to keep a list of all auras on all units
local unitAuras = EnhancedRaidFrames.unitAuras --local handle for the above table

------------------------------------------------
---------- Update Auras for all units ----------
------------------------------------------------

--- This functions is bound to the UNIT_AURA event and is used to track auras on all raid frame units
--- It uses the C_UnitAuras API that was added in 10.0
--- Unit aura information is stored in the unitAuras table
function EnhancedRaidFrames:UpdateUnitAuras(_, unit, payload)
-- Only process player, raid, and party units
if not string.find(unit, "player") and not string.find(unit, "raid") and not string.find(unit, "party") then
return
end

-- Create the main table for the unit
if not unitAuras[unit] then
unitAuras[unit] = {}
end

-- If we get a full update signal, wipe the table and rescan all auras for the unit
if payload.isFullUpdate then
-- Clear out the table
table.wipe(unitAuras[unit])
-- These helper functions will iterate over all buffs and debuffs on the unit
-- and call the addToAuraTable() function for each one
AuraUtil.ForEachAura(unit, "HELPFUL", nil, function(auraData)
EnhancedRaidFrames.addToAuraTable(unit, auraData)
end, true);
AuraUtil.ForEachAura(unit, "HARMFUL", nil, function(auraData)
EnhancedRaidFrames.addToAuraTable(unit, auraData)
end, true);
return
end

-- If new auras are added, update the table with their payload information
if payload.addedAuras then
for _, auraData in pairs(payload.addedAuras) do
EnhancedRaidFrames.addToAuraTable(unit, auraData)
end
end

-- If an aura has been updated, query the updated information and add it to the table
if payload.updatedAuraInstanceIDs then
for _, auraInstanceID in pairs(payload.updatedAuraInstanceIDs) do
if unitAuras[unit][auraInstanceID] then
local auraData = C_UnitAuras.GetAuraDataByAuraInstanceID(unit, auraInstanceID)
EnhancedRaidFrames.addToAuraTable(unit, auraData)
end
end
end

-- If an aura has been removed, remove it from the table
if payload.removedAuraInstanceIDs then
for _, auraInstanceID in pairs(payload.removedAuraInstanceIDs) do
if unitAuras[unit][auraInstanceID] then
unitAuras[unit][auraInstanceID] = nil
end
end
end
end

--- Prior to WoW 10.0, this function was used to track auras on all raid frame units
--- Unit auras are now tracked using the UNIT_AURA event and APIs in Retail
--- Unit aura information is stored in the unitAuras table
function EnhancedRaidFrames:UpdateUnitAuras_Legacy(unit)
-- Create or clear out the tables for the unit
unitAuras[unit] = {}

-- Get all unit buffs
local i = 1
while (true) do
local auraName, icon, count, duration, expirationTime, castBy, spellID

if UnitAura then
auraName, icon, count, _, duration, expirationTime, castBy, _, _, spellID = UnitAura(unit, i, "HELPFUL")
else
auraName, icon, count, _, duration, expirationTime, castBy, _, _, spellID = self.UnitAuraWrapper(unit, i, "HELPFUL") --for wow classic. This is the LibClassicDurations wrapper
end

if not spellID then --break the loop once we have no more buffs
break
end

--it's important to use the 4th argument in string.find to turn of pattern matching, otherwise things with parentheses in them will fail to be found
if auraName and self.allAuras:find(" "..auraName:lower().." ", nil, true) or self.allAuras:find(" "..spellID.." ", nil, true) then -- Only add the spell if we're watching for it
local auraTable = {}
auraTable.auraType = "buff"
auraTable.auraIndex = i
auraTable.auraName = auraName:lower()
auraTable.icon = icon
auraTable.count = count
auraTable.duration = duration
auraTable.expirationTime = expirationTime
auraTable.castBy = castBy
auraTable.spellID = spellID

table.insert(unitAuras[unit], auraTable)
end
i = i + 1
end

-- Get all unit debuffs
i = 1
while (true) do
local auraName, icon, count, duration, expirationTime, castBy, spellID, debuffType

if UnitAura then
auraName, icon, count, debuffType, duration, expirationTime, castBy, _, _, spellID = UnitAura(unit, i, "HARMFUL")
else
auraName, icon, count, debuffType, duration, expirationTime, castBy, _, _, spellID = self.UnitAuraWrapper(unit, i, "HARMFUL") --for wow classic. This is the LibClassicDurations wrapper
end

if not spellID then --break the loop once we have no more buffs
break
end

--it's important to use the 4th argument in string.find to turn off pattern matching, otherwise things with parentheses in them will fail to be found
if auraName and self.allAuras:find(" "..auraName:lower().." ", nil, true) or self.allAuras:find(" "..spellID.." ", nil, true) or (debuffType and self.allAuras:find(" "..debuffType:lower().." ", nil, true)) then -- Only add the spell if we're watching for it
local auraTable = {}
auraTable.auraType = "debuff"
auraTable.auraIndex = i
auraTable.auraName = auraName:lower()
auraTable.icon = icon
auraTable.count = count
if debuffType then
auraTable.debuffType = debuffType:lower()
end
auraTable.duration = duration
auraTable.expirationTime = expirationTime
auraTable.castBy = castBy
auraTable.spellID = spellID

table.insert(unitAuras[unit], auraTable)
end
i = i + 1
end
end

--function to add or update an aura to the unitAuras table
function EnhancedRaidFrames.addToAuraTable(thisUnit, thisAuraData)
if not thisAuraData then
return
end

local aura = {}
aura.auraInstanceID = thisAuraData.auraInstanceID
if thisAuraData.isHelpful then
aura.auraType = "buff"
elseif thisAuraData.isHarmful then
aura.auraType = "debuff"
end
aura.auraName = thisAuraData.name:lower()
aura.icon = thisAuraData.icon
aura.count = thisAuraData.applications
aura.duration = thisAuraData.duration
aura.expirationTime = thisAuraData.expirationTime
aura.castBy = thisAuraData.sourceUnit
aura.spellID = thisAuraData.spellId

-- Update the aura elements if it already exists
if unitAuras[thisUnit][aura.auraInstanceID] then
for k,v in pairs(aura) do
unitAuras[thisUnit][aura.auraInstanceID][k] = v
end
else
unitAuras[thisUnit][aura.auraInstanceID] = aura
end
end
3 changes: 1 addition & 2 deletions DatabaseDefaults.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Enhanced Raid Frames is a World of Warcraft® user interface addon.
-- Copyright (c) 2017-2021 Britt W. Yazel
-- Copyright (c) 2017-2023 Britt W. Yazel
-- This code is licensed under the MIT license (see LICENSE for details)

local _, addonTable = ... --make use of the default addon namespace
Expand Down Expand Up @@ -83,7 +83,6 @@ function EnhancedRaidFrames:CreateDefaults()
showCountdownSwipe = true,
indicatorGlow = false,
glowRemainingSecs = 3,

}
end

Expand Down
12 changes: 3 additions & 9 deletions EnhancedRaidFrames.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Enhanced Raid Frames is a World of Warcraft® user interface addon.
-- Copyright (c) 2017-2021 Britt W. Yazel
-- Copyright (c) 2017-2023 Britt W. Yazel
-- This code is licensed under the MIT license (see LICENSE for details)

local addonName, addonTable = ... --make use of the default addon namespace
Expand All @@ -22,7 +22,6 @@ end

EnhancedRaidFrames.DATABASE_VERSION = 2


--Declare Color Globals
EnhancedRaidFrames.NORMAL_COLOR = NORMAL_FONT_COLOR or CreateColor(1.0, 0.82, 0.0) --the default game text color, dull yellow color
EnhancedRaidFrames.WHITE_COLOR = WHITE_FONT_COLOR or CreateColor(1.0, 1.0, 1.0) --default game white color for text
Expand Down Expand Up @@ -66,6 +65,7 @@ function EnhancedRaidFrames:OnEnable()
-- Hook raid icon updates
self:RegisterBucketEvent({"RAID_TARGET_UPDATE", "RAID_ROSTER_UPDATE"}, 1, "UpdateAllFrames")

-- Use new UNIT_AURA event in retail that was added in 10.0 for huge performance gains
if not self.isWoWClassicEra and not self.isWoWClassic then
self:RegisterEvent("UNIT_AURA", "UpdateUnitAuras")
end
Expand All @@ -77,12 +77,7 @@ function EnhancedRaidFrames:OnEnable()
self:UpdateNotifier()

self:RegisterChatCommand("erf",function()
if Settings then --10.0 introduced a new Settings API
Settings.OpenToCategory("Enhanced Raid Frames")
else
InterfaceOptionsFrame_OpenToCategory("Enhanced Raid Frames")
InterfaceOptionsFrame_OpenToCategory("Enhanced Raid Frames")
end
Settings.OpenToCategory("Enhanced Raid Frames")
end)
end

Expand Down Expand Up @@ -148,7 +143,6 @@ end
---@param setAppearance boolean
function EnhancedRaidFrames:UpdateAllFrames(setAppearance)
--don't do any work if the raid frames aren't shown
--10.0 introduced the CompactPartyFrame, we can't assume it exists in Classic
if not CompactRaidFrameContainer:IsShown() and CompactPartyFrame and not CompactPartyFrame:IsShown() then
return
end
Expand Down
1 change: 1 addition & 0 deletions EnhancedRaidFrames.toc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Localizations\Localizations.xml
EnhancedRaidFrames.lua
DatabaseDefaults.lua
UtilitiesAndOverrides.lua
CollectUnitAuras.lua

AuraIndicators.lua
RaidIcons.lua
Expand Down
2 changes: 1 addition & 1 deletion GUI/GeneralConfigPanel.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Enhanced Raid Frames is a World of Warcraft® user interface addon.
-- Copyright (c) 2017-2021 Britt W. Yazel
-- Copyright (c) 2017-2023 Britt W. Yazel
-- This code is licensed under the MIT license (see LICENSE for details)

local _, addonTable = ...
Expand Down
2 changes: 1 addition & 1 deletion GUI/IconConfigPanel.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Enhanced Raid Frames is a World of Warcraft® user interface addon.
-- Copyright (c) 2017-2021 Britt W. Yazel
-- Copyright (c) 2017-2023 Britt W. Yazel
-- This code is licensed under the MIT license (see LICENSE for details)

local _, addonTable = ...
Expand Down
3 changes: 1 addition & 2 deletions GUI/IndicatorConfigPanel.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Enhanced Raid Frames is a World of Warcraft® user interface addon.
-- Copyright (c) 2017-2021 Britt W. Yazel
-- Copyright (c) 2017-2023 Britt W. Yazel
-- This code is licensed under the MIT license (see LICENSE for details)

local _, addonTable = ...
Expand All @@ -11,7 +11,6 @@ local POSITIONS = { [1] = L["Top left"], [2] = L["Top Center"], [3] = L["Top Rig
[4] = L["Middle Left"], [5] = L["Middle Center"], [6] = L["Middle Right"],
[7] = L["Bottom Left"], [8] = L["Bottom Center"], [9] = L["Bottom Right"]}


-------------------------------------------------------------------------
-------------------------------------------------------------------------

Expand Down
3 changes: 1 addition & 2 deletions GUI/ProfileImportExport.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
-- Enhanced Raid Frames is a World of Warcraft® user interface addon.
-- Copyright (c) 2017-2021 Britt W. Yazel
-- Copyright (c) 2017-2023 Britt W. Yazel
-- This code is licensed under the MIT license (see LICENSE for details)

local _, addonTable = ...
local EnhancedRaidFrames = addonTable.EnhancedRaidFrames

local L = LibStub("AceLocale-3.0"):GetLocale("EnhancedRaidFrames")


-------------------------------------------------------------------------
-------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License

Copyright (c) 2017-2021 Britt W. Yazel
Copyright (c) 2017-2023 Britt W. Yazel

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
3 changes: 1 addition & 2 deletions Libs/embeds.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<!-- Enhanced Raid Frames is a World of Warcraft® user interface addon.
Copyright (c) 2017-2021 Britt W. Yazel
Copyright (c) 2017-2023 Britt W. Yazel
This code is licensed under the MIT license (see LICENSE for details) -->

<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
https://raw.githubusercontent.com/Gethe/wow-ui-source/live/Interface/FrameXML/UI_shared.xsd">

<!--Ace3 Libraries-->
<Script file="LibStub\LibStub.lua"/>
<Include file="CallbackHandler-1.0\CallbackHandler-1.0.xml"/>
Expand Down
6 changes: 3 additions & 3 deletions Localizations/Localizations.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<!-- Enhanced Raid Frames is a World of Warcraft® user interface addon.
Copyright (c) 2017-2021 Britt W. Yazel
Copyright (c) 2017-2023 Britt W. Yazel
This code is licensed under the MIT license (see LICENSE for details) -->

<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/ https://raw.githubusercontent.com/Gethe/wow-ui-source/live/FrameXML/UI.xsd">
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
https://raw.githubusercontent.com/Gethe/wow-ui-source/live/Interface/FrameXML/UI_shared.xsd">
<Script file="enUS.lua"/>
<Script file="deDE.lua"/>
<Script file="esES.lua"/>
Expand All @@ -14,5 +15,4 @@
<Script file="ruRU.lua"/>
<Script file="zhCN.lua"/>
<Script file="zhTW.lua"/>

</Ui>
2 changes: 1 addition & 1 deletion Localizations/deDE.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Enhanced Raid Frames is a World of Warcraft® user interface addon.
-- Copyright (c) 2017-2021 Britt W. Yazel
-- Copyright (c) 2017-2023 Britt W. Yazel
-- This code is licensed under the MIT license (see LICENSE for details)

local L = LibStub("AceLocale-3.0"):NewLocale("EnhancedRaidFrames", "deDE", false)
Expand Down
2 changes: 1 addition & 1 deletion Localizations/enUS.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Enhanced Raid Frames is a World of Warcraft® user interface addon.
-- Copyright (c) 2017-2021 Britt W. Yazel
-- Copyright (c) 2017-2023 Britt W. Yazel
-- This code is licensed under the MIT license (see LICENSE for details)

local L = LibStub("AceLocale-3.0"):NewLocale("EnhancedRaidFrames", "enUS", true)
Expand Down
2 changes: 1 addition & 1 deletion Localizations/esES.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Enhanced Raid Frames is a World of Warcraft® user interface addon.
-- Copyright (c) 2017-2021 Britt W. Yazel
-- Copyright (c) 2017-2023 Britt W. Yazel
-- This code is licensed under the MIT license (see LICENSE for details)

local L = LibStub("AceLocale-3.0"):NewLocale("EnhancedRaidFrames", "esES", false)
Expand Down
2 changes: 1 addition & 1 deletion Localizations/esMX.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Enhanced Raid Frames is a World of Warcraft® user interface addon.
-- Copyright (c) 2017-2021 Britt W. Yazel
-- Copyright (c) 2017-2023 Britt W. Yazel
-- This code is licensed under the MIT license (see LICENSE for details)

local L = LibStub("AceLocale-3.0"):NewLocale("EnhancedRaidFrames", "esMX", false)
Expand Down
2 changes: 1 addition & 1 deletion Localizations/frFR.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Enhanced Raid Frames is a World of Warcraft® user interface addon.
-- Copyright (c) 2017-2021 Britt W. Yazel
-- Copyright (c) 2017-2023 Britt W. Yazel
-- This code is licensed under the MIT license (see LICENSE for details)

local L = LibStub("AceLocale-3.0"):NewLocale("EnhancedRaidFrames", "frFR", false)
Expand Down
2 changes: 1 addition & 1 deletion Localizations/itIT.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Enhanced Raid Frames is a World of Warcraft® user interface addon.
-- Copyright (c) 2017-2021 Britt W. Yazel
-- Copyright (c) 2017-2023 Britt W. Yazel
-- This code is licensed under the MIT license (see LICENSE for details)

local L = LibStub("AceLocale-3.0"):NewLocale("EnhancedRaidFrames", "itIT", false)
Expand Down
2 changes: 1 addition & 1 deletion Localizations/koKR.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Enhanced Raid Frames is a World of Warcraft® user interface addon.
-- Copyright (c) 2017-2021 Britt W. Yazel
-- Copyright (c) 2017-2023 Britt W. Yazel
-- This code is licensed under the MIT license (see LICENSE for details)

local L = LibStub("AceLocale-3.0"):NewLocale("EnhancedRaidFrames", "koKR", false)
Expand Down
2 changes: 1 addition & 1 deletion Localizations/ptBR.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Enhanced Raid Frames is a World of Warcraft® user interface addon.
-- Copyright (c) 2017-2021 Britt W. Yazel
-- Copyright (c) 2017-2023 Britt W. Yazel
-- This code is licensed under the MIT license (see LICENSE for details)

local L = LibStub("AceLocale-3.0"):NewLocale("EnhancedRaidFrames", "ptBR", false)
Expand Down
2 changes: 1 addition & 1 deletion Localizations/ruRU.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Enhanced Raid Frames is a World of Warcraft® user interface addon.
-- Copyright (c) 2017-2021 Britt W. Yazel
-- Copyright (c) 2017-2023 Britt W. Yazel
-- This code is licensed under the MIT license (see LICENSE for details)

local L = LibStub("AceLocale-3.0"):NewLocale("EnhancedRaidFrames", "ruRU", false)
Expand Down
Loading

0 comments on commit 609983f

Please sign in to comment.