Thread Tools Display Modes
10-22-23, 02:04 PM   #1
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Ace3 - reset a namespace DB to default?

Reading through the docs of AceDB-3.0, I see that namespaces are considered full databases except that they cannot control their options, a parent addon does that. All is well and good, although when I reset the profile in the main addon, the module's options do not reset at the same time.

I am missing something, but I don't know what. Attached is the full zip of the addon in progress, which includes the module code. When I look at the SV file, I see the namespace "Chat". Nothing appears in there; any changes appear under profiles - default, and I'm getting confused.

Am I adding the module options correctly? How do I reset the module back to the namespace defaults when I reset the profile?
Attached Files
File Type: zip SmartRes2.zip (772.7 KB, 48 views)
  Reply With Quote
10-29-23, 02:07 AM   #2
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
This still doesn't make any sense to me. I see no API to register module options; I do see two to register module defaults. When I try to register the module options, I get the error telling me that the module is already registered, presumably when I registered the namespace. How then do I assign the options? Is this done with AceConfig, with appName being the module name? If that is true, which I'm not sure about, will doing so merge the module options with the core options?

addon is defined in the core file, and module is defined in the module file. This chunk is from the core file.
Lua Code:
  1. -- functions to register module options and check if a module is registered
  2. local moduleOrder = 100
  3. function addon:RegisterModuleOptions(moduleName, optionsTable)
  4.     if options.args[moduleName] == nil then
  5.         options.args[moduleName] = optionsTable
  6.         options.args[moduleName].order = moduleOrder
  7.         options.args[moduleName].name = optionsTable and optionsTable.name or moduleName
  8.         moduleOrder = moduleOrder + 10
  9.     else
  10.         error(moduleName .. " is already registered", 2)
  11.     end
  12. end
  13.  
  14. function addon:IsModuleAlreadyRegistered(moduleName)
  15.     return options.args[moduleName] and true or false
  16. end

This chunk is in the module file.
Lua Code:
  1. function module:OnInitialize()
  2.     self.db = addon.db:RegisterNamespace("Chat", defaults)
  3.     db = self.db.profile
  4.     self:SetEnabledState(db.enabled)
  5.  
  6.     local options = self:GetOptions()
  7.     addon:RegisterModuleOptions("Chat", options)
  8. end

And after all of that, how do I reset the module when the profile is reset via the core file?
  Reply With Quote
10-30-23, 12:04 PM   #3
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
I have tried every idea that I can think of, and am still stuck. I am getting the following error, which I cannot decipher.
Lua Code:
  1. 2x ...nfig-3.0/AceConfigDialog-3.0-86/AceConfigDialog-3.0.lua:1854: AceConfigRegistry-3.0-21:ValidateOptionsTable(): SmartRes2.args.modules.Chat: unknown parameter
  2. [string "=[C]"]: ?
  3. [string "@Ace3/AceConfig-3.0-3/AceConfigRegistry-3.0-21/AceConfigRegistry-3.0.lua"]:50: in function <...-3.0/AceConfigRegistry-3.0/AceConfigRegistry-3.0.lua:45>
  4. [string "@Ace3/AceConfig-3.0-3/AceConfigRegistry-3.0-21/AceConfigRegistry-3.0.lua"]:239: in function <...-3.0/AceConfigRegistry-3.0/AceConfigRegistry-3.0.lua:220>
  5. [string "@Ace3/AceConfig-3.0-3/AceConfigRegistry-3.0-21/AceConfigRegistry-3.0.lua"]:255: in function <...-3.0/AceConfigRegistry-3.0/AceConfigRegistry-3.0.lua:220>
  6. [string "@Ace3/AceConfig-3.0-3/AceConfigRegistry-3.0-21/AceConfigRegistry-3.0.lua"]:283: in function `ValidateOptionsTable'
  7. [string "@Ace3/AceConfig-3.0-3/AceConfigRegistry-3.0-21/AceConfigRegistry-3.0.lua"]:325: in function `app'
  8. [string "@Ace3/AceConfig-3.0-3/AceConfigDialog-3.0-86/AceConfigDialog-3.0.lua"]:1854: in function `Open'
  9. [string "@SmartRes2/Core.lua"]:74: in function <SmartRes2/Core.lua:70>
  10. [string "@SmartRes2/Core.lua"]:134: in function <SmartRes2/Core.lua:128>
  11. [string "@Titan/TitanLDB.lua"]:298: in function <Titan/TitanLDB.lua:296>
  12.  
  13. Locals:
  14. (*temporary) = "AceConfigRegistry-3.0:ValidateOptionsTable(): SmartRes2.args.modules.Chat: unknown parameter"
My latest code push is on GitHub: https://github.com/Myrroddin/smartres2 I figure it is easier to read there than to download a zip.

Besides the error, some things do not make sense to me. I have looked at Skada and its modules for inspiration, yet things are going sideways.
  • How are the namespace and options table tied together, at least for a module?
  • Is my method to add the module options to the main options correct?
  • Will I be forced to make the module its own addon with its own SVs?
  • Am I referencing addon.db correctly in the module to set options? IE: the db shorthand?
  • Does resetting the profile also reset the module's options back to its defaults?
  • Why does a namespace need a profile table if namespaces cannot control their own profiles? IE: moduleDefaults.profile.enabled instead of simply moduleDefaults.enabled?

Last edited by myrroddin : 10-30-23 at 12:07 PM. Reason: Clarify a question
  Reply With Quote
11-01-23, 11:05 AM   #4
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
After throwing enough darts blindly, I got it working. https://github.com/Myrroddin/smartres2 Now to break it again by adding more options!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Ace3 - reset a namespace DB to default?


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off