mirror of
https://github.com/brues-code/pfUI.git
synced 2026-10-20 11:30:48 +00:00
nameplates: remove table gaps and observe timers
This commit is contained in:
+47
-31
@@ -93,20 +93,28 @@ pfUI:RegisterModule("nameplates", "vanilla:tbc", function ()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function PlateCacheDebuffs(self, unitstr)
|
local function PlateCacheDebuffs(self, unitstr, verify)
|
||||||
if not self.debuffcache then self.debuffcache = {} end
|
if not self.debuffcache then self.debuffcache = {} end
|
||||||
|
|
||||||
for id = 1, 16 do
|
for id = 1, 16 do
|
||||||
local effect, _, texture, stacks, _, duration, timeleft = libdebuff:UnitDebuff(unitstr, id)
|
local effect, _, texture, stacks, _, duration, timeleft = libdebuff:UnitDebuff(unitstr, id)
|
||||||
self.debuffcache[id] = self.debuffcache[id] or {}
|
if effect and timeleft then
|
||||||
self.debuffcache[id].effect = effect
|
local start = GetTime() - ( (duration or 0) - ( timeleft or 0) )
|
||||||
self.debuffcache[id].texture = texture
|
local stop = GetTime() + ( timeleft or 0 )
|
||||||
self.debuffcache[id].stacks = stacks
|
self.debuffcache[id] = self.debuffcache[id] or {}
|
||||||
self.debuffcache[id].duration = duration or 0
|
self.debuffcache[id].effect = effect
|
||||||
|
self.debuffcache[id].texture = texture
|
||||||
self.debuffcache[id].start = GetTime() - ( (duration or 0) - ( timeleft or 0) )
|
self.debuffcache[id].stacks = stacks
|
||||||
self.debuffcache[id].stop = GetTime() + ( timeleft or 0 )
|
self.debuffcache[id].duration = duration or 0
|
||||||
|
self.debuffcache[id].start = start
|
||||||
|
self.debuffcache[id].stop = stop
|
||||||
|
elseif self.debuffcache[id] then
|
||||||
|
self.debuffcache[id] = nil
|
||||||
|
table.remove(self.debuffcache, id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self.verify = verify
|
||||||
end
|
end
|
||||||
|
|
||||||
local function PlateUnitDebuff(self, id)
|
local function PlateUnitDebuff(self, id)
|
||||||
@@ -464,29 +472,11 @@ pfUI:RegisterModule("nameplates", "vanilla:tbc", function ()
|
|||||||
|
|
||||||
-- update debuffs
|
-- update debuffs
|
||||||
if C.nameplates["showdebuffs"] == "1" then
|
if C.nameplates["showdebuffs"] == "1" then
|
||||||
|
local verify = string.format("%s:%s", (name or ""), (level or ""))
|
||||||
|
|
||||||
-- update cached debuffs
|
-- update cached debuffs
|
||||||
if C.nameplates["guessdebuffs"] == "1" then
|
if C.nameplates["guessdebuffs"] == "1" and unitstr then
|
||||||
local verify = string.format("%s:%s", (name or ""), (level or ""))
|
plate:CacheDebuffs(unitstr, verify)
|
||||||
|
|
||||||
if unitstr then
|
|
||||||
-- cache all debuffs
|
|
||||||
plate:CacheDebuffs(unitstr)
|
|
||||||
plate.debuffcache.valid = verify
|
|
||||||
elseif plate.debuffcache and plate.debuffcache.valid == verify then
|
|
||||||
-- delete timed out caches
|
|
||||||
for id = 1, 16 do
|
|
||||||
if plate.debuffcache[id].stop and plate.debuffcache[id].stop < GetTime() then
|
|
||||||
table.remove(plate.debuffcache, id)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
elseif plate.debuffcache then
|
|
||||||
-- nameplate changed, invalidating cache
|
|
||||||
for id = 1, 16 do
|
|
||||||
plate.debuffcache[id] = plate.debuffcache[id] or {}
|
|
||||||
plate.debuffcache[id].effect = nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- update all debuff icons
|
-- update all debuff icons
|
||||||
@@ -494,7 +484,7 @@ pfUI:RegisterModule("nameplates", "vanilla:tbc", function ()
|
|||||||
local effect, rank, texture, stacks, dtype, duration, timeleft
|
local effect, rank, texture, stacks, dtype, duration, timeleft
|
||||||
if unitstr then
|
if unitstr then
|
||||||
effect, rank, texture, stacks, dtype, duration, timeleft = libdebuff:UnitDebuff(unitstr, i)
|
effect, rank, texture, stacks, dtype, duration, timeleft = libdebuff:UnitDebuff(unitstr, i)
|
||||||
else
|
elseif plate.verify == verify then
|
||||||
effect, rank, texture, stacks, dtype, duration, timeleft = plate:UnitDebuff(i)
|
effect, rank, texture, stacks, dtype, duration, timeleft = plate:UnitDebuff(i)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -574,6 +564,32 @@ pfUI:RegisterModule("nameplates", "vanilla:tbc", function ()
|
|||||||
update = true
|
update = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- scan for debuff timeouts
|
||||||
|
if frame.nameplate.debuffcache then
|
||||||
|
local plate = frame.nameplate
|
||||||
|
|
||||||
|
-- delete timed out caches
|
||||||
|
for id, data in pairs(plate.debuffcache) do
|
||||||
|
if not data.stop or data.stop < GetTime() then
|
||||||
|
plate.debuffcache[id] = nil
|
||||||
|
trigger = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- remove nil keys whenever a value was removed
|
||||||
|
if trigger then
|
||||||
|
local count = 1
|
||||||
|
for id, data in pairs(plate.debuffcache) do
|
||||||
|
if id ~= count then
|
||||||
|
plate.debuffcache[count] = plate.debuffcache[id]
|
||||||
|
plate.debuffcache[id] = nil
|
||||||
|
end
|
||||||
|
count = count + 1
|
||||||
|
end
|
||||||
|
update = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- run full updates if required
|
-- run full updates if required
|
||||||
if update then
|
if update then
|
||||||
nameplates:OnDataChanged(frame.nameplate)
|
nameplates:OnDataChanged(frame.nameplate)
|
||||||
|
|||||||
Reference in New Issue
Block a user