Nenue@6: --- Turok - Aura.lua Nenue@6: -- @file-author@ Nenue@6: -- @project-revision@ @project-hash@ Nenue@6: -- @file-revision@ @file-hash@ Nenue@6: -- Created: 12/25/2015 5:58 AM Nenue@6: -- Aura data collection Nenue@6: local GetTime, UnitAura, GetSpellDescription, GetSpellInfo = GetTime, UnitAura, GetSpellDescription, GetSpellInfo Nenue@6: local T, _G, tinsert = Turok, _G, tinsert Nenue@6: local mod = T:GetModule("TimerControl") Nenue@6: Nenue@6: --@debug@ Nenue@6: local cType, cText, cNum, cWord, cKey, cPink, cBool = cType, cText, cNum, cWord, cKey, cPink, cBool Nenue@6: local print = function(...) Nenue@6: if _G.Devian and _G.DevianDB.workspace ~= 1 then Nenue@6: _G.print('Aura', ...) Nenue@6: end Nenue@6: end Nenue@6: print('Peep!', ...) Nenue@6: --@end-debug@ Nenue@6: Nenue@6: T.defaults.spirit.aura = { Nenue@6: counterText = "%p", Nenue@6: subCounterText = "%.p", Nenue@6: chargesText = "%s", Nenue@6: justifyH = 'CENTER', Nenue@6: justifyV = 'TOP', Nenue@6: leftText = "%p", Nenue@6: rightText = "%n", Nenue@6: Nenue@6: passive = { Nenue@6: icon = { Nenue@6: desaturated = false, Nenue@6: color = {1, 1, 1, 1}, Nenue@6: blend = 'BLEND' Nenue@6: } Nenue@6: }, Nenue@6: active = { Nenue@6: icon = { Nenue@6: desaturated = false, Nenue@6: color = {1, 1, 1, 1}, Nenue@6: blend = 'BLEND' Nenue@6: } Nenue@6: }, Nenue@6: } Nenue@6: Nenue@6: local p = mod.prototype.trigger.aura Nenue@6: p.class = 'trigger' -- identifier values that are visible from function scope Nenue@6: p.type = 'aura' Nenue@6: p.cvars = { -- only define things that could break the frame here Nenue@6: } Nenue@6: p.events = { Nenue@6: ['UNIT_AURA'] = true, Nenue@6: } Nenue@6: Nenue@6: --- takes user supplied values or fills itself with the cvar values provided Nenue@6: p.Init = function(self, auraName, auraFilters, auraUnit) Nenue@6: Nenue@6: _G.print('Prototype', 'Aura.Init') Nenue@6: self.unit = auraUnit and auraUnit or self.dvars.unit Nenue@6: self.spellName = auraName and auraName or self.spellName Nenue@6: self.filters = auraFilters and auraFilters or self.dvars.filters Nenue@6: -- set inversion states, states 0 and 1 are only processed when prevState differs Nenue@6: if self.cvars.inverse then Nenue@6: self.flags = { Nenue@6: active = 0, Nenue@6: active_prev = 2, Nenue@6: passive = 0, Nenue@6: passive_prev = 1, Nenue@6: hidden = 1, Nenue@6: hidden_prev = 0, Nenue@6: } Nenue@6: self.duration = 1 Nenue@6: self.expires = 1 Nenue@6: else Nenue@6: self.flags = { Nenue@6: active = 2, Nenue@6: active_prev = 0, Nenue@6: passive = 1, Nenue@6: passive_prev = 0, Nenue@6: hidden = 0, Nenue@6: hidden_prev = 1} Nenue@6: end Nenue@6: print(cWord('Load:'),cNum(self.spellID or self.inventoryID or self.itemID), cText(self.spellName)) Nenue@6: end Nenue@6: Nenue@6: p.Unload = function(self) Nenue@6: print('unloading events') Nenue@6: for k,v in pairs(p.events) do Nenue@6: self:UnregisterEvent(k) Nenue@6: end Nenue@6: end Nenue@6: Nenue@6: --- Return current status data Nenue@6: p.Query = function(self) Nenue@6: print( ' Q:', self.unit , self.spellName, nil, self.filters) Nenue@6: return UnitAura(self.unit , self.spellName, nil, self.filters) Nenue@6: end Nenue@6: Nenue@6: p.SetText = mod.SetText Nenue@6: Nenue@6: --- Set supplied status data, using the list returned by p.Query() Nenue@6: p.Set = function(self, ...) Nenue@6: self.active, self.rank, _, self.count, self.dispelType, self.duration, self.expires, self.caster, Nenue@6: self.isStealable, self.shouldConsolidate, self.spellID, self.canApplyAura, self.isBossDebuff = ... Nenue@6: if self.active then Nenue@6: if self.cvars.duration then Nenue@6: self.duration = self.cvars.duration Nenue@6: print(cKey('force duration ='), cNum(self.cvars.duration)) Nenue@6: end Nenue@6: self.start = self.expires - self.duration Nenue@6: end Nenue@6: end Nenue@6: Nenue@6: --- Handle in the frame itself to limit collateral from bugs Nenue@6: function p.Event(self, event, unit) Nenue@6: self.event = event Nenue@6: if not event then Nenue@6: print(' DRY FIRE') Nenue@6: elseif unit ~= self.unit then Nenue@6: return Nenue@6: end Nenue@6: Nenue@6: --- 3 states: nil, 0, >0 Nenue@6: Nenue@6: local active, rank, _, count, dispelType, duration, expires, caster, isStealable, shouldConsolidate, spellID, canApplyAura, isBossDebuff = self:Query() Nenue@6: local state Nenue@6: if self.cvars.duration and active ~= self.active then Nenue@6: print('passive aura with forced duration') Nenue@6: state = self.flags.active Nenue@6: duration = self.cvars.duration Nenue@6: expires = GetTime() + self.cvars.duration Nenue@6: elseif (not self.cvars.duration and (duration ~= self.duration or expires ~= self.expires)) or active ~= self.active then Nenue@6: if not active then Nenue@6: if (not self.untriggerFunc) or self:untriggerFunc() then Nenue@6: state = self.flags.hidden Nenue@6: end Nenue@6: else Nenue@6: if (not self.triggerFunc) or self:triggerFunc() then Nenue@6: if duration == 0 then Nenue@6: print('passive aura') Nenue@6: state = self.flags.passive Nenue@6: else Nenue@6: print('updating an active aura') Nenue@6: state = self.flags.active Nenue@6: end Nenue@6: self.start = expires - duration Nenue@6: end Nenue@6: end Nenue@6: end Nenue@6: Nenue@6: if state then Nenue@6: T:Dispatch('TK_AURA_UPDATE', self.spellID, self.filters, state, self.displayState) Nenue@6: self:Set(active, rank, _, count, dispelType, duration, expires, caster, isStealable, shouldConsolidate, spellID, canApplyAura, isBossDebuff) Nenue@6: self:SetState(state) Nenue@6: print(cText('push state'), cNum(self.displayState).. ' (prev: '.. cNum(self.prevState)..')', self.timerName, cText(active), cKey(duration), cNum(expires), cBool(self.cvars.inverse)) Nenue@6: else Nenue@6: print(cText('no changes'), cNum(self.displayState).. ' (prev: '.. cNum(self.prevState)..')', cText(self.timerName)) Nenue@6: end Nenue@6: end Nenue@6: Nenue@6: p.Value = function(self) Nenue@6: return (self.charges and self.charges < self.maxCharges) and ((GetTime() - self.chargeStart) / self.chargeDuration) or ((GetTime() - self.start) / self.duration) Nenue@6: end