View Single Post
12-28-14, 12:23 PM   #1
cokedrivers
A Rage Talon Dragon Guard
 
cokedrivers's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 325
Which is Better?

Which code is written in a more correct way or are they both the same?

Style A:
Lua Code:
  1. local cBuffs = CreateFrame("Frame")
  2. cBuffs:RegisterEvent("ADDON_LOADED")
  3. cBuffs:SetScript("OnEvent", function(self, event, arg1)
  4.     if event == "ADDON_LOADED" and arg1 == "cBuffs" then
  5.         BuffFrame:SetScale(1.193)
  6.        
  7.        
  8.         local origSecondsToTimeAbbrev = _G.SecondsToTimeAbbrev
  9.         local function SecondsToTimeAbbrevHook(seconds)
  10.             origSecondsToTimeAbbrev(seconds)
  11.  
  12.             local tempTime
  13.             if (seconds >= 86400) then
  14.                 tempTime = ceil(seconds / 86400)
  15.                 return '|cffffffff%dd|r', tempTime
  16.             end
  17.  
  18.             if (seconds >= 3600) then
  19.                 tempTime = ceil(seconds / 3600)
  20.                 return '|cffffffff%dh|r', tempTime
  21.             end
  22.  
  23.             if (seconds >= 60) then
  24.                 tempTime = ceil(seconds / 60)
  25.                 return '|cffffffff%dm|r', tempTime
  26.             end
  27.  
  28.             return '|cffffffff%d|r', seconds
  29.         end
  30.         SecondsToTimeAbbrev = SecondsToTimeAbbrevHook  
  31.  
  32.        
  33.         hooksecurefunc('AuraButton_Update', function(self, index)
  34.             local font = [[Fonts\ARIALN.ttf]]
  35.             local button = _G[self..index]
  36.             if (button) then
  37.                 local duration = _G[self..index..'Duration']
  38.                 if (duration) then
  39.                     duration:ClearAllPoints()
  40.                     duration:SetPoint('BOTTOM', button, 'BOTTOM', 0, -2)
  41.                     if (self:match('Debuff')) then
  42.                         duration:SetFont(font, 12, 'THINOUTLINE')
  43.                     else
  44.                         duration:SetFont(font, 12, 'THINOUTLINE')
  45.                     end
  46.                     duration:SetShadowOffset(0, 0)
  47.                     duration:SetDrawLayer('OVERLAY')
  48.                 end
  49.  
  50.                 local count = _G[self..index..'Count']
  51.                 if (count) then
  52.                     count:ClearAllPoints()
  53.                     count:SetPoint('TOPRIGHT', button)
  54.                     if (self:match('Debuff')) then
  55.                         count:SetFont(font, 12, 'THINOUTLINE')
  56.                     else
  57.                         count:SetFont(font, 12, 'THINOUTLINE')
  58.                     end
  59.                     count:SetShadowOffset(0, 0)
  60.                     count:SetDrawLayer('OVERLAY')
  61.                 end    
  62.             end
  63.         end)
  64.     end
  65.  
  66.     SlashCmdList['RELOADUI'] = function()
  67.         ReloadUI()
  68.     end
  69.     SLASH_RELOADUI1 = '/rl'
  70.    
  71.     self:UnregisterEvent("ADDON_LOADED")
  72. end)

Style B:
Lua Code:
  1. local cBuffs = CreateFrame("Frame")
  2. cBuffs:RegisterEvent("ADDON_LOADED")
  3. cBuffs:SetScript("OnEvent", function(self, event, arg1)
  4.     if event == "ADDON_LOADED" and arg1 == "cBuffs" then
  5.         self:SetScale()
  6.         self:TimeDisplayAdjust()
  7.         self:Duration_Count_Placement()
  8.     end
  9.  
  10.     SlashCmdList['RELOADUI'] = function()
  11.         ReloadUI()
  12.     end
  13.     SLASH_RELOADUI1 = '/rl'
  14.    
  15.     self:UnregisterEvent("ADDON_LOADED")
  16. end)
  17.  
  18. function cBuffs:SetScale()
  19.     BuffFrame:SetScale(1.193)
  20. end
  21.  
  22. function cBuffs:TimeDisplayAdjust()
  23.     local origSecondsToTimeAbbrev = _G.SecondsToTimeAbbrev
  24.     local function SecondsToTimeAbbrevHook(seconds)
  25.         origSecondsToTimeAbbrev(seconds)
  26.  
  27.         local tempTime
  28.         if (seconds >= 86400) then
  29.             tempTime = ceil(seconds / 86400)
  30.             return '|cffffffff%dd|r', tempTime
  31.         end
  32.  
  33.         if (seconds >= 3600) then
  34.             tempTime = ceil(seconds / 3600)
  35.             return '|cffffffff%dh|r', tempTime
  36.         end
  37.  
  38.         if (seconds >= 60) then
  39.             tempTime = ceil(seconds / 60)
  40.             return '|cffffffff%dm|r', tempTime
  41.         end
  42.  
  43.         return '|cffffffff%d|r', seconds
  44.     end
  45.     SecondsToTimeAbbrev = SecondsToTimeAbbrevHook
  46. end
  47.  
  48. function cBuffs:Duration_Count_Placement()
  49.     hooksecurefunc('AuraButton_Update', function(self, index)
  50.         local font = [[Fonts\ARIALN.ttf]]
  51.         local button = _G[self..index]
  52.         if (button) then
  53.             local duration = _G[self..index..'Duration']
  54.             if (duration) then
  55.                 duration:ClearAllPoints()
  56.                 duration:SetPoint('BOTTOM', button, 'BOTTOM', 0, -2)
  57.                 if (self:match('Debuff')) then
  58.                     duration:SetFont(font, 12, 'THINOUTLINE')
  59.                 else
  60.                     duration:SetFont(font, 12, 'THINOUTLINE')
  61.                 end
  62.                 duration:SetShadowOffset(0, 0)
  63.                 duration:SetDrawLayer('OVERLAY')
  64.             end
  65.  
  66.             local count = _G[self..index..'Count']
  67.             if (count) then
  68.                 count:ClearAllPoints()
  69.                 count:SetPoint('TOPRIGHT', button)
  70.                 if (self:match('Debuff')) then
  71.                     count:SetFont(font, 12, 'THINOUTLINE')
  72.                 else
  73.                     count:SetFont(font, 12, 'THINOUTLINE')
  74.                 end
  75.                 count:SetShadowOffset(0, 0)
  76.                 count:SetDrawLayer('OVERLAY')
  77.             end    
  78.         end
  79.     end)
  80. end

Thanks for any opinion on this.

Coke
  Reply With Quote