Skip to content

Commit

Permalink
Cleanup and Nil Catch
Browse files Browse the repository at this point in the history
  • Loading branch information
CuteOne committed May 10, 2024
1 parent 8e383af commit 1c7ea54
Showing 1 changed file with 54 additions and 45 deletions.
99 changes: 54 additions & 45 deletions BadRotations.lua
@@ -1,12 +1,13 @@
-- [[ Global Variables and Tables Initialization ]] --
-- define br global that will hold the bot global background features
local _, br = ...
br._G = setmetatable({}, {__index = _G})
br._G = setmetatable({}, { __index = _G })
br.unlock = {}
br.data = {}
br.data.settings = {}
br.addonName = "BadRotations"
br.castPosition = {x = 0, y = 0, z = 0}
br.auraMaxStacks = {}
br.castPosition = { x = 0, y = 0, z = 0 }
br.commandHelp = {}
br.deadPet = false
-- developers debug, use /run br.data.settings[br.selectedSpec].toggles["isDebugging"] = true
Expand All @@ -24,7 +25,7 @@ br.dropOptions.Toggle = {
"Mouse4",
"Mouse5"
}
br.dropOptions.CD = {"Never", "CDs", "Always"}
br.dropOptions.CD = { "Never", "CDs", "Always" }
br.engines = {}
br.loadedIn = false
br.loadFile = false
Expand All @@ -43,19 +44,19 @@ br.unlocker = "None"
-- [[ Class Colors Definition ]] --
-- The colors Duke, the colors!
br.classColors = {
[1] = {class = "Warrior", B = 0.43, G = 0.61, R = 0.78, hex = "c79c6e"},
[2] = {class = "Paladin", B = 0.73, G = 0.55, R = 0.96, hex = "f58cba"},
[3] = {class = "Hunter", B = 0.45, G = 0.83, R = 0.67, hex = "abd473"},
[4] = {class = "Rogue", B = 0.41, G = 0.96, R = 1, hex = "fff569"},
[5] = {class = "Priest", B = 1, G = 1, R = 1, hex = "ffffff"},
[6] = {class = "Deathknight", B = 0.23, G = 0.12, R = 0.77, hex = "c41f3b"},
[7] = {class = "Shaman", B = 0.87, G = 0.44, R = 0, hex = "0070de"},
[8] = {class = "Mage", B = 0.94, G = 0.8, R = 0.41, hex = "69ccf0"},
[9] = {class = "Warlock", B = 0.79, G = 0.51, R = 0.58, hex = "9482c9"},
[10] = {class = "Monk", B = 0.59, G = 1, R = 0, hex = "00ff96"},
[11] = {class = "Druid", B = 0.04, G = 0.49, R = 1, hex = "ff7d0a"},
[12] = {class = "Demonhunter", B = 0.79, G = 0.19, R = 0.64, hex = "a330c9"},
[13] = {class = "Evoker", B = 0.50, G = 0.58, R = 0.20, hex = "33937f"}
[1] = { class = "Warrior", B = 0.43, G = 0.61, R = 0.78, hex = "c79c6e" },
[2] = { class = "Paladin", B = 0.73, G = 0.55, R = 0.96, hex = "f58cba" },
[3] = { class = "Hunter", B = 0.45, G = 0.83, R = 0.67, hex = "abd473" },
[4] = { class = "Rogue", B = 0.41, G = 0.96, R = 1, hex = "fff569" },
[5] = { class = "Priest", B = 1, G = 1, R = 1, hex = "ffffff" },
[6] = { class = "Deathknight", B = 0.23, G = 0.12, R = 0.77, hex = "c41f3b" },
[7] = { class = "Shaman", B = 0.87, G = 0.44, R = 0, hex = "0070de" },
[8] = { class = "Mage", B = 0.94, G = 0.8, R = 0.41, hex = "69ccf0" },
[9] = { class = "Warlock", B = 0.79, G = 0.51, R = 0.58, hex = "9482c9" },
[10] = { class = "Monk", B = 0.59, G = 1, R = 0, hex = "00ff96" },
[11] = { class = "Druid", B = 0.04, G = 0.49, R = 1, hex = "ff7d0a" },
[12] = { class = "Demonhunter", B = 0.79, G = 0.19, R = 0.64, hex = "a330c9" },
[13] = { class = "Evoker", B = 0.50, G = 0.58, R = 0.20, hex = "33937f" }
}
br.classColor = tostring("|cff" .. br.classColors[select(3, br._G.UnitClass("player"))].hex)
br.qualityColors = {
Expand All @@ -81,6 +82,7 @@ function br.debugPrint(message)
br._G.print(message)
end
end

-- Run
function br.Run()
if br.selectedSpec == nil then
Expand Down Expand Up @@ -108,6 +110,7 @@ function br.Run()
br.loadedIn = true
end
end

-- Default Settings
function br.defaultSettings()
br._G.C_Timer.After(
Expand Down Expand Up @@ -159,6 +162,7 @@ function br.defaultSettings()
}
end
end

-- Load Saved Settings
function br.loadSavedSettings()
if br.initializeSettings then
Expand All @@ -170,16 +174,21 @@ function br.loadSavedSettings()
elseif br.rotations[br.selectedSpec] then
br:loadSettings(nil, nil, nil, br.rotations[br.selectedSpec][1].name)
else
if not br.rotations[br.selectedSpec] then br.initializeSettings = false return end
if not br.rotations[br.selectedSpec] then
br.initializeSettings = false
return
end
end
br.defaultSettings()
-- Build the Toggles
br.TogglesFrame()
-- Restore Minimap Button Position
br.BadRotationsButton:SetPoint("CENTER", br.data.settings.minimapButton.pos.x, br.data.settings.minimapButton.pos.y)
br.BadRotationsButton:SetPoint("CENTER", br.data.settings.minimapButton.pos.x,
br.data.settings.minimapButton.pos.y)
br.initializeSettings = false
end
end

function br.load()
-- Update Selected Spec
br.selectedSpecID, br.selectedSpec = br._G.GetSpecializationInfo(br._G.GetSpecialization())
Expand Down Expand Up @@ -227,33 +236,33 @@ frame:RegisterEvent("LOADING_SCREEN_DISABLED")

-- Separate OnEvent function
local function OnEvent(self, event)
if event == "LOADING_SCREEN_ENABLED" then
br.disablePulse = true
end
if event == "LOADING_SCREEN_DISABLED" then
br.disablePulse = false
end
if event == "PLAYER_LOGOUT" then
if br.unlocked then
-- Return queue window to previous setting
if br._G.C_CVar.GetCVar("SpellQueueWindow") == "0" then
br._G.RunMacroText("/console SpellQueueWindow " .. br.prevQueueWindow)
end
br.ui:saveWindowPosition()
if br.getOptionCheck("Reset Options") then
-- Reset Settings
br:saveSettings(nil, nil, br.selectedSpec, br.selectedProfileName, true)
else
-- Save Settings
br:saveSettings(nil, nil, br.selectedSpec, br.selectedProfileName)
end
br.saveLastProfileTracker()
end
end
if event == "PLAYER_ENTERING_WORLD" then
br.load()
end
if event == "LOADING_SCREEN_ENABLED" then
br.disablePulse = true
end
if event == "LOADING_SCREEN_DISABLED" then
br.disablePulse = false
end
if event == "PLAYER_LOGOUT" then
if br.unlocked then
-- Return queue window to previous setting
if br._G.C_CVar.GetCVar("SpellQueueWindow") == "0" then
br._G.RunMacroText("/console SpellQueueWindow " .. br.prevQueueWindow)
end
br.ui:saveWindowPosition()
if br.getOptionCheck("Reset Options") then
-- Reset Settings
br:saveSettings(nil, nil, br.selectedSpec, br.selectedProfileName, true)
else
-- Save Settings
br:saveSettings(nil, nil, br.selectedSpec, br.selectedProfileName)
end
br.saveLastProfileTracker()
end
end
if event == "PLAYER_ENTERING_WORLD" then
br.load()
end
end

-- Setting the OnEvent script handler
frame:SetScript("OnEvent", OnEvent)
frame:SetScript("OnEvent", OnEvent)

0 comments on commit 1c7ea54

Please sign in to comment.