Skip to content

Instantly share code, notes, and snippets.

@nefftd
Last active August 29, 2015 14:13
Show Gist options
  • Save nefftd/93c3d1c18f4eae8a7d8a to your computer and use it in GitHub Desktop.
Save nefftd/93c3d1c18f4eae8a7d8a to your computer and use it in GitHub Desktop.
-- Namespace
local _,mod = ...
-- Example
mod:provider 'example' {
function(unit)
-- This function gets invoked as per unit events. If it returns values
-- (select('#',...)>0) then those values are passed to whichever callbacks
-- are registered for this 'provider' on the unit frames.
end,
updatefor = {'.*'}, -- A set of Lua patterns to test if a unit should be
-- able to listen to this event
unitevents = {'BLAH'}, -- A set of Blizzard 'unit' events which pass unitID
-- as first argument. These will directly invoke
-- function above.
resolve = true, -- If truthy, the function also gets invoked for a given
-- unit when that unit changes.
-- Thoughts?: How should I go about having the function above invoked during
-- situations for which a 'unit' event does not exist? For instance,
-- the 'incombat' provider will listen to PLAYER_REGEN_* and should throw
-- an update to player's UF. How to cleanly specify when such updates should
-- be thrown to the UF callbacks, and for which units they should be thrown,
-- when we cannot depend on the event providing the unitID for us? Goal is
-- to avoid being too verbose so that providers can be trivially extended,
-- updated and added.
}
-- Health
mod:provider 'health' {
function(unit)
local min = UnitHealth(unit) or 0
local max = UnitHealthMax(unit) or 0
return min,max
end,
updatefor = {'.*'},
unitevents = {'UNIT_HEALTH','UNIT_MAXHEALTH'},
resolve = true,
}
-- Power
mod:provider 'power' {
function(unit)
local min = UnitPower(unit) or 0
local max = UnitPowerMax(unit) or 0
return min,max
end,
updatefor = {'.*'},
unitevents = {'UNIT_POWER','UNIT_MAXPOWER','UNIT_DISPLAYPOWER'},
resolve = true,
-- add .1 sec timer for 'player' unit
}
-- Druid mana
if PLAYER_CLASS == 'DRUID' then
mod:provider 'druidmana' {
function(unit,ptype)
if ptype and ptype ~= 'MANA' then return end
if UnitPowerType(unit) ~= SPELL_POWER_MANA then return nil end
local min = UnitPower(unit,SPELL_POWER_MANA) or 0
local max = UnitPowerMax(unit,SPELL_POWER_MANA) or 0
return min,max
end,
updatefor = {'player'},
unitevents = {'UNIT_POWER','UNIT_MAXPOWER','UNIT_DISPLAYPOWER'},
}
end
-- Incoming heals
mod:provider 'incheal' {
function(unit)
local h = UnitGetIncomingHeals(unit)
if not h or h <= 0 then return nil end
local min = UnitHealth(unit)
local max = UnitHealthMax(unit)
return h,min,max
end,
updatefor = {'.*'},
unitevents = {'UNIT_HEAL_PREDICTION','UNIT_HEALTH','UNIT_MAXHEALTH'},
resolve = true,
}
-- Combo points
mod:provider 'combopoints' {
}
-- Name
mod:provider 'name' {
function(unit)
local name,realm = UnitName(unit)
if not name then name = unit:gsub('.',string.upper,1) end
if not realm then realm = GetRealmName() or 'Realm' end
local forgein = UnitRealmRelationship(unit) == LE_REALM_RELATION_COALESCED
return name,realm,foreign
end,
updatefor = {'.*'},
unitevents = {'UNIT_NAME_UPDATE'},
resolve = true,
}
-- Level
mod:provider 'level' {
function(unit)
local level = UnitLevel(unit)
local clas = UnitClassification(unit)
if level == -1 then level = nil end
return level,clas
end,
updatefor = {'.*'},
unitevents = {'UNIT_LEVEL','UNIT_CLASSIFICATION_CHANGED'},
resolve = true,
}
-- Class
mod:provider 'class' {
function(unit)
local lclass,enclass = UnitClass(unit)
local shouldcolor = UnitIsPlayer(unit)
return lclass,enclass,shouldcolor
end,
updatefor = {'.*'},
unitevents = {'UNIT_NAME_UPDATE'},
resolve = true,
}
-- Race/faction
mod:provider 'race' {
-- return race, faction, isplayer
}
-- Experience
mod:provider 'xp' {
}
-- Connection
mod:provider 'connected' {
function(unit)
local c = UnitIsConnected(unit)
return c
end,
updatefor = {'.*'},
unitevents = {'UNIT_CONNECTION'},
resolve = true,
}
-- Status
mod:provider 'status' {
-- AFK, DND, Dead, Ghost
}
-- Role
mod:provider 'role' {
-- also try to guess role in BGs based on spec?
}
-- Combat
mod:provider 'incombat' {
-- enable for all units (UnitAffectingCombat)
-- quick updates for player from PLAYER_REGEN_*
}
-- Has Aggro
mod:provider 'aggro' {
-- ?
}
-- Threat
mod:provider 'threat' {
-- ?
}
-- Has DoT
if PLAYER_CLASS == 'DRUID' or PLAYER_CLASS == 'ROGUE' then
mod:provider 'dot' {
-- has DoT? (ie, cannot stealth)
}
end
-- Casting
mod:provider 'casting' {
}
-- GCD
mod:provider 'gcd' {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment