Thread: AceDB Resetting
View Single Post
08-08-16, 04:39 PM   #19
MilleXIV
A Deviate Faerie Dragon
 
MilleXIV's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2016
Posts: 16
So I've been running at this thing with the following script in WoWLua:

Lua Code:
  1. print('--------------------------------------------------')
  2. local xb = LibStub('AceAddon-3.0'):GetAddon('XIV_Databar')
  3. --local mmm = xb:GetModule('MenuModule')
  4.  
  5. function printTable(table, prefix)
  6.    for k,v in pairs(table) do
  7.       if type(v) == 'table' then
  8.          printTable(v, prefix..'.'..k)
  9.       else
  10.          print(prefix..'.'..k..': '..tostring(v))
  11.       end
  12.    end
  13. end
  14. printTable(xb.db, 'db')

Then stripped my addon down to as basic as I could. My OnInit only does AceDB:New, LSM:Register, self.frames = {}, sets up an options table (statically), then registers the options frame, and a slash command. My OnEnable has been set to just return.

If I run that after loading into the game it's completely missing self.db.profile. After I load up my config it fills in self.db.profile with my defaults.

The full OnInit/OnEnable/ToggleConfig:

Lua Code:
  1. function XIVBar:OnInitialize()
  2.   self.db = LibStub("AceDB-3.0"):New("XIVBarDB", self.defaults)
  3.   self.LSM:Register(self.LSM.MediaType.FONT, 'Homizio Bold', self.constants.mediaPath.."homizio_bold.ttf")
  4.   self.frames = {}
  5.  
  6.   local options = {
  7.     name = "XIV Bar",
  8.     handler = XIVBar,
  9.     type = 'group',
  10.     args = {
  11.       general = {
  12.         name = L['General'],
  13.         type = "group",
  14.         order = 3,
  15.         inline = true,
  16.         args = {
  17.           barPosition = {
  18.             name = L['Bar Position'],
  19.             type = "select",
  20.             order = 1,
  21.             values = {TOP = L['Top'], BOTTOM = L['Bottom']},
  22.             style = "dropdown",
  23.             get = function() return self.db.profile.general.barPosition; end,
  24.             set = function(info, value) self.db.profile.general.barPosition = value; self:Refresh(); end,
  25.           },
  26.           barColor = {
  27.             name = L['Bar Color'],
  28.             type = "color",
  29.             order = 2,
  30.             hasAlpha = true,
  31.             set = function(info, r, g, b, a)
  32.               XIVBar:SetColor('barColor', r, g, b, a)
  33.             end,
  34.             get = function() return XIVBar:GetColor('barColor') end
  35.           },
  36.         }
  37.       }
  38.     }
  39.   }
  40.  
  41.   options.args.profiles = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
  42.   options.args.profiles.order = 90
  43.  
  44.   LibStub("AceConfig-3.0"):RegisterOptionsTable(AddOnName, options)
  45.   self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions(AddOnName, "XIV Bar")
  46.  
  47.   self:RegisterChatCommand('xivbar', 'ToggleConfig')
  48. end
  49.  
  50. function XIVBar:OnEnable() return; end
  51.  
  52. function XIVBar:ToggleConfig()
  53.   InterfaceOptionsFrame_OpenToCategory(self.optionsFrame)
  54. end
  Reply With Quote