From 9279fddb24fd2511b0223c3a1038cc0355b5eeae Mon Sep 17 00:00:00 2001 From: yaroot Date: Thu, 25 Nov 2010 19:54:22 +0800 Subject: [PATCH] more buggy codes --- core.lua | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 74 insertions(+), 3 deletions(-) diff --git a/core.lua b/core.lua index 2a4c265..6eb7fe5 100644 --- a/core.lua +++ b/core.lua @@ -12,6 +12,7 @@ local defaults = { }, } + SATimer.all = {} SATimer.unused = {} SATimer.using = {} @@ -35,30 +36,100 @@ function SATimer:OnSAOFEvent(_, event, ...) end function SATimer:SPELL_ACTIVATION_OVERLAY_SHOW(spellID, texture, position, scale, r, g, b) + local f = self:Get(spellID) + local endTime = self:GetTimeLeft(spellID) + + if(endTime) then + -- XXX + if(not f) then + f = self:GetUnused() + self:SetUsing(f) + end + f.spellID = spellID + f.position = position + f.scale = scale + f.r = r + f.g = g + f.b = b + + self:Update(f) + self:UpdateTimers() + else + if(f) then + self:Remove(f) + end + end + end function SATimer:SPELL_ACTIVATION_OVERLAY_HIDE(spellID) local f = self:Get(spellID) if(f) then self:Remove(f) + self:UpdateTimers() + end +end + +function SATimer:UpdateTimers() +end + +do + local _SPELLS = setmetatable({}, {__index=function(t,i) + local n = GetSpellInfo(i) + rawset(t, i, n) + return n + end}) + function SATimer:GetTimeLeft(spellID) + local spell = _SPELLS[spellID] + if(not spell) then return end + + local name, _, _, duration, expiration, caster = UnitAura('player', spell, 'PLAYER') + if(name and duration>0 and expiration>GetTime()) then + return expiration + end end end -function SATimer:Update(spellID, texture, position, scale, r, g, b) +function SATimer:Update(f) end function SATimer:Remove(f) f:Hide() f:SetScript('OnUpdate', nil) + self:SetUnused(f) +end + +function SATimer:SetUsing(f) + self.using[f] = true + self.unused[f] = nil +end + +function SATimer:SetUnused(f) self.using[f] = nil self.unused[f] = true end -function SATimer:Get(spellID, position) +function SATimer:Get(spellID) for f in next, self.using do - if(f.spellID == spellID and (position and f.position == position or true)) then + if(f.spellID == spellID) then return f end end end +function SATimer:GetUnused() + local f = next(self.unused) + if(not f) then + f = self:CreateTimer() + end + + return f +end + +function SATimer:CreateTimer() + local f = CreateFrame('Frame', nil, 'SpellActivationOverlayFrame') + self:SetUnused(f) + + return f +end + -- 1.7.9.5