Mercurial > wow > libmoduledbshare-1-0
comparison LibModuleDBShare-1.0/LibModuleDBShare-1.0.lua @ 24:efdeebcef96e
Implemented callback forwarding functions
| author | Andrew Knoll <andrewtknoll@gmail.com> |
|---|---|
| date | Fri, 15 Mar 2013 22:26:14 -0400 |
| parents | 91ae8cfc63f2 |
| children | e825492d4edd |
comparison
equal
deleted
inserted
replaced
| 23:91ae8cfc63f2 | 24:efdeebcef96e |
|---|---|
| 9 local LibModuleDBShare, oldminor = LibStub:NewLibrary(MAJOR, MINOR) | 9 local LibModuleDBShare, oldminor = LibStub:NewLibrary(MAJOR, MINOR) |
| 10 | 10 |
| 11 if not LibModuleDBShare then return end -- No upgrade needed | 11 if not LibModuleDBShare then return end -- No upgrade needed |
| 12 | 12 |
| 13 -- Lua APIs | 13 -- Lua APIs |
| 14 local assert, type, pairs = assert, type, pairs; | 14 local assert, type, pairs, time = assert, type, pairs, time; |
| 15 | 15 |
| 16 -- Required Libraries | 16 -- Required Libraries |
| 17 local AceDB = LibStub("AceDB-3.0"); | 17 local AceDB = LibStub("AceDB-3.0"); |
| 18 local AceDBOptions = LibStub("AceDBOptions-3.0"); | 18 local AceDBOptions = LibStub("AceDBOptions-3.0"); |
| 19 local AceConfigRegistry = LibStub("AceConfigRegistry-3.0"); | 19 local AceConfigRegistry = LibStub("AceConfigRegistry-3.0"); |
| 125 newDB.RegisterCallback(self, "OnDatabaseShutdown", "OnDatabaseShutdown"); | 125 newDB.RegisterCallback(self, "OnDatabaseShutdown", "OnDatabaseShutdown"); |
| 126 end | 126 end |
| 127 | 127 |
| 128 -- callback handlers (new profiles are handled by OnProfileChanged) | 128 -- callback handlers (new profiles are handled by OnProfileChanged) |
| 129 | 129 |
| 130 function DBGroup:OnProfileChanged(callback, db, profile) | 130 function DBGroup:OnProfileChanged(callback, syncDB, profile) |
| 131 print("Profile Changed"); | 131 print("Group "..self.name..": Profile Changed to "..profile); |
| 132 print(self.name); | 132 if not self.squelchCallbacks then |
| 133 print(type(profile)); | 133 for db, _ in pairs(self.members) do |
| 134 print(tostring(profile)); | 134 db:ChangeProfile(profile); |
| 135 end | |
| 136 else | |
| 137 print(" squelched"); | |
| 138 end | |
| 135 end | 139 end |
| 136 | 140 |
| 137 function DBGroup:OnProfileDeleted(callback, db, profile) | 141 function DBGroup:OnProfileDeleted(callback, syncDB, profile) |
| 138 print("Profile Deleted"); | 142 print("Group "..self.name..": Profile Deleted: "..profile); |
| 139 print(self.name); | 143 for db, _ in pairs(self.members) do |
| 140 print(type(profile)); | 144 db:DeleteProfile(profile, true); |
| 141 print(tostring(profile)); | 145 end |
| 142 end | 146 end |
| 143 | 147 |
| 144 function DBGroup:OnProfileCopied(callback, db, profile) | 148 function DBGroup:OnProfileCopied(callback, syncDB, profile) |
| 145 print("Profile Copied"); | 149 print("Group "..self.name..": Profile Copied from "..profile); |
| 146 print(self.name); | 150 for db, _ in pairs(self.members) do |
| 147 print(type(profile)); | 151 db:CopyProfile(profile, true); |
| 148 print(tostring(profile)); | 152 end |
| 149 end | 153 end |
| 150 | 154 |
| 151 function DBGroup:OnProfileReset(callback, db) | 155 function DBGroup:OnProfileReset(callback, syncDB) |
| 152 print("Profile Reset"); | 156 print("Group "..self.name..": Profile Reset"); |
| 153 print(self.name); | 157 for db, _ in pairs(self.members) do |
| 158 db:ResetProfile(false, false); | |
| 159 end | |
| 154 end | 160 end |
| 155 | 161 |
| 162 local timestamp = nil; | |
| 163 | |
| 156 function DBGroup:OnDatabaseShutdown(callback, db) | 164 function DBGroup:OnDatabaseShutdown(callback, db) |
| 157 print("Database Shutdown"); | 165 if not timestamp then -- ensures uniform timestamps so |
| 166 timestamp = time(); | |
| 167 end | |
| 168 db.char.logoutTimestamp = timestamp; | |
| 158 end | 169 end |
