Skip to content

Commit

Permalink
Add a db check in some places
Browse files Browse the repository at this point in the history
  • Loading branch information
Lardeck committed Feb 9, 2023
1 parent f0c272e commit 2eb8aa5
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion ImprovedTalentLoadouts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ local function GetPlayerName()
end

function TalentLoadouts:Initialize()
-- Will be removed in a future version. Necessary because of a rename of the AddOn
ImprovedTalentLoadoutsDB = ImprovedTalentLoadoutsDB or TalentLoadoutProfilesDB or defaultDB
if not ImprovedTalentLoadoutsDB.classesInitialized then
self:InitializeClassDBs()
Expand Down Expand Up @@ -122,6 +121,24 @@ function TalentLoadouts:InitializeCharacterDB()
self:UpdateMacros()
end

-- Not sure how that can happen but apparently it was a problem for someone
function TalentLoadouts:CheckDBIntegrity()
ImprovedTalentLoadoutsDB.loadouts = ImprovedTalentLoadoutsDB.loadouts or {globalLoadouts = {}, characterLoadouts = {}}
ImprovedTalentLoadoutsDB.loadouts.globalLoadouts = ImprovedTalentLoadoutsDB.loadouts.globalLoadouts or {}
ImprovedTalentLoadoutsDB.loadouts.characterLoadouts = ImprovedTalentLoadoutsDB.loadouts.characterLoadouts or {}

if not self.globalDB then
ImprovedTalentLoadoutsDB.classesInitialized = nil
self:Initialize()
self.globalDB = ImprovedTalentLoadoutsDB.loadouts.globalLoadouts[UnitClassBase("player")]
end

if not self.charDB then
local playerName = GetPlayerName()
self.charDB = ImprovedTalentLoadoutsDB.loadouts.characterLoadouts[playerName]
end
end

function TalentLoadouts:CheckForDBUpdates()
if ImprovedTalentLoadoutsDB.applyLoadout == nil then
ImprovedTalentLoadoutsDB.applyLoadout = true
Expand Down Expand Up @@ -176,6 +193,10 @@ local function CreateExportString(configInfo, configID, specID, skipEntryInfo)
end

function TalentLoadouts:InitializeTalentLoadouts()
if not self.globalDB or not self.charDB then
self:CheckDBIntegrity()
end

local specConfigIDs = self.globalDB.configIDs
local currentSpecID = self.specID
if specConfigIDs[currentSpecID] then
Expand Down Expand Up @@ -239,6 +260,10 @@ function TalentLoadouts:SaveLoadout(configID, currentSpecID)
end

function TalentLoadouts:SaveCurrentLoadouts()
if not self.globalDB or not self.charDB then
self:CheckDBIntegrity()
end

local firstLoad = self.charDB.firstLoad
if self.charDB.firstLoad then
for specIndex=1, GetNumSpecializations() do
Expand Down

0 comments on commit 2eb8aa5

Please sign in to comment.