LibModuleDBShare-1.0 provides a shared profile manager for addons without a central core.
Including LibModuleDBShare in your project
Using a repository
- Set an external pointing to http://hg.curseforge.net/wow/libmoduledbshare-1-0/mainline/LibModuleDBShare-1.0
- In your <addon>.toc or embeds.xml file, load the LibModuleDBShare.xml file.
Manually
- Download the latest version of the library.
- Copy the LibModuleDBShare-1.0 subfolder into your Libs folder.
- In your <addon>.toc or embeds.xml file, load the LibModuleDBShare.xml file.
Using LibModuleDBShare
Dependencies
LibModuleDBShare-1.0 requires the following libraries:
- AceDB-3.0
- AceDBOptions-3.0
- AceConfigRegistry-3.0
- AceConfigDialog-3.0
- CallbackHandler-1.0 is required by AceDB-3.0 and AceConfigRegistry-3.0
- AceGUI-3.0 is required by AceConfigDialog-3.0
- LibDualSpec-1.0 is not required, but cannot be used if absent
Creating your group
In each module of your addon, create your database as normal. Then, check to see if the group exists. If it does, add your database, otherwise create it.
localdatabase;-- this function is called after the ADDON_LOADED event fireslocalgroup;functioninitializeDB()database=LibStub("AceDB-3.0"):New("MyAddonDB",defaults,true);group=LibStub("LibModuleDBShare-1.0"):GetGroup("Group Name");ifnotgroupthengroup=LibStub("LibModuleDBShare-1.0"):NewGroup("Group Name","A description for this group.",database);elsegroup:AddDB(database);endend
Options Panels
With each group that LibModuleDBShare manages, it creates an interface options panel in the Bilzzard options frame. This panel displays the description of your addon, supplied when creating your group, has the same name as your group, and has a profiles management subpanel. While not required by the library, putting your modules' options panels here keeps your addon's options in one place.
localmyOptionsTable;-- assume this to be defined-- this function is called after the group is createdfunctionaddOptionsToBlizzPanel()LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable("MyModuleName",myOptionsTable);LibStub("AceConfigDialog-3.0"):AddToBlizOptions("MyModuleName","Module Name","Group Name");-- third argument is the name of the parentend
LibDualSpec integration
If the usesDualSpec
parameter of the :NewGroup
method is set to true
when creating the group, the group profile manager will include options for setting up an alternate profile, just like any other database that uses LibDualSpec. There is no need to enhance the individual databases of member modules; the group takes care of everything.
Additionally, it is possible to enable dual spec support after you create your group. DBGroup objects have an :EnableDualSpec()
method, which takes no parameters, and does exactly what its name says. There is also an :IsUsingDualSpec()
method, which returns true
or false
, depending on whether the group is currently using LibDualSpec.
Slash Commands
LibModuleDBShare can add a slash command to its groups.
-- this function is called after the group is createdfunctionaddSlashCommandToGroup()group:EnableSlashCommand("MY_GROUP","/mygroupcommand")end
By default, this command opens the root options panel for the group. If you specify a handler function as the third parameter to :EnableSlashCommand()
, that function will be called instead.
It is also possible to specify secondary command handlers for your group. For example, "/mygroupcommand foo" will call the OnFoo()
function, while "/mygroupcommand bar" will call the OnBar()
function.
localfunctionOnFoo(message,editBox)-- handle foo hereendlocalfunctionOnBar(message,editBox)-- handle bar hereend-- this is called after enabling slash commandslocalfunctionaddSecondaryCommands()group:AddSecondaryCommand("foo",OnFoo);group:AddSecondaryCommand("bar",OnBar);end
All handler functions are passed two parameters. The first is the message typed after the command, and the second is the editBox that the command originated from. NOTE: for secondary handlers, message
does NOT include the secondary command name; "/mygroupcommand foo blah" would only pass "blah" to OnFoo()
.
Saving Data
Because LibModuleDBShare has no saved variables of its own, it will create a namespace on each of its members' databases to store its information.