From 015fe95ac86e5ed74a21414a9ca9fcf9bda4fbb1 Mon Sep 17 00:00:00 2001 From: wutname1 Date: Wed, 21 Aug 2024 15:40:24 -0500 Subject: [PATCH] Refactor function names and improve error handling Simplified the names of several functions in the UnitFrames module, removing redundant 'Element' prefixes. Also replaced underscore placeholders with 'nil' for clarity in UF.Elements:Register calls across multiple files. Added a type check to ensure that an update function is valid before attempting to call it, improving error handling. --- Modules/UnitFrames/Elements/ClassIcon.lua | 8 ++++---- Modules/UnitFrames/Elements/PVPSpecIcon.lua | 2 +- Modules/UnitFrames/Elements/RaidRoleIndicator.lua | 2 +- Modules/UnitFrames/Elements/RaidTargetIndicator.lua | 2 +- Modules/UnitFrames/Elements/SummonIndicator.lua | 2 +- Modules/UnitFrames/Elements/TargetIndicator.lua | 2 +- Modules/UnitFrames/Handlers/Elements.lua | 5 +++++ 7 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Modules/UnitFrames/Elements/ClassIcon.lua b/Modules/UnitFrames/Elements/ClassIcon.lua index be6e0545..61aebdec 100644 --- a/Modules/UnitFrames/Elements/ClassIcon.lua +++ b/Modules/UnitFrames/Elements/ClassIcon.lua @@ -3,7 +3,7 @@ local L = SUI.L ---@param frame table ---@param DB table -local function ElementBuild(frame, DB) +local function Build(frame, DB) frame.ClassIcon = frame:CreateTexture(nil, 'BORDER') frame.ClassIcon.Sizeable = true frame.ClassIcon.shadow = frame:CreateTexture(nil, 'BACKGROUND') @@ -24,7 +24,7 @@ end ---@param frame table ---@param settings? table -local function ElementUpdate(frame, settings) +local function Update(frame, settings) local element = frame.ClassIcon local DB = settings or element.DB local reaction = UnitReaction(frame.unit, 'player') @@ -50,7 +50,7 @@ end ---@param unitName string ---@param OptionSet AceConfig.OptionsTable -local function ElementOptions(unitName, OptionSet) +local function Options(unitName, OptionSet) local ElementSettings = UF.CurrentSettings[unitName].elements.ClassIcon local function OptUpdate(option, val) UF.CurrentSettings[unitName].elements.ClassIcon[option] = val @@ -106,7 +106,7 @@ local Settings = { }, } -UF.Elements:Register('ClassIcon', ElementBuild, ElementUpdate, ElementOptions, Settings) +UF.Elements:Register('ClassIcon', Build, Update, Options, Settings) do -- ClassIcon as an SUIUF module local function Update(self, event, unit) diff --git a/Modules/UnitFrames/Elements/PVPSpecIcon.lua b/Modules/UnitFrames/Elements/PVPSpecIcon.lua index 539b7a3a..84777910 100644 --- a/Modules/UnitFrames/Elements/PVPSpecIcon.lua +++ b/Modules/UnitFrames/Elements/PVPSpecIcon.lua @@ -18,4 +18,4 @@ local Settings = { }, } -UF.Elements:Register('PVPSpecIcon', Build, _, _, Settings) +UF.Elements:Register('PVPSpecIcon', Build, nil, nil, Settings) diff --git a/Modules/UnitFrames/Elements/RaidRoleIndicator.lua b/Modules/UnitFrames/Elements/RaidRoleIndicator.lua index 8d0c768f..d05d999d 100644 --- a/Modules/UnitFrames/Elements/RaidRoleIndicator.lua +++ b/Modules/UnitFrames/Elements/RaidRoleIndicator.lua @@ -22,4 +22,4 @@ local Settings = { }, } -UF.Elements:Register('RaidRoleIndicator', Build, _, _, Settings) +UF.Elements:Register('RaidRoleIndicator', Build, nil, nil, Settings) diff --git a/Modules/UnitFrames/Elements/RaidTargetIndicator.lua b/Modules/UnitFrames/Elements/RaidTargetIndicator.lua index 0b2ef13a..eab63c8f 100644 --- a/Modules/UnitFrames/Elements/RaidTargetIndicator.lua +++ b/Modules/UnitFrames/Elements/RaidTargetIndicator.lua @@ -22,4 +22,4 @@ local Settings = { }, } -UF.Elements:Register('RaidTargetIndicator', Build, _, _, Settings) +UF.Elements:Register('RaidTargetIndicator', Build, nil, nil, Settings) diff --git a/Modules/UnitFrames/Elements/SummonIndicator.lua b/Modules/UnitFrames/Elements/SummonIndicator.lua index fbe7d880..009e961b 100644 --- a/Modules/UnitFrames/Elements/SummonIndicator.lua +++ b/Modules/UnitFrames/Elements/SummonIndicator.lua @@ -16,4 +16,4 @@ local Settings = { }, } -UF.Elements:Register('SummonIndicator', Build, _, _, Settings) +UF.Elements:Register('SummonIndicator', Build, nil, nil, Settings) diff --git a/Modules/UnitFrames/Elements/TargetIndicator.lua b/Modules/UnitFrames/Elements/TargetIndicator.lua index b15108c3..855e38b9 100644 --- a/Modules/UnitFrames/Elements/TargetIndicator.lua +++ b/Modules/UnitFrames/Elements/TargetIndicator.lua @@ -40,4 +40,4 @@ local Settings = { }, } -UF.Elements:Register('TargetIndicator', Build, Update, _, Settings) +UF.Elements:Register('TargetIndicator', Build, Update, nil, Settings) diff --git a/Modules/UnitFrames/Handlers/Elements.lua b/Modules/UnitFrames/Handlers/Elements.lua index 199ac01f..4238a430 100644 --- a/Modules/UnitFrames/Handlers/Elements.lua +++ b/Modules/UnitFrames/Handlers/Elements.lua @@ -126,6 +126,11 @@ end ---@return boolean --False if the element did not provide an updater function Elements:Update(frame, ElementName, DB) if UF.Elements.List[ElementName] and UF.Elements.List[ElementName].Update then + if type(UF.Elements.List[ElementName].Update) ~= 'function' then + SUI:Error('Element ' .. ElementName .. ' does not have a valid update function.', 'UnitFrames') + return false + end + UF.Elements.List[ElementName].Update(frame, DB or UF.CurrentSettings[frame.unitOnCreate].elements[ElementName] or {}) return true else