annotate Spirit.lua @ 5:8a9a6637f082

focusbar data collection tracking db info declarations to main chunk
author Nenue
date Tue, 15 Dec 2015 10:10:22 -0500
parents 766d8a40a1d6
children
rev   line source
Nenue@1 1 -- User: Krakyn
Nenue@1 2 -- Created: 12/8/2015 7:30 PM
Nenue@1 3 local T = LibStub("AceAddon-3.0"):GetAddon("Turok")
Nenue@1 4 local TL = 'Spirit'
Nenue@1 5 local print = function(...) _G.print(TL, ...) end
Nenue@1 6 local LSM = LibStub("LibSharedMedia-3.0")
Nenue@1 7 local mod = T:NewModule("Spirit", "AceTimer-3.0")
Nenue@1 8 local time = _G.ct
Nenue@1 9 local auras = {
Nenue@1 10 168811, -- sniper training
Nenue@1 11 168809, -- sniper training: recently moved
Nenue@1 12 13159, -- aspect of the pack,
Nenue@1 13 187615, -- Maalus
Nenue@1 14 }
Nenue@1 15 local spells = {
Nenue@1 16 3045, -- rapid fire,
Nenue@1 17 26297, -- berserking,
Nenue@1 18 121818, -- stampede,
Nenue@1 19
Nenue@1 20 }
Nenue@1 21 local FRAME_PREFIX = 'TkSpirit'
Nenue@1 22 local FADE_TIME = 0.5
Nenue@1 23 -- local repetitive tasks
Nenue@1 24 local function FindSpirit(id)
Nenue@1 25 local db = T.db
Nenue@1 26 local c = db.spirit
Nenue@1 27 local isIcon = false
Nenue@1 28 if db.spirit.progressbar[id] then
Nenue@1 29 c = db.spirit.progressbar[id]
Nenue@1 30 elseif db.spirit.icon[id] then
Nenue@1 31 c = db.spirit.icon[id]
Nenue@1 32 isIcon = true
Nenue@1 33 end
Nenue@1 34 local name, rank, icon, castingTime, minRange, maxRange, spellID = GetSpellInfo(id)
Nenue@1 35 local s = {
Nenue@1 36 name = name,
Nenue@1 37 rank = rank,
Nenue@1 38 icon = icon,
Nenue@1 39 castingTime = castingTime,
Nenue@1 40 minRange = minRange,
Nenue@1 41 maxRange = maxRange,
Nenue@1 42 spellID = spellID
Nenue@1 43 }
Nenue@1 44
Nenue@1 45 return s, c, isIcon
Nenue@1 46 end
Nenue@1 47
Nenue@1 48 function mod:OnEnable()
Nenue@1 49 local db = _G.TurokData
Nenue@1 50 self.aura_watch = {}
Nenue@1 51 self.cooldown_watch = {}
Nenue@1 52 self.item_watch = {}
Nenue@1 53 self.myGUID = UnitGUID('player')
Nenue@1 54
Nenue@1 55
Nenue@1 56 db.spirit = {
Nenue@1 57 foreground_color = {1, 1, 1, 0.7},
Nenue@1 58 foreground_texture = 'Cilo',
Nenue@1 59 foreground_blend = 'BLEND',
Nenue@1 60 foreground_inset = -1,
Nenue@1 61 background_color = {0, 0, 0, 0.7},
Nenue@1 62 background_blend = 'BLEND',
Nenue@1 63 background_texture = 'Cilo',
Nenue@1 64 icon_show = true,
Nenue@1 65 width = 250, height = 20,
Nenue@1 66 anchor = 'CENTER', parent = 'UIParent', anchorTo = 'CENTER',
Nenue@1 67 posX = 0, posY = -150,
Nenue@1 68 label_color = {1, 1, 1, 1},
Nenue@1 69 label_font = 'turok',
Nenue@1 70 label_size = 14,
Nenue@1 71 label_inset = -2,
Nenue@1 72 label_point = 'LEFT',
Nenue@1 73 label_outline = 'OUTLINE',
Nenue@1 74 label_string = '%n %p',
Nenue@1 75 label_strata = 'HIGH',
Nenue@1 76 expire_sound = LSM:Fetch('sound'),
Nenue@1 77 strata = 'LOW',
Nenue@1 78 icon = {
Nenue@1 79 [13159] = { -- Aspect of the Pack
Nenue@1 80 posX = 20, posY = 20, width = 140, height = 140,
Nenue@1 81 },
Nenue@1 82 [3045] = {
Nenue@1 83 parent = 13159, anchor = 'RIGHT', anchorTo = 'LEFT',
Nenue@1 84 posx = 0, posY = 0, width = 64, height = 64,
Nenue@1 85 }
Nenue@1 86 },
Nenue@1 87 progressbar = {
Nenue@1 88 [168811] = { -- Sniper Training (duration)
Nenue@1 89 background_color = {0,0,0,0},
Nenue@1 90 foreground_color = {1,0,0,1},
Nenue@1 91 anchor = 'BOTTOMLEFT', parent = 'TkFocusBar', anchorTo = 'TOPLEFT',
Nenue@1 92 posX = 0, posY = 0, height = 16, width = 250,
Nenue@1 93 label_string = '',
Nenue@1 94 label_point = 'TOPLEFT',
Nenue@1 95 strata = 'LOW',
Nenue@1 96 attach = {{
Nenue@1 97 width_relative = 0.5,
Nenue@1 98 height_relative = 1,
Nenue@1 99 background_color = {1,0,0,1},
Nenue@1 100 foreground_color = {1,1,0.5, 1},
Nenue@1 101 background_blend = 'ADD',
Nenue@1 102 foreground_blend = 'ADD',
Nenue@1 103
Nenue@1 104 anchor = 'LEFT',
Nenue@1 105 anchorTo = 'LEFT',
Nenue@1 106 strata = 'MEDIUM',
Nenue@1 107 }}
Nenue@1 108 },
Nenue@1 109 [168809] = { -- Sniper Training: Recently Moved
Nenue@1 110 background_color = {0,0,0,0 },
Nenue@1 111 foreground_color = {1,1,1,1},
Nenue@1 112 foreground_blend = 'ADD',
Nenue@1 113 anchor = 'BOTTOMLEFT', parent = 'TkFocusBar', anchorTo = 'TOPLEFT',
Nenue@1 114 strata = 'HIGH',
Nenue@1 115 posX = 0, posY = 0, height = 16, width = 125,
Nenue@1 116 icon_show = false,
Nenue@1 117 label_string = '',
Nenue@1 118 exceptions = {
Nenue@1 119 function(aura)
Nenue@1 120 return (mod.aura_watch[168811].expires < aura.expires)
Nenue@1 121 end
Nenue@1 122 },
Nenue@1 123 },
Nenue@1 124 },
Nenue@1 125 }
Nenue@1 126
Nenue@1 127 for _, id in pairs(auras) do
Nenue@1 128 -- store spellinfo fetch
Nenue@1 129 self.aura_watch[id] = self:CreateSpiritFrame(id)
Nenue@1 130 self.aura_watch[id].count = 0
Nenue@1 131 self.aura_watch[id].duration = 0
Nenue@1 132 self.aura_watch[id].expires = 0
Nenue@1 133 self.aura_watch[id].caster = 0
Nenue@1 134 print('AURA', id, self.aura_watch[id].name)
Nenue@1 135 end
Nenue@1 136
Nenue@1 137 for _, id in ipairs(spells) do
Nenue@1 138 self.cooldown_watch[id] = self:CreateSpiritFrame(id)
Nenue@1 139 print('COOLDOWN', id, self.cooldown_watch[id].name)
Nenue@1 140 end
Nenue@1 141
Nenue@1 142 self:SpiritScan()
Nenue@1 143 self:RegisterEvent('UNIT_AURA')
Nenue@1 144 self:RegisterEvent('COMBAT_LOG_EVENT_UNFILTERED')
Nenue@1 145 self:RegisterEvent('PLAYER_REGEN_DISABLED')
Nenue@1 146 self:RegisterEvent('PLAYER_REGEN_ENABLED')
Nenue@1 147 end
Nenue@1 148
Nenue@1 149 -- StatusBar factory
Nenue@1 150 function mod:CreateSpiritFrame(id)
Nenue@1 151 local s, c, isIcon = FindSpirit(id)
Nenue@1 152
Nenue@1 153 -- how much frame do we need?
Nenue@1 154 local f
Nenue@1 155 if isIcon then
Nenue@1 156 f = CreateFrame('Frame', FRAME_PREFIX..id, UIParent)
Nenue@1 157 f.db = c
Nenue@1 158 function f:Update() end
Nenue@1 159 else
Nenue@1 160 f = T:CreateBar('TkAuraBar'..id, c)
Nenue@1 161 f.isTimer = true
Nenue@1 162 if (c.label_string ~= '') then
Nenue@1 163 print('has label, add it', id)
Nenue@1 164 T:AddLabel(f, c)
Nenue@1 165 end
Nenue@1 166 end
Nenue@1 167 f:Hide()
Nenue@1 168
Nenue@1 169 -- general display
Nenue@1 170 f:SetPoint(c.anchor, c.parent, c.anchorTo, c.posX, c.posY)
Nenue@1 171 f:SetSize(c.width, c.height)
Nenue@1 172 f:SetFrameStrata(c.strata)
Nenue@1 173
Nenue@1 174 -- icon?
Nenue@1 175 f.icon = s.icon
Nenue@1 176 T:CreateStatusIcon(f)
Nenue@1 177
Nenue@1 178 -- attachment frames?
Nenue@1 179 if c.attach then
Nenue@1 180 for i, e in ipairs(c.attach) do
Nenue@1 181 local ef = CreateFrame('Frame', 'TkExtra'..id, f)
Nenue@1 182 f[i] = ef
Nenue@1 183 ef:SetPoint(e.anchor, f, e.anchorTo)
Nenue@1 184 ef:SetSize(c.width * e.width_relative or e.width, c.height * e.height_relative or e.height)
Nenue@1 185 ef:SetFrameStrata(e.strata or c.strata)
Nenue@1 186 T:CreateStatusTextures(ef, e)
Nenue@1 187 end
Nenue@1 188 end
Nenue@1 189
Nenue@1 190 -- setup suppression checking
Nenue@1 191 if c.exceptions then
Nenue@1 192 function s:ExceptionCheck ()
Nenue@1 193 for i, func in ipairs(c.exceptions) do
Nenue@1 194 if not func(self) then
Nenue@1 195 return false, i
Nenue@1 196 end
Nenue@1 197 end
Nenue@1 198 return true
Nenue@1 199 end
Nenue@1 200 else
Nenue@1 201 function s:ExceptionCheck () return true end
Nenue@1 202 end
Nenue@1 203
Nenue@1 204 -- access linkage
Nenue@1 205 f.format = c.label_string
Nenue@1 206 f.spirit = s
Nenue@1 207 f.name = s.name
Nenue@1 208 s.frame = f
Nenue@1 209 return s
Nenue@1 210 end
Nenue@1 211
Nenue@1 212 function mod:UNIT_AURA(e, unit)
Nenue@1 213 if unit == 'player' then
Nenue@1 214 self:SpiritScan()
Nenue@1 215 end
Nenue@1 216 end
Nenue@1 217
Nenue@1 218 -- Updates aura watches
Nenue@1 219 function mod:SpiritScan()
Nenue@1 220 local db = _G.TurokData
Nenue@1 221 for id, aura in pairs(self.aura_watch) do
Nenue@1 222 local c = aura.conf
Nenue@1 223 local f = aura.frame
Nenue@1 224
Nenue@1 225 local name, _, _, count, _, duration, expires, caster = UnitAura('player', aura.name)
Nenue@1 226
Nenue@1 227 if name then
Nenue@1 228 aura.duration = duration
Nenue@1 229 aura.expires = expires
Nenue@1 230 aura.caster = caster
Nenue@1 231 aura.count = count
Nenue@1 232 local test, i = aura:ExceptionCheck()
Nenue@1 233 print(name, duration, expires)
Nenue@1 234 if not test then
Nenue@1 235 print('suppressing '..aura.name..' (failed test #'..i..')')
Nenue@1 236 else
Nenue@1 237 f.name = name
Nenue@1 238 f:Update(nil, duration, expires)
Nenue@1 239 f:Show()
Nenue@1 240 end
Nenue@1 241 end
Nenue@1 242 end
Nenue@1 243 end
Nenue@1 244
Nenue@1 245 function mod:PLAYER_REGEN_ENABLED()
Nenue@1 246 for id, aura in pairs(self.aura_watch) do
Nenue@1 247 print('non-combat alpha for #', id, aura.name, 'is', aura.frame.db.alpha_ooc)
Nenue@1 248 aura.frame.fadeTo = aura.frame.db.alpha_ooc
Nenue@1 249 aura.frame.fadeDuration = FADE_TIME
Nenue@1 250 end
Nenue@1 251 end
Nenue@1 252
Nenue@1 253 function mod:PLAYER_REGEN_DISABLED()
Nenue@1 254 for id, aura in pairs(self.aura_watch) do
Nenue@1 255 print('combat alpha for #', id, aura.name, 'is', aura.frame.db.alpha)
Nenue@1 256 aura.frame.fadeTo = aura.frame.db.alpha
Nenue@1 257 aura.frame.fadeDuration = FADE_TIME
Nenue@1 258 end
Nenue@1 259 end
Nenue@1 260
Nenue@1 261 -- This is the most reliable way of catching item and spell uses, other events are delayed or too vague to be useful
Nenue@1 262 function mod:COMBAT_LOG_EVENT_UNFILTERED(e, ...)
Nenue@1 263 local timestamp, combatEvent, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags =
Nenue@1 264 ...; -- Those arguments appear for all combat event variants.
Nenue@1 265 local eventPrefix, eventSuffix = combatEvent:match("^(.-)_?([^_]*)$");
Nenue@1 266 if eventPrefix ~= 'SPELL_' or sourceGUID ~= self.myGUID then
Nenue@1 267 return
Nenue@1 268 end
Nenue@1 269
Nenue@1 270 local spellid, name, count, type = select(13, select('#', ...), ...)
Nenue@1 271 local kc = ''
Nenue@1 272 for i=1,4 do
Nenue@1 273 kc = kc .. string.format('%X',((string.byte(eventSuffix,i) % 8) + 8))
Nenue@1 274 end
Nenue@1 275 print('|cFFFF'..kc..eventSuffix..'|r', sourceName, destName, spellid, name)
Nenue@1 276 end