Skip to content

Commit

Permalink
fixed repeating sounds and streamlined a few loops. Should now be 100…
Browse files Browse the repository at this point in the history
…% functional and a tad more efficient
  • Loading branch information
zendil committed Mar 29, 2016
1 parent 04f3602 commit 5bfe33b
Showing 1 changed file with 29 additions and 26 deletions.
55 changes: 29 additions & 26 deletions Teds_PVP_Spelltimers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,10 @@ function Teds_PVP_Spelltimers_Event(self,event,...)
--clear out cached values for replacement with fresh ones
F.targetbuffs = {}
--store the old values to check when theres new ones
--TODO: this seems messy. maybe there is a better way?
F.activealerts_old = F.activealerts
F.activealerts_old = F.activealerts --creates a reference, not a copy. but it works?
-- for x,y in pairs(F.activealerts) do
-- F.activealerts_old[x] = y
-- end
F.activealerts = {}
--check all buffs
for i=1,40 do
Expand All @@ -124,31 +126,32 @@ function Teds_PVP_Spelltimers_Event(self,event,...)
F.targetbuffs[i] = {["id"] = id,["expire"] = expire}
end
end
end
--now, filter for the ones we want
if F.targetbuffs then
--if we have buffs on target
for _,v in pairs(F.targetbuffs) do
--iterate through the target's cached buffs
if F.filter_def[v.id] and (v.expire - GetTime()) > 0 then
--buff is in filter and has non-negative duration -> create alert
F.activealerts[v.id] = {["name"] = F.filter_def[v.id],["expire"] = v.expire}
if not F.activealerts_old[v.id] then
--this is the first detection (new buff). Play sound.
PlaySoundFile("Interface\\Addons\\Teds_PVP_Spelltimers\\media\\BoxingArenaSound.ogg","Master")
--KNOWN ISSUE: when multiple alerts are active, losing one will cause the sound to play. Somehow, the remaining aura is then seen as 'new'.
--Unknown how the check fails; both expired and remaining aura should still be in _old on the first iteration after the exired fades.
--now, filter for the ones we want
if F.targetbuffs then
--if we have buffs on target
for _,v in pairs(F.targetbuffs) do
--iterate through the target's cached buffs
if F.filter_def[v.id] and (v.expire - GetTime()) > 0 then
--buff is in filter and has non-negative duration -> create alert
F.activealerts[v.id] = {["name"] = F.filter_def[v.id],["expire"] = v.expire}
end
end
end
end
--now, check if we had any that matched filter
if next(F.activealerts) ~= nil then
--we did match some filters. show the frame (which will start updates)
F:Show()
else
--no alerts to show. hide the frame (which stops updates)
F:Hide()
end
end
--now, check if we had any that matched filter
if next(F.activealerts) ~= nil then
--we did match some filters. show the frame (which will start updates)
F:Show()
else
--no alerts to show. hide the frame (which stops updates)
F:Hide()
end
for m,_ in pairs(F.activealerts) do
--we have to iterate to check for new entries
if not F.activealerts_old[m] then
--we have new alerts. play sound
PlaySoundFile("Interface\\Addons\\Teds_PVP_Spelltimers\\media\\BoxingArenaSound.ogg","Master")
end
end
end
end
end
Expand Down

0 comments on commit 5bfe33b

Please sign in to comment.