Version 1.1.5 (04-07-2020)

Jarth [07-04-20 - 11:30]
Version 1.1.5 (04-07-2020)
- Reverted fix in 1.1.5, and fixed issue properly by changing the load order
-- Now fetches the settings twice, first to set logging, and then set settings
- Made changes to the functions for getting and updating settings
Filename
CBs_Constants.lua
CBs_Helpers.lua
CBs_Logging.lua
CBs_Settings_Data.lua
Changelog
CollectionBars.lua
CollectionBars.txt
diff --git a/CBs_Constants.lua b/CBs_Constants.lua
index 6aed498..73e39fe 100644
--- a/CBs_Constants.lua
+++ b/CBs_Constants.lua
@@ -7,7 +7,7 @@ Filename: CBs_Constants.lua
 -------------------------------------------------------------------------------------------------
 CollectionBars = {
     WM = GetWindowManager(),
-    Addon = {Name = "CollectionBars", DisplayName = "Collection Bars", Abbreviation = "CBs", Version = 1.1, MinorVersion = 4, SettingsSlash = "/cb", Author = "Jarth"},
+    Addon = {Name = "CollectionBars", DisplayName = "Collection Bars", Abbreviation = "CBs", Version = 1.1, MinorVersion = 5, SettingsSlash = "/cb", Author = "Jarth"},
     AllButtons = {},
     Default = {
         UseAccountSettings = true,
@@ -110,10 +110,10 @@ function base:GenerateCategories()
     for _, categoryData in ZO_COLLECTIBLE_DATA_MANAGER:CategoryIterator({ZO_CollectibleCategoryData.HasShownCollectiblesInCollection}) do
         if categoryData ~= nil and categoryData:IsStandardCategory() then
             local type = base.GetType(categoryData)
-            if type ~= nil and base.CategoryHasUsableCollectible(categoryData) then
+            if type ~= nil and categoryData ~= nil and base:CategoryHasUnlockedValidAndUsableCollectible(categoryData) then
                 base.AddCategory(type, categoryData)
             else
-                if categoryData:IsTopLevelCategory() and base.SubCategoryHasUsableCollectible(categoryData) then
+                if categoryData:IsTopLevelCategory() and base:SubCategoryHasUsableCollectible(categoryData) then
                     local parentIcons = {categoryData:GetKeyboardIcons()}
                     base.AddCategory(nil, categoryData, parentIcons, true)
                     for _, subcategoryData in categoryData:SubcategoryIterator({ZO_CollectibleCategoryData.HasShownCollectiblesInCollection}) do
@@ -161,7 +161,7 @@ function base.AddCategory(type, categoryData, parentIcons, hasChildren, parentKe
         Fragment = nil
     }
     table.insert(base.CategoriesOrdered, base.Categories[categoryId])
-    base.Saved.Categories[categoryId] = {
+    base.Default.Categories[categoryId] = {
         AutoSelectAll = false,
         Selected = {},
         Enabled = false,
@@ -173,7 +173,7 @@ function base.AddCategory(type, categoryData, parentIcons, hasChildren, parentKe
     }
 end

-function base.CategoryHasUnlockedValidAndUsableCollectible(categoryData)
+function base:CategoryHasUnlockedValidAndUsableCollectible(categoryData)
     base:Debug("CategoryHasUnlockedValidAndUsableCollectible", categoryData)
     if GetTotalCollectiblesByCategoryType(categoryData:GetId()) > 0 then
         for _, collectibleData in ZO_CollectibleCategoryData.CollectibleIterator(categoryData, {ZO_CollectibleData.IsShownInCollection}) do
@@ -183,17 +183,11 @@ function base.CategoryHasUnlockedValidAndUsableCollectible(categoryData)
     return false
 end

-function base.CategoryHasUsableCollectible(categoryData)
-    base:Debug("CategoryHasUsableCollectible", categoryData)
-    if categoryData ~= nil and base.CategoryHasUnlockedValidAndUsableCollectible(categoryData) then return true end
-    return false
-end
-
-function base.SubCategoryHasUsableCollectible(categoryData)
+function base:SubCategoryHasUsableCollectible(categoryData)
     base:Debug("SubCategoryHasUsableCollectible", categoryData)
     for _, subcategoryData in categoryData:SubcategoryIterator({ZO_CollectibleCategoryData.HasShownCollectiblesInCollection}) do
         local type = base.GetType(subcategoryData)
-        if type ~= nil and subcategoryData ~= nil and base.CategoryHasUnlockedValidAndUsableCollectible(subcategoryData) then return true end
+        if type ~= nil and subcategoryData ~= nil and base:CategoryHasUnlockedValidAndUsableCollectible(subcategoryData) then return true end
     end
     return false
 end
diff --git a/CBs_Helpers.lua b/CBs_Helpers.lua
index 0d365d9..1cee689 100644
--- a/CBs_Helpers.lua
+++ b/CBs_Helpers.lua
@@ -132,32 +132,47 @@ function base:SelectAll(category, newValue)
     end
 end

-function base:SetAndUpdateAccountSettings(newUseAccountSettings)
-    base:Debug("SetAndUpdateAccountSettings", newUseAccountSettings)
-    base.Saved = ZO_SavedVars:NewAccountWide(texts.AccountKey, base.Addon.Version, nil, base.Default)
+function base:GetAccountsettings()
+    base:Debug("GetAccountsettings")
+    return ZO_SavedVars:NewAccountWide(texts.AccountKey, base.Addon.Version, nil, base.Default)
+end

-    if newUseAccountSettings ~= nil then
-        base:Debug("Update Saved.UseAccountSettings to:", newUseAccountSettings)
-        base.Saved.UseAccountSettings = newUseAccountSettings
-    end
+function base:GetCharactersettings(useAccountSettings)
+    base:Debug("GetCharactersettings", useAccountSettings)
+    local characterSettings = nil

-    local useAccountSettings = base.Saved.UseAccountSettings
     if not useAccountSettings then
-        base.Saved = ZO_SavedVars:NewCharacterNameSettings(texts.CharacterKey, base.Addon.Version, nil, base.Default)
-        base.Saved.UseAccountSettings = useAccountSettings
+        characterSettings = ZO_SavedVars:NewCharacterNameSettings(texts.CharacterKey, base.Addon.Version, nil, base.Default)
+        characterSettings.UseAccountSettings = false
     end

-    base:LogsSetEnabled()
+    return characterSettings
+end
+
+function base:SetSavedSettings()
+    base:Debug("SetSavedSettings")
+    local accountSettings = base:GetAccountsettings()
+    local characterSettings = base:GetCharactersettings(accountSettings.UseAccountSettings)
+    base.Saved = characterSettings or accountSettings
+end
+
+function base:UpdateUseAccountSettings(useAccountSettings)
+    base:Debug("UpdateUseAccountSettings", useAccountSettings)
+    local accountSettings = base:GetAccountsettings()
+    accountSettings.UseAccountSettings = useAccountSettings
+    local characterSettings = base:GetCharactersettings(accountSettings.UseAccountSettings)
+    base.Saved = characterSettings or accountSettings
 end

-function base:ResetAccountSettings()
-    base:Debug("ResetAccountSettings")
-    if base.Saved.UseAccountSettings then
+function base:ResetSavedSettings()
+    base:Debug("ResetSavedSettings")
+    local useAccountSettings = base.Saved.UseAccountSettings
+    if useAccountSettings then
         _G[texts.AccountKey] = nil
-        base.Saved = ZO_SavedVars:NewAccountWide(texts.AccountKey, base.Addon.Version, nil, base.Default)
+        base.Saved = base:GetAccountsettings()
     else
         _G[texts.CharacterKey] = nil
-        base.Saved = ZO_SavedVars:NewCharacterNameSettings(texts.CharacterKey, base.Addon.Version, nil, base.Default)
+        base.Saved = base:GetCharactersettings(useAccountSettings)
     end
 end

diff --git a/CBs_Logging.lua b/CBs_Logging.lua
index 085c485..c1fb283 100644
--- a/CBs_Logging.lua
+++ b/CBs_Logging.lua
@@ -12,17 +12,17 @@ local texts = base.Texts
 -------------------------------------------------------------------------------------------------
 -- FUNCTIONS --
 -------------------------------------------------------------------------------------------------
-function base:LogInitialize(...)
+function base:InitializeLog(...)
     if LibDebugLogger ~= nil and loggers.Logger == nil then
         loggers.Logger = LibDebugLogger(base.Addon.Name)
         loggers.Debug = loggers.Logger:Create("debug")
         loggers.Verbose = loggers.Logger:Create("verbose")
         base:Info(...)
-        base:LogsSetEnabled()
+        base:SetLogsEnabled()
     end
 end

-function base:LogsSetEnabled()
+function base:SetLogsEnabled()
     if base.Saved then
         base:LogSetEnabled(loggers.Logger, base.Saved and base.Saved.Logging.Info, "Logging")
         base:LogSetEnabled(loggers.Debug, base.Saved and base.Saved.Logging.Debug, "Logging debug")
diff --git a/CBs_Settings_Data.lua b/CBs_Settings_Data.lua
index 74ffd14..03ffde3 100644
--- a/CBs_Settings_Data.lua
+++ b/CBs_Settings_Data.lua
@@ -18,7 +18,8 @@ function base.AppendMasterListTypeGeneral(self, listType)
         tooltip = "When ON the account settings will be used. When OFF character settings will be used",
         funcGet = function() return base.Saved.UseAccountSettings end,
         funcSet = function(_, newValue)
-            base:SetAndUpdateAccountSettings(newValue)
+            base:UpdateUseAccountSettings(newValue)
+            base:SetLogsEnabled()
             base:InitializeWithSavedData()
             base:RestoreFrames()
             base:RestoreCombineLabels()
@@ -26,7 +27,7 @@ function base.AppendMasterListTypeGeneral(self, listType)
         end
     })
     self:AppendRow_Button(listType, {
-        name = "Remove character settings",
+        name = "Remove all character settings",
         buttonName = "Remove",
         disabledFunc = base.GetCharacterSettingsDisabledState,
         funcSet = function()
@@ -38,8 +39,8 @@ function base.AppendMasterListTypeGeneral(self, listType)
         name = "Reset settings",
         buttonName = "Reset",
         funcSet = function()
-            base:ResetAccountSettings()
-            base:SetAndUpdateAccountSettings()
+            base:ResetSavedSettings()
+            base:SetLogsEnabled()
             base:InitializeWithSavedData()
             base:RestoreFrames()
             base:RestoreCombineLabels()
@@ -187,7 +188,7 @@ function base.AppendMasterListTypeGeneral(self, listType)
             if not newValue then base.Saved.Logging.Debug = newValue end
             if not newValue then base.Saved.Logging.Verbose = newValue end
             base.Global.Settings.List:RefreshData()
-            base:LogsSetEnabled()
+            base:SetLogsEnabled()
         end
     })
     self:AppendRow_Checkbox(listType, {
diff --git a/Changelog b/Changelog
index 800c4dd..c98be38 100644
--- a/Changelog
+++ b/Changelog
@@ -1,6 +1,11 @@
 -------------------------------------------------------------------------------
  Collection bars
 -------------------------------------------------------------------------------
+Version 1.1.5 (04-07-2020)
+- Reverted fix in 1.1.5, and fixed issue properly by changing the load order
+-- Now fetches the settings twice, first to set logging, and then set settings
+- Made changes to the functions for getting and updating settings
+
 Version 1.1.4 (04-07-2020)
 - Fixed issue where category saved data would not be accessible

diff --git a/CollectionBars.lua b/CollectionBars.lua
index 25dde6e..ef22d25 100644
--- a/CollectionBars.lua
+++ b/CollectionBars.lua
@@ -13,10 +13,12 @@ local texts = base.Texts
 -------------------------------------------------------------------------------------------------

 function base.OnAddOnLoaded(_, addonName)
-    base:LogInitialize("OnAddOnLoaded", addonName)
+    base:InitializeLog("OnAddOnLoaded", addonName)
     if addonName == base.Addon.Name then
-        base:SetAndUpdateAccountSettings()
+        base:SetSavedSettings() -- Incomplete saved settings - For SetLogsEnabled
+        base:SetLogsEnabled()
         base:GenerateCategories()
+        base:SetSavedSettings() -- Complete saved settings
         base:InitializeReverseBinding()
         base:InitializeCombineFrame()
         base:InitializeWithSavedData()
diff --git a/CollectionBars.txt b/CollectionBars.txt
index 67288e5..86fe02e 100644
--- a/CollectionBars.txt
+++ b/CollectionBars.txt
@@ -6,8 +6,8 @@

 ## APIVersion: 100031
 ## Title: Collection Bars
-## AddOnVersion: 10104
-## Version: 1.1.4
+## AddOnVersion: 10105
+## Version: 1.1.5
 ## Author: Jarth
 ## Description: Show collection bars and activate collections with key or button press. Shortcuts: Settings window: /cb OptionalDependsOn: LibDebugLogger (Logging can be enabled in settings)
 ##