Thread Tools Display Modes
06-17-19, 11:03 AM   #1
Terenna
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 105
Druid Empowerment code optimization

Good afternoon,

The following code is within my oUF layout. It currently works exactly as intended. It is designed for balance druids to have visual markers of their empowerment stacks. I am curious if there is a more efficient way to do this.

Lua Code:
  1. --[[
  2.     first we are going to make two tables (lunarEmpowerments and solarEmpowerments)
  3.     we're going to make a frame we will utilize later to update the frames
  4.     then we are going to make 3 different individual lunarEmpowerment and solarEmpowerment frames, place them, make them pretty, and then put them in our empowerments parent table and hide them
  5.     then we set our script which will scan the player's buffs for lunar or solar empowerment, if they are there, show the respective number of bars, and if they aren't, hide any bars
  6. ]]--
  7. if UnitClass(unit) == 'Druid' then
  8.     local lunarEmpowerments, solarEmpowerments  = {}, {}
  9.     local empowermentCheckFrame = CreateFrame('Frame', nil, self)
  10.     empowermentCheckFrame:RegisterEvent('PLAYER_ENTERING_WORLD')
  11.     empowermentCheckFrame:RegisterUnitEvent('UNIT_AURA', 'player')
  12.    
  13.     for i = 1, 3 do
  14.         local lunarEmpowerment = CreateFrame('Frame', nil, self)
  15.         local solarEmpowerment = CreateFrame('Frame', nil, self)
  16.         lunarEmpowerment:SetSize(41.3, 5)
  17.         solarEmpowerment:SetSize(41.3, 5)
  18.        
  19.         local lunarEmpowermentTexture = lunarEmpowerment:CreateTexture(nil, 'OVERLAY')
  20.         local solarEmpowermentTexture = solarEmpowerment:CreateTexture(nil, 'OVERLAY')
  21.         lunarEmpowermentTexture:SetAllPoints()
  22.         solarEmpowermentTexture:SetAllPoints()
  23.            
  24.         if i == 1 then
  25.             lunarEmpowerment:SetPoint('BOTTOMRIGHT', self.Power, 'TOP', -0.4, 0.8)
  26.             solarEmpowerment:SetPoint('BOTTOMLEFT', self.Power, 'TOP', 0.4, 0.8)
  27.         else
  28.             lunarEmpowerment:SetPoint('RIGHT', lunarEmpowerments[i - 1], 'LEFT', -0.8, 0)
  29.             solarEmpowerment:SetPoint('LEFT', solarEmpowerments[i - 1], 'RIGHT', 0.8, 0)
  30.         end
  31.            
  32.         lunarEmpowerment:SetBackdrop(BACKDROP)
  33.         solarEmpowerment:SetBackdrop(BACKDROP)
  34.            
  35.         lunarEmpowerment:SetBackdropColor(0, 0, 0)
  36.         solarEmpowerment:SetBackdropColor(0, 0, 0)
  37.            
  38.         lunarEmpowermentTexture:SetTexture(TEXTURE)
  39.         solarEmpowermentTexture:SetTexture(TEXTURE)
  40.            
  41.         lunarEmpowermentTexture:SetVertexColor(0.3, 0.52, 0.9)
  42.         solarEmpowermentTexture:SetVertexColor(1, 0.55, 0)
  43.            
  44.         lunarEmpowerment:Hide()
  45.         solarEmpowerment:Hide()
  46.            
  47.         lunarEmpowerments[i] = lunarEmpowerment
  48.         solarEmpowerments[i] = solarEmpowerment
  49.     end
  50.    
  51.     empowermentCheckFrame:SetScript('OnEvent', function(self)
  52.         local isLunarEmpowered, isSolarEmpowered = false, false
  53.         for i = 1, 40 do
  54.             local name, _, count, _, _, _, _, _, _, spellID = UnitBuff('player', i)
  55.             if not name then break end
  56.             if spellID == 164547 then
  57.                 isLunarEmpowered = true
  58.                 for j = 1, count do
  59.                     lunarEmpowerments[j]:Show()
  60.                 end
  61.                
  62.                 if count < 3 then
  63.                     for k = count + 1, 3 do
  64.                         lunarEmpowerments[k]:Hide()
  65.                     end
  66.                 end
  67.             elseif spellID == 164545 then
  68.                 isSolarEmpowered = true
  69.                 for j = 1, count do
  70.                     solarEmpowerments[j]:Show()
  71.                 end
  72.                
  73.                 if count < 3 then
  74.                     for k = count + 1, 3 do
  75.                         solarEmpowerments[k]:Hide()
  76.                     end
  77.                 end
  78.             end
  79.         end
  80.                
  81.         if not isLunarEmpowered then
  82.             for i = 1, 3 do
  83.                 lunarEmpowerments[i]:Hide()
  84.             end
  85.         end
  86.                
  87.         if not isSolarEmpowered then
  88.             for i = 1, 3 do
  89.                 solarEmpowerments[i]:Hide()
  90.             end
  91.         end
  92.     end)
  93. end

Last edited by Terenna : 06-17-19 at 11:07 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Druid Empowerment code optimization

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off