|
>@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@18
|
54 AceConfigDialog:AddToBlizOptions(groupName.."Profiles", group.profileOptionsTable.name, groupName);
|
|
andrewtknoll@18
|
55 group.members = {};
|
|
@12
|
56 for k, v in pairs(DBGroup) do
|
|
@12
|
57 group[k] = v;
|
|
@12
|
58 end
|
|
andrewtknoll@19
|
59 group.syncDB.RegisterCallback(group, "OnProfileChanged", "OnProfileChanged");
|
|
andrewtknoll@19
|
60 group.syncDB.RegisterCallback(group, "OnProfileDeleted", "OnProfileDeleted");
|
|
andrewtknoll@19
|
61 group.syncDB.RegisterCallback(group, "OnProfileCopied", "OnProfileCopied");
|
|
andrewtknoll@19
|
62 group.syncDB.RegisterCallback(group, "OnProfileReset", "OnProfileReset");
|
|
andrewtknoll@19
|
63 LibModuleDBShare.groups[groupName] = group;
|
|
@12
|
64 return group;
|
|
>@4
|
65 end
|
|
>@4
|
66
|
|
>@5
|
67 --- Retrieves an existing DB group.
|
|
>@5
|
68 -- @param groupName The name of the DB group to retrieve.
|
|
>@5
|
69 -- @usage
|
|
>@5
|
70 -- local myAddonDBGroup = LibStub("LibModuleDBShare-1.0"):GetGroup("MyAddonGroupName")
|
|
>@5
|
71 -- @return the DB group object, or nil if not found
|
|
>@5
|
72 function LibModuleDBShare:GetGroup(groupName)
|
|
andrewtknoll@17
|
73 assert(type(groupName) == "string", "Usage: LibModuleDBShare:GetGroup(groupName): 'groupName' must be a string");
|
|
@12
|
74 return LibModuleDBShare.groups[groupName];
|
|
>@4
|
75 end
|
|
>@5
|
76
|
|
>@5
|
77 --- Adds a database to the group.
|
|
>@5
|
78 -- @param db The name of the new DB group.
|
|
>@5
|
79 -- @usage
|
|
>@5
|
80 -- myAddonDBGroup:AddDB(MyAddon.db)
|
|
>@5
|
81 function DBGroup:AddDB(db)
|
|
>@5
|
82
|
|
>@5
|
83 end
|
|
andrewtknoll@18
|
84
|
|
andrewtknoll@19
|
85 -- callback handlers (new profiles are handled by OnProfileChanged)
|
|
andrewtknoll@19
|
86
|
|
andrewtknoll@19
|
87 function DBGroup:OnProfileChanged(callback, db, profile)
|
|
andrewtknoll@19
|
88 print("Profile Changed");
|
|
andrewtknoll@19
|
89 print(self.name);
|
|
andrewtknoll@18
|
90 print(type(profile));
|
|
andrewtknoll@18
|
91 print(tostring(profile));
|
|
andrewtknoll@18
|
92 end
|
|
andrewtknoll@18
|
93
|
|
andrewtknoll@19
|
94 function DBGroup:OnProfileDeleted(callback, db, profile)
|
|
andrewtknoll@19
|
95 print("Profile Deleted");
|
|
andrewtknoll@19
|
96 print(self.name);
|
|
andrewtknoll@18
|
97 print(type(profile));
|
|
andrewtknoll@18
|
98 print(tostring(profile));
|
|
andrewtknoll@18
|
99 end
|
|
andrewtknoll@18
|
100
|
|
andrewtknoll@19
|
101 function DBGroup:OnProfileCopied(callback, db, profile)
|
|
andrewtknoll@19
|
102 print("Profile Copied");
|
|
andrewtknoll@19
|
103 print(self.name);
|
|
andrewtknoll@18
|
104 print(type(profile));
|
|
andrewtknoll@18
|
105 print(tostring(profile));
|
|
andrewtknoll@18
|
106 end
|
|
andrewtknoll@18
|
107
|
|
andrewtknoll@19
|
108 function DBGroup:OnProfileReset(callback, db)
|
|
andrewtknoll@19
|
109 print("Profile Reset");
|
|
andrewtknoll@19
|
110 print(self.name);
|
|
andrewtknoll@18
|
111 end
|