Mercurial > wow > libmoduledbshare-1-0
comparison LibModuleDBShare-1.0/LibModuleDBShare-1.0.lua @ 20:647cb45f5864
implemented DBG:AddDB()
| author | Andrew Knoll <andrewtknoll@gmail.com> |
|---|---|
| date | Fri, 15 Mar 2013 03:02:01 -0400 |
| parents | ec910729e073 |
| children | f2038b9d4d9a |
comparison
equal
deleted
inserted
replaced
| 19:ec910729e073 | 20:647cb45f5864 |
|---|---|
| 58 end | 58 end |
| 59 group.syncDB.RegisterCallback(group, "OnProfileChanged", "OnProfileChanged"); | 59 group.syncDB.RegisterCallback(group, "OnProfileChanged", "OnProfileChanged"); |
| 60 group.syncDB.RegisterCallback(group, "OnProfileDeleted", "OnProfileDeleted"); | 60 group.syncDB.RegisterCallback(group, "OnProfileDeleted", "OnProfileDeleted"); |
| 61 group.syncDB.RegisterCallback(group, "OnProfileCopied", "OnProfileCopied"); | 61 group.syncDB.RegisterCallback(group, "OnProfileCopied", "OnProfileCopied"); |
| 62 group.syncDB.RegisterCallback(group, "OnProfileReset", "OnProfileReset"); | 62 group.syncDB.RegisterCallback(group, "OnProfileReset", "OnProfileReset"); |
| 63 group.squelchCallbacks = false; | |
| 63 LibModuleDBShare.groups[groupName] = group; | 64 LibModuleDBShare.groups[groupName] = group; |
| 64 return group; | 65 return group; |
| 65 end | 66 end |
| 66 | 67 |
| 67 --- Retrieves an existing DB group. | 68 --- Retrieves an existing DB group. |
| 73 assert(type(groupName) == "string", "Usage: LibModuleDBShare:GetGroup(groupName): 'groupName' must be a string"); | 74 assert(type(groupName) == "string", "Usage: LibModuleDBShare:GetGroup(groupName): 'groupName' must be a string"); |
| 74 return LibModuleDBShare.groups[groupName]; | 75 return LibModuleDBShare.groups[groupName]; |
| 75 end | 76 end |
| 76 | 77 |
| 77 --- Adds a database to the group. | 78 --- Adds a database to the group. |
| 78 -- @param db The name of the new DB group. | 79 -- @param db The database to add. |
| 79 -- @usage | 80 -- @usage |
| 80 -- myAddonDBGroup:AddDB(MyAddon.db) | 81 -- myAddonDBGroup:AddDB(MyAddon.db) |
| 81 function DBGroup:AddDB(db) | 82 function DBGroup:AddDB(db) |
| 82 | 83 local syncProfile = self.syncDB:GetCurrentProfile(); |
| 84 | |
| 85 local shouldDeleteDefault = false; -- if not first DB, then default profile already handled | |
| 86 if type(self.profileTimestamp) == "nil" then | |
| 87 shouldDeleteDefault = true -- first DB added.. might not have default profile | |
| 88 self.profileTimestamp = 0; | |
| 89 end | |
| 90 self.squelchCallbacks = true; | |
| 91 for i, profile in pairs(db:GetProfiles()) do | |
| 92 if profile == "Default" then | |
| 93 shouldDeleteDefault = false; | |
| 94 end | |
| 95 self.syncDB:SetProfile(profile); | |
| 96 end | |
| 97 | |
| 98 if db.character.logoutTimestamp > self.profileTimestamp then | |
| 99 self.syncDB:SetProfile(db:GetCurrentProfile()); | |
| 100 self.profileTimestamp = db.character.logoutTimestamp; | |
| 101 else | |
| 102 self.syncDB:SetProfile(syncProfile); | |
| 103 end | |
| 104 | |
| 105 if shouldDeleteDefault then | |
| 106 self.syncDB:DeleteProfile("Default"); | |
| 107 end | |
| 108 self.squelchCallbacks = false; | |
| 109 | |
| 110 if self.syncDB:GetCurrentProfile() ~= syncProfile then | |
| 111 self:OnProfileChanged("OnProfileChanged", self.syncDB, self.syncDB:GetCurrentProfile()); | |
| 112 end | |
| 83 end | 113 end |
| 84 | 114 |
| 85 -- callback handlers (new profiles are handled by OnProfileChanged) | 115 -- callback handlers (new profiles are handled by OnProfileChanged) |
| 86 | 116 |
| 87 function DBGroup:OnProfileChanged(callback, db, profile) | 117 function DBGroup:OnProfileChanged(callback, db, profile) |
