Fold librange into pfUI.api.UnitInRange

This commit is contained in:
Brues
2026-10-31 15:23:13 -05:00
parent 7ba0fedd2b
commit 2d5cf94ae1
4 changed files with 9 additions and 40 deletions
+8 -8
View File
@@ -150,8 +150,7 @@ function pfUI.api.checkversion(chkmajor, chkminor, chkfix)
end
-- [ UnitInRange ]
-- Returns whether a party/raid member is nearby.
-- It takes care of the rangecheck module if existing.
-- Returns whether a party/raid member is nearby, by the configured range check.
-- unit [string] A unit to query (string, unitID)
-- return: [bool] "1" if in range otherwise "nil"
function pfUI.api.UnitInRange(unit)
@@ -166,20 +165,21 @@ function pfUI.api.UnitInRange(unit)
-- returned nil above, matching the pre-collapse behavior.
if C.unitframes.rangecheck == "0" then return 1 end
-- UnitXP precise mode: skip librange entirely, use direct distance check
-- UnitXP precise mode: direct distance check against the configured range
if C.unitframes.rangecheck_mode == "unitxp" and _G.UnitXP then
local threshold = tonumber(C.unitframes.rangecheck_distance) or 40
local success, distance = pcall(_G.UnitXP, "distanceBetween", "player", unit)
if success and distance then
return distance <= threshold and 1 or nil
end
-- fallthrough to librange if UnitXP fails
-- fallthrough to the 40y check if UnitXP fails
end
if pfUI.api.librange then
return pfUI.api.librange:UnitInSpellRange(unit)
end
return nil
-- ClassicAPI's 40y check, _G-qualified since the bare name is this function
-- inside the pfUI environment. A unit it can't place (outside the client's
-- sync range) counts as in range.
local inRange, checked = _G.UnitInRange(unit)
return (inRange or not checked) and 1 or nil
end
-- [ UnitHasBuff ]
+1 -1
View File
@@ -1719,7 +1719,7 @@ function pfUI.uf:RefreshUnitState(unit)
unit.power.bar:SetMinMaxValues(0, 100)
SetBarValue(unit.hp.bar, 0)
SetBarValue(unit.power.bar, 0)
elseif unit.config.faderange == "1" and not pfUI.api.UnitInRange(unit.label .. unit.id, 4) and not unlock then
elseif unit.config.faderange == "1" and not pfUI.api.UnitInRange(unit.label .. unit.id) and not unlock then
alpha = unit.alpha_outrange
end
-1
View File
@@ -2,7 +2,6 @@
<Include file="..\libs\libtipscan.lua"/>
<Include file="..\libs\libspell.lua"/>
<Include file="..\libs\libdebuff.lua"/>
<Include file="..\libs\librange.lua"/>
<Include file="..\libs\libunitscan.lua"/>
<Include file="..\libs\libhealth.lua"/>
<Include file="..\libs\libthrottle.lua"/>
-30
View File
@@ -1,30 +0,0 @@
-- load pfUI environment
setfenv(1, pfUI:GetEnvironment())
--[[ librange ]]--
-- A thin wrapper over ClassicAPI's UnitInRange: a fixed 40y healing-range
-- check computed C-side from unit positions, valid for any unit. There is
-- no cache or scan loop -- the check is cheap enough to run per query,
-- which also sidesteps the staleness a cached scan hit on zone changes and
-- roster re-indexing.
--
-- librange:UnitInSpellRange(unit)
-- Returns `1` if the unit is within range, `nil` otherwise.
if pfUI.api.librange then return end
local librange = {}
function librange:UnitInSpellRange(unit)
-- _G-qualified: bare `UnitInRange` resolves to pfUI.api.UnitInRange inside
-- the pfUI environment (which calls us), so this must reach ClassicAPI's
-- global directly or it recurses.
local inRange, checked = _G.UnitInRange(unit)
-- position miss (e.g. a unit outside the client's sync range): we can't
-- tell, so default to in-range -- matches the old cache's nil behavior.
if not checked then return 1 end
return inRange and 1 or nil
end
-- add librange to pfUI API
pfUI.api.librange = librange