Skip to content

Commit

Permalink
FSR & Mana configs
Browse files Browse the repository at this point in the history
  • Loading branch information
d87 committed May 31, 2021
1 parent 8c8111c commit ff80233
Show file tree
Hide file tree
Showing 3 changed files with 281 additions and 39 deletions.
36 changes: 7 additions & 29 deletions NugEnergy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ NugEnergy.L = L


NugEnergy:RegisterEvent("PLAYER_LOGIN")
NugEnergy:RegisterEvent("PLAYER_LOGOUT")
local UnitPower = UnitPower
local math_modf = math.modf
local math_abs = math.abs
Expand Down Expand Up @@ -74,8 +73,8 @@ local ColorArray = function(color) return {color.r, color.g, color.b} end
local defaults = {
global = {
classConfig = {
ROGUE = { "EnergyRogueTicker", "EnergyRogueTicker", "EnergyRogueTicker" },
DRUID = { "Disabled", "Disabled", "Disabled", "Disabled" },
ROGUE = { "EnergyRogue", "EnergyRogue", "EnergyRogue" },
DRUID = { "ShapeshiftDruidClassic", "ShapeshiftDruidClassic", "ShapeshiftDruidClassic", "ShapeshiftDruidClassic" },
PALADIN = { "Disabled", "Disabled", "Disabled" },
MONK = { "Disabled", "Disabled", "Disabled" },
WARLOCK = { "Disabled", "Disabled", "Disabled" },
Expand Down Expand Up @@ -179,11 +178,6 @@ function NugEnergy.PLAYER_LOGIN(self,event)
pmult = (768/h) / UIParent:GetScale()
end


if APILevel >= 3 then
self:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED") -- for mark swaps
end

NugEnergy:UpdateUpvalues()

NugEnergy:Initialize()
Expand All @@ -202,10 +196,6 @@ function NugEnergy.PLAYER_LOGIN(self,event)
end)
end

-- function NugEnergy.PLAYER_LOGOUT(self, event)
-- RemoveDefaults( NugEnergyDB, defaults)
-- end

function NugEnergy:UpdateUpvalues()
isVertical = NugEnergy.db.profile.isVertical
onlyText = NugEnergy.db.profile.hideBar
Expand Down Expand Up @@ -718,7 +708,7 @@ function NugEnergy.UpdateEnergy(self, elapsed)
-- self.spentBar:SetColor(unpack(c))
self:SetColor(unpack(c))

if APILevel <= 2 then
if APILevel <= 2 and PowerTypeIndex == Enum_PowerType_Energy then
self:ColorTickWindow(capped, c)
end

Expand All @@ -727,6 +717,7 @@ function NugEnergy.UpdateEnergy(self, elapsed)
if self.marks[p] then self.marks[p].shine:Play() end
end
end
NugEnergy.Update = NugEnergy.UpdateEnergy
NugEnergy.__UpdateEnergy = NugEnergy.UpdateEnergy

-- local idleSince = nil
Expand Down Expand Up @@ -759,16 +750,6 @@ NugEnergy.__UpdateEnergy = NugEnergy.UpdateEnergy
-- end
-- end

function NugEnergy:PlaySound()
local sound
if NugEnergy.db.profile.soundName == "Heartbeat" then
sound = "Interface\\AddOns\\NugEnergy\\heartbeat.mp3"
elseif NugEnergy.db.profile.soundName then
sound = NugEnergy.db.profile.soundNameCustom
end
PlaySoundFile(sound, NugEnergy.db.profile.soundChannel)
end

function NugEnergy:Disable()
PowerFilter = nil
PowerTypeIndex = nil
Expand Down Expand Up @@ -872,12 +853,6 @@ function NugEnergy:UpdateVisibility()
end
end

function NugEnergy.ACTIVE_TALENT_GROUP_CHANGED()
NugEnergy:ReconfigureMarks()
if NugEnergy.UNIT_DISPLAYPOWER then
NugEnergy:UNIT_DISPLAYPOWER()
end
end
function NugEnergy.ReconfigureMarks(self)
-- local spec_marks = NugEnergy.db.profile_Character.marks[GetSpecialization() or 0]
-- for at, frame in pairs(NugEnergy.marks) do
Expand Down Expand Up @@ -2416,6 +2391,9 @@ function NugEnergy:ResetConfig()
self.eventProxy:SetScript("OnUpdate", nil)
self:UpdateBarEffects()
self.ticker:Disable()
if self.fsrwatch then
self.fsrwatch:Disable()
end
end

function NugEnergy:SelectConfig(name)
Expand Down
215 changes: 207 additions & 8 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ local math_modf = math.modf
local math_abs = math.abs
local GetSpecialization = APILevel <= 2 and function() return 1 end or _G.GetSpecialization

local IsAnySpellKnown = function (...)
for i=1, select("#", ...) do
local spellID = select(i, ...)
if not spellID then break end
if IsPlayerSpell(spellID) then return spellID end
end
end

local GetSpell = function(spellId)
return function()
Expand All @@ -20,6 +27,26 @@ local GetPowerBy5 = function(unit)
return p, math_modf(p/5)*5, nil, nil, p == pmax, nil
end

local execute = false
local function UNIT_HEALTH_EXECUTE(execute_range)
return function(self, event, unit)
if unit ~= "target" then return end
local uhm = UnitHealthMax(unit)
if uhm == 0 then uhm = 1 end
if execute_range then
execute = UnitHealth(unit)/uhm < execute_range
else
execute = false
end
self:UpdateEnergy()
end
end
local function UNIT_HEALTH_EXECUTE_PLAYER_TARGET_CHANGED(self,event)
if UnitExists('target') then
self.eventProxy:UNIT_HEALTH(self, event, "target")
end
end

local MakeGeneralGetPower = function(PowerTypeIndex, shineZone, cappedZone, minLimit, throttleText)
return function(unit)
local p = UnitPower(unit, PowerTypeIndex)
Expand All @@ -30,7 +57,7 @@ local MakeGeneralGetPower = function(PowerTypeIndex, shineZone, cappedZone, minL
-- if GetSpecialization() == 3 p < 60 pmax-10
local capped = p >= pmax-cappedZone
local p2 = throttleText and math_modf(p/5)*5
return p, p2, nil, shine, capped, (minLimit and p < minLimit)
return p, p2, execute, shine, capped, (minLimit and p < minLimit)
end
end

Expand All @@ -55,8 +82,6 @@ local function GENERAL_UPDATE_STEALTH(self)
end


local lastEnergyTickTime = GetTime()
local lastEnergyValue = 0
local GetPower_ClassicRogueTicker = function(PowerTypeIndex, shineZone, cappedZone, minLimit, throttleText)
local ticker = NugEnergy.ticker
return function(unit)
Expand All @@ -69,10 +94,6 @@ local GetPower_ClassicRogueTicker = function(PowerTypeIndex, shineZone, cappedZo
return p, p2, nil, shine, capped, (minLimit and p2 < minLimit)
end
end
local UNIT_MAXPOWER_ClassicTicker = function(self)
self:SetMinMaxValues(0, 2)
end




Expand All @@ -89,6 +110,7 @@ NugEnergy:RegisterConfig("EnergyRogue", {

self.eventProxy:RegisterUnitEvent("UNIT_MAXPOWER", "player")
self.eventProxy.UNIT_MAXPOWER = GENERAL_UNIT_MAXPOWER
GENERAL_UNIT_MAXPOWER(self)

self.eventProxy:RegisterUnitEvent("UNIT_POWER_UPDATE", "player")
self.eventProxy.UNIT_POWER_UPDATE = FILTERED_UNIT_POWER_UPDATE("ENERGY")
Expand All @@ -112,4 +134,181 @@ NugEnergy:RegisterConfig("EnergyRogueTicker", {
self.ticker:Enable()
self:UpdateBarEffects("DISABLE_SMOOTHING")
end,
}, "ROGUE")
}, "ROGUE")

NugEnergy:RegisterConfig("GeneralRage", {
triggers = { GetSpecialization },
setup = function(self, spec)
self:SetPowerFilter("RAGE", Enum.PowerType.Rage)
self:SetNormalColor()
self.flags.shouldBeFull = true

self.eventProxy:RegisterUnitEvent("UNIT_MAXPOWER", "player")
self.eventProxy.UNIT_MAXPOWER = GENERAL_UNIT_MAXPOWER
GENERAL_UNIT_MAXPOWER(self)

self.eventProxy:RegisterUnitEvent("UNIT_POWER_UPDATE", "player")
self.eventProxy.UNIT_POWER_UPDATE = FILTERED_UNIT_POWER_UPDATE("RAGE")

-- self.eventProxy:RegisterUnitEvent("UNIT_HEALTH", "target")
-- self.eventProxy.UNIT_HEALTH = UNIT_HEALTH_EXECUTE(0.2)

-- self:SetPowerGetter(MakeGeneralGetPower(Enum.PowerType.Rage, 30, 10, nil, nil))
end,
}, "GENERAL")


local GetPower_ClassicMana = function(unit)
local p = GetTime() - NugEnergy.ticker:GetLastTickTime()
local _, PowerTypeIndex = NugEnergy:GetPowerFilter()
local mana = UnitPower(unit, PowerTypeIndex)
local pmax = UnitPowerMax(unit, PowerTypeIndex)
local p2
if pmax > 0 then
p2 = string.format("%d", mana/pmax*100)
end
local shine = nil
local capped = mana == pmax
local insufficient = nil
return p, p2, execute, shine, capped, insufficient
end

NugEnergy:RegisterConfig("GeneralMana", {
triggers = { GetSpecialization },
setup = function(self, spec)
self:SetPowerFilter("MANA", Enum.PowerType.Mana)
self:SetNormalColor()
self.flags.shouldBeFull = true

-- self.eventProxy:RegisterUnitEvent("UNIT_MAXPOWER", "player")
-- self.eventProxy.UNIT_MAXPOWER = GENERAL_UNIT_MAXPOWER
-- GENERAL_UNIT_MAXPOWER(self)
self.eventProxy:UnregisterEvent("UNIT_MAXPOWER")
self:SetMinMaxValues(0, 2)

self.eventProxy:RegisterUnitEvent("UNIT_POWER_UPDATE", "player")
self.eventProxy.UNIT_POWER_UPDATE = FILTERED_UNIT_POWER_UPDATE("MANA")

self.ticker:Enable()
self.eventProxy:SetScript("OnUpdate", function() NugEnergy:UpdateEnergy() end)

self:SetPowerGetter(GetPower_ClassicMana)
end,
}, "GENERAL")


local GetPower_ClassicMana5SR = function(unit)
local p = GetTime() - NugEnergy.fsrwatch:GetLastManaSpentTime()
local _, PowerTypeIndex = NugEnergy:GetPowerFilter()
local mana = UnitPower(unit, PowerTypeIndex)
local pmax = UnitPowerMax(unit, PowerTypeIndex)
local p2
if pmax > 0 then
p2 = string.format("%d", mana/pmax*100)
end
local shine = nil
local capped = nil
local insufficient = nil
-- if p >= 5 and callback then
-- callback()
-- end
-- local p2 = throttleText and math_modf(p2/5)*5 or p2
return p, p2, execute, shine, capped, true
end



NugEnergy:RegisterConfig("GeneralFSRMana", {
triggers = { GetSpecialization },
setup = function(self, spec)
-- local powerFilter = self:GetPowerFilter()
-- if powerFilter ~= "MANA" then
self:ApplyConfig("GeneralMana")
-- end

self.fsrwatch = self.fsrwatch or self:Make5SRWatcher(function(self)
local powerFilter = self:GetPowerFilter()
if powerFilter == "MANA" then
self:ApplyConfig("GeneralFSRMana")
end
end)
self.fsrwatch:Enable()

self.ticker:Enable("FSR", function(self)
self:ResetConfig()
self:ApplyConfig("GeneralMana")
self.fsrwatch:Enable()
self:Update()
end)

self.eventProxy:UnregisterEvent("UNIT_MAXPOWER")
self:SetMinMaxValues(0, 5)

self:SetPowerGetter(GetPower_ClassicMana5SR)
self.eventProxy:SetScript("OnUpdate", function() NugEnergy:UpdateEnergy() end)
end,
}, "GENERAL")

NugEnergy:RegisterConfig("RageWarriorClassic", {
triggers = { GetSpecialization },
setup = function(self, spec)
self:ApplyConfig("GeneralRage")

if IsAnySpellKnown(20662, 20661, 20660, 20658, 5308) then
self.eventProxy:RegisterUnitEvent("UNIT_HEALTH", "target")
self.eventProxy.UNIT_HEALTH = UNIT_HEALTH_EXECUTE(0.2)

self.eventProxy:RegisterEvent("PLAYER_TARGET_CHANGED")
self.eventProxy.PLAYER_TARGET_CHANGED = UNIT_HEALTH_EXECUTE_PLAYER_TARGET_CHANGED
end

self:SetPowerGetter(MakeGeneralGetPower(Enum.PowerType.Rage, 30, 10, nil, nil))
end,
}, "WARRIOR")









NugEnergy:RegisterConfig("RageDruidClassic", {
triggers = { GetSpecialization },
setup = function(self, spec)
self:ApplyConfig("GeneralRage")

self:SetPowerGetter(MakeGeneralGetPower(Enum.PowerType.Rage, 30, 10, nil, nil))
end,
}, "DRUID")


NugEnergy:RegisterConfig("ShapeshiftDruidClassic", {
triggers = { GetSpecialization },

setup = function(self, spec)
self:RegisterEvent("UNIT_DISPLAYPOWER") -- Registering on main addon, not event proxy
self.UNIT_DISPLAYPOWER = function(self)
local newPowerType = select(2,UnitPowerType("player"))
self:ResetConfig()

if newPowerType == "ENERGY" then
self:ApplyConfig("EnergyRogueTicker")
if APILevel == 2 then
self.ticker:Reset()
end
self:Update()
elseif newPowerType == "RAGE" then
self:ApplyConfig("RageDruidClassic")
self:Update()
elseif newPowerType == "MANA" then
self:ApplyConfig("GeneralFSRMana")
self:Update()
else
self:Disable()
end
end
self.UNIT_DISPLAYPOWER(self)
end
}, "DRUID")
Loading

0 comments on commit ff80233

Please sign in to comment.