Files
pfUI/libs/librange.lua
Brues 1c0c9dc019 Replace librange's position scan with ClassicAPI's UnitInRange
librange was a per-frame position scanner: it swept party/raid unit
tokens, cached each one's distance via UnitPosition, and answered range
queries from that cache. All of it existed only because 1.12 had no cheap
way to check an arbitrary unit's distance. ClassicAPI's UnitInRange does
exactly that C-side (fixed 40y healing range, position miss reported via
the second return), so the whole library collapses to a direct call.

Wins from dropping the cache:
- No staleness. The scanner's zone-death and roster-reindex bugs simply
  can't exist without a cache to go stale, so this supersedes the
  keep-alive fixes from 756e8840.
- All classes get target-frame range fading. The old target path faked a
  40y check via IsActionInRange on a healing spell found on the action
  bar, so classes without such a spell (GetRangeSlot returned nil) never
  had a working target range check.

The rangecheck == "0" master switch used to be enforced by hiding the
scanner; with no scanner, move that gate into pfUI.api.UnitInRange so
disabling the check still means nothing fades. Threshold is now 40y (the
ClassicAPI constant) rather than the old 45y. Drop the now-dead
rangechecki (Range Check Interval) setting, its GUI row, and migration.
2026-07-20 16:54:27 -05:00

31 lines
1.1 KiB
Lua

-- 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