Skip to content

Commit

Permalink
fixes to make luacheck happier
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuller committed Sep 3, 2018
1 parent e81d6b7 commit f2d7cc5
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 65 deletions.
19 changes: 9 additions & 10 deletions Dominos_Progress/config.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
local AddonName, Addon = ...
local Dominos = LibStub('AceAddon-3.0'):GetAddon('Dominos')
local _, Addon = ...
local Dominos = LibStub("AceAddon-3.0"):GetAddon("Dominos")
local ConfigVersion = 1

local Config = {}

function Config:Init()
local db = Dominos.db:RegisterNamespace('ProgressBars', self:GetDefaults())
local db = Dominos.db:RegisterNamespace("ProgressBars", self:GetDefaults())

if db.global.version ~= ConfigVersion then
db.global.version = ConfigVersion
Expand All @@ -15,10 +15,9 @@ function Config:Init()
end

function Config:GetDefaults()
return {
return {
profile = {
one_bar = false,

one_bar = false,
colors = {
xp = {0.58, 0, 0.55, 1},
xp_bonus = {0, 0.39, 0.88},
Expand All @@ -32,17 +31,17 @@ function Config:GetDefaults()
end

function Config:SetOneBarMode(enable)
self.db.profile.one_bar = enable or false
self.db.profile.one_bar = enable or false
end

function Config:OneBarMode()
return self.db.profile.one_bar
return self.db.profile.one_bar
end

function Config:SetColor(key, ...)
local color = self.db.profile.colors[key]

for i = 1, select('#', ...) do
for i = 1, select("#", ...) do
color[i] = select(i, ...)
end
end
Expand All @@ -52,4 +51,4 @@ function Config:GetColor(key)
end

-- exports
Addon.Config = Config
Addon.Config = Config
2 changes: 1 addition & 1 deletion Dominos_Progress/honorBar.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local Addon = select(2, ...)
local _, Addon = ...
local Dominos = _G.Dominos
local HonorBar = Dominos:CreateClass('Frame', Addon.ProgressBar)

Expand Down
67 changes: 32 additions & 35 deletions Dominos_Progress/main.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
--[[
the main controller of dominos progress
--]]

local AddonName, Addon = ...
local Dominos = LibStub('AceAddon-3.0'):GetAddon('Dominos')
local ProgressBarModule = Dominos:NewModule('ProgressBars', 'AceEvent-3.0')
local L = LibStub('AceLocale-3.0'):GetLocale('Dominos-Progress')
local ConfigVersion = 1
local _, Addon = ...
local Dominos = LibStub("AceAddon-3.0"):GetAddon("Dominos")
local ProgressBarModule = Dominos:NewModule("ProgressBars", "AceEvent-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale("Dominos-Progress")

function ProgressBarModule:OnInitialize()
Addon.Config:Init()
Expand All @@ -15,38 +13,38 @@ end
function ProgressBarModule:Load()
if Addon.Config:OneBarMode() then
self.bars = {
Addon.ExperienceBar:New('exp', { 'xp', 'reputation', 'honor', 'artifact', 'azerite' }),
Addon.ExperienceBar:New("exp", {"xp", "reputation", "honor", "artifact", "azerite"})
}
else
self.bars = {
Addon.ExperienceBar:New('exp', { 'xp', 'reputation', 'honor' }),
Addon.ArtifactBar:New('artifact', { 'artifact', 'azerite' })
Addon.ExperienceBar:New("exp", {"xp", "reputation", "honor"}),
Addon.ArtifactBar:New("artifact", {"artifact", "azerite"})
}
end

-- common events
self:RegisterEvent('PLAYER_ENTERING_WORLD')
self:RegisterEvent('UPDATE_EXHAUSTION')
self:RegisterEvent('PLAYER_UPDATE_RESTING')
self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:RegisterEvent("UPDATE_EXHAUSTION")
self:RegisterEvent("PLAYER_UPDATE_RESTING")

-- xp bar events
self:RegisterEvent('PLAYER_XP_UPDATE')
self:RegisterEvent("PLAYER_XP_UPDATE")

-- reputation events
self:RegisterEvent('UPDATE_FACTION')
self:RegisterEvent("UPDATE_FACTION")

-- honor events
self:RegisterEvent('HONOR_XP_UPDATE')
self:RegisterEvent('HONOR_LEVEL_UPDATE')
self:RegisterEvent("HONOR_XP_UPDATE")
self:RegisterEvent("HONOR_LEVEL_UPDATE")

-- artifact events
self:RegisterEvent('ARTIFACT_XP_UPDATE')
self:RegisterEvent('UNIT_INVENTORY_CHANGED')
self:RegisterEvent("ARTIFACT_XP_UPDATE")
self:RegisterEvent("UNIT_INVENTORY_CHANGED")

-- azerite events
self:RegisterEvent('AZERITE_ITEM_EXPERIENCE_CHANGED')
self:RegisterEvent("AZERITE_ITEM_EXPERIENCE_CHANGED")

self:RegisterEvent('ADDON_LOADED')
self:RegisterEvent("ADDON_LOADED")
end

function ProgressBarModule:UpdateAllBars()
Expand All @@ -57,15 +55,13 @@ function ProgressBarModule:UpdateAllBars()
end

function ProgressBarModule:Unload()
for i, bar in pairs(self.bars) do
for _, bar in pairs(self.bars) do
bar:Free()
end

self.bars = {}
end

--[[ events ]]--

function ProgressBarModule:PLAYER_ENTERING_WORLD()
self:UpdateAllBars()
end
Expand Down Expand Up @@ -95,7 +91,9 @@ function ProgressBarModule:AZERITE_ITEM_EXPERIENCE_CHANGED()
end

function ProgressBarModule:UNIT_INVENTORY_CHANGED(event, unit)
if unit ~= 'player' then return end
if unit ~= "player" then
return
end

self:UpdateAllBars()
end
Expand All @@ -109,17 +107,17 @@ function ProgressBarModule:HONOR_LEVEL_UPDATE()
end

function ProgressBarModule:ADDON_LOADED(event, addonName)
if addonName == 'Dominos_Config' then
if addonName == "Dominos_Config" then
self:AddOptionsPanel()
self:UnregisterEvent('ADDON_LOADED')
self:UnregisterEvent("ADDON_LOADED")
end
end

function ProgressBarModule:AddOptionsPanel()
local panel = Dominos.Options.AddonOptions:NewPanel(L.Progress)
local prev = nil

local oneBarModeToggle = panel:Add('CheckButton', {
local oneBarModeToggle = panel:Add("CheckButton", {
name = L.OneBarMode,

get = function()
Expand All @@ -133,12 +131,11 @@ function ProgressBarModule:AddOptionsPanel()
end
})

oneBarModeToggle:SetPoint('TOPLEFT', 0, -2)

for i, key in ipairs{'xp', 'xp_bonus', 'honor', 'artifact', 'azerite'} do
oneBarModeToggle:SetPoint("TOPLEFT", 0, -2)

local picker = panel:Add('ColorPicker', {
name = L['Color_' .. key],
for _, key in ipairs {"xp", "xp_bonus", "honor", "artifact", "azerite"} do
local picker = panel:Add("ColorPicker", {
name = L["Color_" .. key],

hasOpacity = true,

Expand All @@ -149,13 +146,13 @@ function ProgressBarModule:AddOptionsPanel()
set = function(...)
Addon.Config:SetColor(key, ...)

for i, bar in pairs(self.bars) do
for _, bar in pairs(self.bars) do
bar:Init()
end
end
})

picker:SetPoint('TOP', prev or oneBarModeToggle, 'BOTTOM', 0, -6)
picker:SetPoint("TOP", prev or oneBarModeToggle, "BOTTOM", 0, -6)
prev = picker
end
end
end
39 changes: 25 additions & 14 deletions Dominos_Progress/progressBar.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local AddonName, Addon = ...
local _, Addon = ...
local Dominos = LibStub('AceAddon-3.0'):GetAddon('Dominos')
local ProgressBar = Dominos:CreateClass('Frame', Dominos.ButtonBar)

Expand Down Expand Up @@ -242,20 +242,22 @@ function ProgressBar:SetValues(value, max, bonus)
local valueChanged = false

local maxChanged = false
local max = math.max(tonumber(max) or 0, 1)

max = math.max(tonumber(max) or 0, 1)
if self.max ~= max then
self.max = max
maxChanged = true
end

local value = math.min(math.max(tonumber(value) or 0, 0), max)
value = math.min(math.max(tonumber(value) or 0, 0), max)
if self.value ~= value then
self.value = value
valueChanged = true
end

local bonusChanged = false
local bonus = tonumber(bonus) or 0

bonus = tonumber(bonus) or 0
if self.bonus ~= bonus then
self.bonus = bonus
bonusChanged = true
Expand Down Expand Up @@ -297,7 +299,8 @@ end

function ProgressBar:UpdateBonusValue()
local value, max, bonus = self:GetValues()
local bonus = bonus > 0 and math.min(value + bonus, max) or bonus

bonus = bonus > 0 and math.min(value + bonus, max) or bonus

local segmentValue = max / self:GetSegmentCount()
local lastFilledIndex = floor(bonus / segmentValue)
Expand Down Expand Up @@ -343,13 +346,17 @@ function ProgressBar:SetColor(r, g, b, a)
colors[3] = tonumber(b) or 0
colors[4] = tonumber(a) or 1

self:UpdateColor()
return self
end

function ProgressBar:UpdateColor()
local r, g, b, a = self:GetColor()
for i, bar in pairs(self.buttons) do

for _, bar in pairs(self.buttons) do
bar.bg:SetVertexColor(r / 2, g / 2, b / 2, a / 2)
bar.value:SetStatusBarColor(r, g, b, a)
end

return self
end

function ProgressBar:GetColor()
Expand All @@ -366,12 +373,16 @@ function ProgressBar:SetBonusColor(r, g, b, a)
colors[3] = tonumber(b) or 0
colors[4] = tonumber(a) or 1

self:UpdateBonusColor()
return self
end

function ProgressBar:UpdateBonusColor()
local r, g, b, a = self:GetBonusColor()
for i, bar in pairs(self.buttons) do

for _, bar in pairs(self.buttons) do
bar.bonus:SetStatusBarColor(r, g, b, a)
end

return self
end

function ProgressBar:GetBonusColor()
Expand Down Expand Up @@ -424,7 +435,7 @@ end
--[[ segments ]]--

function ProgressBar:SetSegmentCount(count)
local count = tonumber(count) or 1
count = tonumber(count) or 1

if count ~= self:GetSegmentCount() then
self:SetNumButtons(count)
Expand Down Expand Up @@ -487,7 +498,7 @@ end
function ProgressBar:UpdateTexture()
local texture = LibStub('LibSharedMedia-3.0'):Fetch('statusbar', self:GetTextureID())

for i, segment in pairs(self.buttons) do
for _, segment in pairs(self.buttons) do
segment.bg:SetTexture(texture)
segment.value:SetStatusBarTexture(texture)
segment.bonus:SetStatusBarTexture(texture)
Expand Down Expand Up @@ -571,7 +582,7 @@ end
function ProgressBar:Layout()
local width, height = self:GetSegmentSize()

for i, segment in pairs(self.buttons) do
for _, segment in pairs(self.buttons) do
segment:SetSize(width, height)
end

Expand Down
9 changes: 4 additions & 5 deletions Dominos_Progress/reputationBar.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
local AddonName, Addon = ...
local _, Addon = ...
local Dominos = _G.Dominos
local ReputationBar = Dominos:CreateClass('Frame', Addon.ProgressBar)
local L = LibStub('AceLocale-3.0'):GetLocale('Dominos-Progress')
local FRIEND_FACTION_COLOR_INDEX = 5
local PARAGON_FACTION_COLOR_INDEX = #FACTION_BAR_COLORS
local MAX_REPUTATION_REACTION = _G.MAX_REPUTATION_REACTION
Expand All @@ -23,14 +22,14 @@ function ReputationBar:Update()
local description, colorIndex, capped

if C_Reputation.IsFactionParagon(factionID) then
local currentValue, threshold, rewardQuestID, hasRewardPending = C_Reputation.GetFactionParagonInfo(factionID)
local currentValue, threshold = C_Reputation.GetFactionParagonInfo(factionID)
min, max, value = 0, threshold, currentValue % threshold

colorIndex = PARAGON_FACTION_COLOR_INDEX
description = GetText('FACTION_STANDING_LABEL'..reaction, UnitSex('player'))
capped = false
else
local friendID, friendRep, friendMaxRep, friendName, friendText, friendTexture, friendTextLevel, friendThreshold, nextFriendThreshold = GetFriendshipReputation(factionID)
local friendID, friendRep, _, _, _, _, friendTextLevel, friendThreshold, nextFriendThreshold = GetFriendshipReputation(factionID)
if friendID then
if nextFriendThreshold then
min, max, value = friendThreshold, nextFriendThreshold, friendRep
Expand All @@ -55,7 +54,7 @@ function ReputationBar:Update()
max = max - min
value = value - min

local color = FACTION_BAR_COLORS[reaction]
local color = FACTION_BAR_COLORS[colorIndex]
self:SetColor(color.r, color.g, color.b)
self:SetValues(value, max)
self:UpdateText(name, value, max, description, capped)
Expand Down

0 comments on commit f2d7cc5

Please sign in to comment.