Mercurial > wow > libmoduledbshare-1-0
comparison LibModuleDBShare-1.0/LibModuleDBShare-1.0.lua @ 35:328df380892c v1.1 release
Corrected errors in DBGroup:AddDB().
Added DBGroup:IsUsingDualSpec() and DBGroup:EnableDualSpec() methods.
| author | Andrew Knoll <andrewtknoll@gmail.com> |
|---|---|
| date | Wed, 20 Mar 2013 00:52:00 -0400 |
| parents | 3f329c676eac |
| children | f971130a84bb |
comparison
equal
deleted
inserted
replaced
| 34:a8e142ef1178 | 35:328df380892c |
|---|---|
| 3 -- standard profile manager as a subpanel. Changes through the profiles panel are propagated | 3 -- standard profile manager as a subpanel. Changes through the profiles panel are propagated |
| 4 -- to member databases. The root panel can be used as a parent for your module config panels, | 4 -- to member databases. The root panel can be used as a parent for your module config panels, |
| 5 -- to keep all your addon's config in one place. The root panel's name is the same as the group's | 5 -- to keep all your addon's config in one place. The root panel's name is the same as the group's |
| 6 -- name.\\ | 6 -- name.\\ |
| 7 -- \\ | 7 -- \\ |
| 8 -- A group can be created using the ':NewGroup' library method. The returned object inherits | 8 -- A group can be created using the ':NewGroup' library method. The returned object inherits all |
| 9 -- the ':AddDB' method of the DBGroup object described below.\\ | 9 -- methods of the DBGroup object described below.\\ |
| 10 -- \\ | 10 -- \\ |
| 11 -- **LibDualSpec Support**\\ | 11 -- **LibDualSpec Support**\\ |
| 12 -- LibModuleDBShare can use LibDualSpec to manage automatic profile switching with talent spec | 12 -- LibModuleDBShare can use LibDualSpec to manage automatic profile switching with talent spec |
| 13 -- changes. This integration is handled by the library; there is no need to use LibDualSpec | 13 -- changes. This integration is handled by the library; there is no need to use LibDualSpec |
| 14 -- on member databases directly. | 14 -- on member databases directly. |
| 25 -- group:AddDB(database); | 25 -- group:AddDB(database); |
| 26 -- end | 26 -- end |
| 27 -- end | 27 -- end |
| 28 -- @class file | 28 -- @class file |
| 29 -- @name LibModuleDBShare-1.0 | 29 -- @name LibModuleDBShare-1.0 |
| 30 local MAJOR, MINOR = "LibModuleDBShare-1.0", 2 | 30 local MAJOR, MINOR = "LibModuleDBShare-1.0", 3 |
| 31 local LibModuleDBShare, oldminor = LibStub:NewLibrary(MAJOR, MINOR) | 31 local LibModuleDBShare, oldminor = LibStub:NewLibrary(MAJOR, MINOR) |
| 32 | 32 |
| 33 if not LibModuleDBShare then return end -- No upgrade needed | 33 if not LibModuleDBShare then return end -- No upgrade needed |
| 34 | 34 |
| 35 -- Lua functions | 35 -- Lua functions |
| 57 -- local myDB = LibStub("AceDB-3.0"):New("MySavedVar"); | 57 -- local myDB = LibStub("AceDB-3.0"):New("MySavedVar"); |
| 58 -- local myAddonDBGroup = LibStub("LibModuleDBShare-1.0"):NewGroup("MyAddonGroupName", "MyDescription", myDB, true) | 58 -- local myAddonDBGroup = LibStub("LibModuleDBShare-1.0"):NewGroup("MyAddonGroupName", "MyDescription", myDB, true) |
| 59 -- @return the new DB group object | 59 -- @return the new DB group object |
| 60 -- @name LibModuleDBShare:NewGroup(groupName, groupDescription, initialDB[, usesDualSpec]); | 60 -- @name LibModuleDBShare:NewGroup(groupName, groupDescription, initialDB[, usesDualSpec]); |
| 61 function LibModuleDBShare:NewGroup(groupName, groupDescription, initialDB, usesDualSpec) | 61 function LibModuleDBShare:NewGroup(groupName, groupDescription, initialDB, usesDualSpec) |
| 62 -- check to see if LibDualSpec has been loaded | |
| 63 if not LibDualSpec then | |
| 64 LibDualSpec = LibStub("LibDualSpec-1.0", true); | |
| 65 end | |
| 62 -- verify parameters | 66 -- verify parameters |
| 63 if type(groupName) ~= "string" then | 67 if type(groupName) ~= "string" then |
| 64 error("Usage: LibModuleDBShare:NewGroup(groupName, groupDescription, initialDB, usesDualSpec): 'groupName' must be a string.", 2); | 68 error("Usage: LibModuleDBShare:NewGroup(groupName, groupDescription, initialDB, usesDualSpec): 'groupName' must be a string.", 2); |
| 65 elseif type(groupDescription) ~= "string" then | 69 elseif type(groupDescription) ~= "string" then |
| 66 error("Usage: LibModuleDBShare:NewGroup(groupName, groupDescription, initialDB, usesDualSpec): 'groupDescription' must be a string.", 2); | 70 error("Usage: LibModuleDBShare:NewGroup(groupName, groupDescription, initialDB, usesDualSpec): 'groupDescription' must be a string.", 2); |
| 116 if type(storedData.logoutTimestamp) == "number" then | 120 if type(storedData.logoutTimestamp) == "number" then |
| 117 group.profileTimestamp = storedData.logoutTimestamp; | 121 group.profileTimestamp = storedData.logoutTimestamp; |
| 118 else | 122 else |
| 119 group.profileTimestamp = 0; | 123 group.profileTimestamp = 0; |
| 120 end | 124 end |
| 121 if usesDualSpec and storedData.altProfile then | 125 if usesDualSpec then |
| 122 namespace = group.syncDB:GetNamespace("LibDualSpec-1.0"); | 126 local LDSnamespace = group.syncDB:GetNamespace("LibDualSpec-1.0"); |
| 123 namespace.char.enabled = storedData.dualSpecEnabled; | 127 LDSnamespace.char.enabled = storedData.dualSpecEnabled; |
| 124 namespace.char.profile = storedData.altProfile; | 128 LDSnamespace.char.profile = storedData.altProfile; |
| 125 namespace.char.specGroup = storedData.activeSpecGroup; | 129 LDSnamespace.char.specGroup = storedData.activeSpecGroup; |
| 126 group.syncDB:CheckDualSpecState(); | 130 group.syncDB:CheckDualSpecState(); |
| 131 else | |
| 132 group.syncDB.char.enabled = storedData.dualSpecEnabled; | |
| 133 group.syncDB.char.profile = storedData.altProfile; | |
| 134 group.syncDB.char.specGroup = storedData.activeSpecGroup; | |
| 127 end | 135 end |
| 128 -- add methods and callbacks | 136 -- add methods and callbacks |
| 129 for k, v in pairs(DBGroup) do | 137 for k, v in pairs(DBGroup) do |
| 130 group[k] = v; | 138 group[k] = v; |
| 131 end | 139 end |
| 142 | 150 |
| 143 --- Retrieves an existing DB group. | 151 --- Retrieves an existing DB group. |
| 144 -- @param groupName The name of the DB group to retrieve. | 152 -- @param groupName The name of the DB group to retrieve. |
| 145 -- @usage | 153 -- @usage |
| 146 -- local myAddonDBGroup = LibStub("LibModuleDBShare-1.0"):GetGroup("MyAddonGroupName") | 154 -- local myAddonDBGroup = LibStub("LibModuleDBShare-1.0"):GetGroup("MyAddonGroupName") |
| 147 -- @return the DB group object, or nil if not found | 155 -- @return the DB group object, or ##nil## if not found |
| 148 function LibModuleDBShare:GetGroup(groupName) | 156 function LibModuleDBShare:GetGroup(groupName) |
| 149 if type(groupName) ~= "string" then | 157 if type(groupName) ~= "string" then |
| 150 error("Usage: LibModuleDBShare:GetGroup(groupName): 'groupName' must be a string.", 2); | 158 error("Usage: LibModuleDBShare:GetGroup(groupName): 'groupName' must be a string.", 2); |
| 151 end | 159 end |
| 152 return LibModuleDBShare.groups[groupName]; | 160 return LibModuleDBShare.groups[groupName]; |
| 182 local storedData = namespace.char; | 190 local storedData = namespace.char; |
| 183 if type(storedData.logoutTimestamp) == "number" and storedData.logoutTimestamp > self.profileTimestamp then | 191 if type(storedData.logoutTimestamp) == "number" and storedData.logoutTimestamp > self.profileTimestamp then |
| 184 self.squelchCallbacks = false; | 192 self.squelchCallbacks = false; |
| 185 self.syncDB:SetProfile(newDB:GetCurrentProfile()); | 193 self.syncDB:SetProfile(newDB:GetCurrentProfile()); |
| 186 self.profileTimestamp = storedData.logoutTimestamp; | 194 self.profileTimestamp = storedData.logoutTimestamp; |
| 187 if usesDualSpec and storedData.altProfile then | 195 if self.usesDualSpec and storedData.altProfile then |
| 188 namespace = group.syncDB:GetNamespace("LibDualSpec-1.0"); | 196 local LDSnamespace = group.syncDB:GetNamespace("LibDualSpec-1.0"); |
| 189 namespace.char.enabled = storedData.dualSpecEnabled; | 197 LDSnamespace.char.enabled = storedData.dualSpecEnabled; |
| 190 namespace.char.profile = storedData.altProfile; | 198 LDSnamespace.char.profile = storedData.altProfile; |
| 191 namespace.char.specGroup = storedData.activeSpecGroup; | 199 LDSnamespace.char.specGroup = storedData.activeSpecGroup; |
| 192 group.syncDB:CheckDualSpecState(); | 200 group.syncDB:CheckDualSpecState(); |
| 201 elseif storedData.altProfile then | |
| 202 self.syncDB.char.enabled = storedData.dualSpecEnabled; | |
| 203 self.syncDB.char.profile = storedData.altProfile; | |
| 204 self.syncDB.char.specGroup = storedData.activeSpecGroup; | |
| 193 end | 205 end |
| 194 else | 206 else |
| 195 self.syncDB:SetProfile(syncProfile); | 207 self.syncDB:SetProfile(syncProfile); |
| 196 newDB:SetProfile(syncProfile); | 208 newDB:SetProfile(syncProfile); |
| 197 self.squelchCallbacks = false; | 209 self.squelchCallbacks = false; |
| 198 end | 210 end |
| 199 -- add to members list | 211 -- add to members list |
| 200 self.members[newDB] = namespace; | 212 self.members[newDB] = namespace; |
| 201 newDB.RegisterCallback(self, "OnDatabaseShutdown", "OnMemberShutdown"); | 213 newDB.RegisterCallback(self, "OnDatabaseShutdown", "OnMemberShutdown"); |
| 214 end | |
| 215 | |
| 216 --- Checks to see if this group uses LibDualSpec. | |
| 217 -- @return ##true## if this group uses LibDualSpec, ##false## otherwise | |
| 218 function DBGroup:IsUsingDualSpec() | |
| 219 return self.usesDualSpec; | |
| 220 end | |
| 221 | |
| 222 --- Enables dual spec support if not already enabled. | |
| 223 function DBGroup:EnableDualSpec() | |
| 224 if not LibDualSpec then | |
| 225 LibDualSpec = LibStub("LibDualSpec-1.0"); -- this will error if LDS isn't found | |
| 226 end | |
| 227 if not self.usesDualSpec then | |
| 228 LibDualSpec:EnhanceDatabase(self.syncDB, self.name); | |
| 229 LibDualSpec:EnhanceOptions(self.profileOptionsTable, self.syncDB); | |
| 230 self.usesDualSpec = true; | |
| 231 local namespace = self.syncDB:GetNamespace("LibDualSpec-1.0"); | |
| 232 namespace.char.enabled = self.syncDB.char.enabled; | |
| 233 namespace.char.profile = self.syncDB.char.profile; | |
| 234 namespace.char.specGroup = self.syncDB.char.specGroup; | |
| 235 self.syncDB:CheckDualSpecState(); | |
| 236 end | |
| 202 end | 237 end |
| 203 | 238 |
| 204 -- callback handlers (new profiles are handled by OnProfileChanged) | 239 -- callback handlers (new profiles are handled by OnProfileChanged) |
| 205 | 240 |
| 206 function DBGroup:OnProfileChanged(callback, syncDB, profile) | 241 function DBGroup:OnProfileChanged(callback, syncDB, profile) |
