Skip to content

Commit

Permalink
range: Use events to drive updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ls- committed Jun 15, 2024
1 parent 88ce0a0 commit 9d2fea3
Showing 1 changed file with 2 additions and 37 deletions.
39 changes: 2 additions & 37 deletions elements/range.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ Offline units are handled as if they are in range.
local _, ns = ...
local oUF = ns.oUF

local _FRAMES = {}
local OnRangeFrame

local UnitInRange, UnitIsConnected = UnitInRange, UnitIsConnected

local function Update(self, event)
local element = self.Range
local unit = self.unit
Expand Down Expand Up @@ -83,36 +78,14 @@ local function Path(self, ...)
return (self.Range.Override or Update) (self, ...)
end

-- Internal updating method
local timer = 0
local function OnRangeUpdate(_, elapsed)
timer = timer + elapsed

if(timer >= .20) then
for _, object in next, _FRAMES do
if(object:IsShown()) then
Path(object, 'OnUpdate')
end
end

timer = 0
end
end

local function Enable(self)
local element = self.Range
if(element) then
element.__owner = self
element.insideAlpha = element.insideAlpha or 1
element.outsideAlpha = element.outsideAlpha or 0.55

if(not OnRangeFrame) then
OnRangeFrame = CreateFrame('Frame')
OnRangeFrame:SetScript('OnUpdate', OnRangeUpdate)
end

table.insert(_FRAMES, self)
OnRangeFrame:Show()
self:RegisterEvent('UNIT_IN_RANGE_UPDATE', Path)

return true
end
Expand All @@ -121,17 +94,9 @@ end
local function Disable(self)
local element = self.Range
if(element) then
for index, frame in next, _FRAMES do
if(frame == self) then
table.remove(_FRAMES, index)
break
end
end
self:SetAlpha(element.insideAlpha)

if(#_FRAMES == 0) then
OnRangeFrame:Hide()
end
self:UnregisterEvent('UNIT_IN_RANGE_UPDATE', Path)
end
end

Expand Down

0 comments on commit 9d2fea3

Please sign in to comment.