LibModuleDBShare-1.0 provides a shared profile manager for addons without a central core.
Including LibModuleDBShare in your project
Using a repository
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.
local database;
-- this function is called after the ADDON_LOADED event fires
local group;
function initializeDB()
database = LibStub("AceDB-3.0"):New("MyAddonDB", defaults, true);
group = LibStub("LibModuleDBShare-1.0"):GetGroup("Group Name");
if not group then
group = LibStub("LibModuleDBShare-1.0"):NewGroup("Group Name", "A description for this group.", database);
else
group:AddDB(database);
end
end
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.
local myOptionsTable; -- assume this to be defined
-- this function is called after the group is created
function addOptionsToBlizzPanel()
LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable("MyModuleName", myOptionsTable);
LibStub("AceConfigDialog-3.0"):AddToBlizOptions("MyModuleName", "Module Name", "Group Name"); -- third argument is the name of the parent
end
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 created
function addSlashCommandToGroup()
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.
local function OnFoo(message, editBox)
-- handle foo here
end
local function OnBar(message, editBox)
-- handle bar here
end
-- this is called after enabling slash commands
local function addSecondaryCommands()
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.