|
>@5
|
1 --- **LibModuleDBShare-1.0**\\
|
|
>@5
|
2 -- A description will eventually be here.
|
|
>@5
|
3 --
|
|
>@5
|
4 -- @usage
|
|
>@5
|
5 -- Also coming soon.
|
|
>@5
|
6 -- @class file
|
|
>@5
|
7 -- @name LibModuleDBShare-1.0.lua
|
|
>@3
|
8 local MAJOR, MINOR = "LibModuleDBShare-1.0", 1
|
|
>@3
|
9 local LibModuleDBShare, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
|
|
>@3
|
10
|
|
>@4
|
11 if not LibModuleDBShare then return end -- No upgrade needed
|
|
>@4
|
12
|
|
andrewtknoll@15
|
13 -- Lua APIs
|
|
andrewtknoll@15
|
14 local assert = assert;
|
|
andrewtknoll@15
|
15
|
|
andrewtknoll@17
|
16 -- Required Libraries
|
|
@12
|
17 local AceDB = LibStub("AceDB-3.0");
|
|
andrewtknoll@17
|
18 local AceDBOptions = LibStub("AceDBOptions-3.0");
|
|
andrewtknoll@17
|
19 local AceConfigRegistry = LibStub("AceConfigRegistry-3.0");
|
|
andrewtknoll@17
|
20 local AceConfigDialog = LibStub("AceConfigDialog-3.0");
|
|
@12
|
21
|
|
>@4
|
22 LibModuleDBShare.groups = LibModuleDBShare.groups or {};
|
|
>@4
|
23
|
|
>@5
|
24 local DBGroup = {};
|
|
>@5
|
25
|
|
>@5
|
26 --- Creates a new DB group.
|
|
>@5
|
27 -- @param groupName The name of the new DB group.
|
|
@12
|
28 -- @param usesDualSpec True if this group should use LibDualSpec, false otherwise. (NYI)
|
|
andrewtknoll@17
|
29 -- @param initialProfile The name of the profile to start with. (Defaults to character-specific)
|
|
>@5
|
30 -- @usage
|
|
>@5
|
31 -- local myAddonDBGroup = LibStub("LibModuleDBShare-1.0"):NewGroup("MyAddonGroupName", true)
|
|
>@5
|
32 -- @return the new DB group object
|
|
andrewtknoll@11
|
33 function LibModuleDBShare:NewGroup(groupName, usesDualSpec, initialProfile)
|
|
andrewtknoll@17
|
34 assert(type(groupName) == "string", "Usage: LibModuleDBShare:NewGroup(groupName, usesDualSpec, initialProfile): 'groupName' must be a string.");
|
|
andrewtknoll@15
|
35 assert(type(LibModuleDBShare.groups[groupName]) == "nil", "LibModuleDBShare:NewGroup(groupName, usesDualSpec, initialProfile): 'groupName' already exists");
|
|
@12
|
36 local group = {}
|
|
@12
|
37 group.name = groupName;
|
|
andrewtknoll@17
|
38 group.rootOptionsTable = {
|
|
andrewtknoll@17
|
39 type = "group",
|
|
andrewtknoll@17
|
40 name = groupName,
|
|
andrewtknoll@17
|
41 args = {
|
|
andrewtknoll@17
|
42 text = {
|
|
andrewtknoll@17
|
43 type = "description",
|
|
andrewtknoll@17
|
44 name = "placeholder text.",
|
|
andrewtknoll@17
|
45 },
|
|
andrewtknoll@17
|
46 },
|
|
andrewtknoll@17
|
47 };
|
|
andrewtknoll@17
|
48 AceConfigRegistry:RegisterOptionsTable(groupName, group.rootOptionsTable);
|
|
andrewtknoll@17
|
49 AceConfigDialog:AddToBlizOptions(groupName);
|
|
@12
|
50 group.syncDBTable = {};
|
|
andrewtknoll@16
|
51 group.syncDB = AceDB:New(group.syncDBTable, nil, initialProfile);
|
|
andrewtknoll@17
|
52 group.profileOptionsTable = AceDBOptions:GetOptionsTable(group.syncDB, false);
|
|
andrewtknoll@17
|
53 AceConfigRegistry:RegisterOptionsTable(groupName.."Profiles", group.profileOptionsTable);
|
|
andrewtknoll@17
|
54 AceConfigDialog:AddToBlizOptions(groupName.."Profiles", "Profiles", groupName); -- need to figure out localization
|
|
andrewtknoll@17
|
55 -- profile change callbacks
|
|
@12
|
56 for k, v in pairs(DBGroup) do
|
|
@12
|
57 group[k] = v;
|
|
@12
|
58 end
|
|
@12
|
59 return group;
|
|
>@4
|
60 end
|
|
>@4
|
61
|
|
>@5
|
62 --- Retrieves an existing DB group.
|
|
>@5
|
63 -- @param groupName The name of the DB group to retrieve.
|
|
>@5
|
64 -- @usage
|
|
>@5
|
65 -- local myAddonDBGroup = LibStub("LibModuleDBShare-1.0"):GetGroup("MyAddonGroupName")
|
|
>@5
|
66 -- @return the DB group object, or nil if not found
|
|
>@5
|
67 function LibModuleDBShare:GetGroup(groupName)
|
|
andrewtknoll@17
|
68 assert(type(groupName) == "string", "Usage: LibModuleDBShare:GetGroup(groupName): 'groupName' must be a string");
|
|
@12
|
69 return LibModuleDBShare.groups[groupName];
|
|
>@4
|
70 end
|
|
>@5
|
71
|
|
>@5
|
72 --- Adds a database to the group.
|
|
>@5
|
73 -- @param db The name of the new DB group.
|
|
>@5
|
74 -- @usage
|
|
>@5
|
75 -- myAddonDBGroup:AddDB(MyAddon.db)
|
|
>@5
|
76 function DBGroup:AddDB(db)
|
|
>@5
|
77
|
|
>@5
|
78 end
|