>@5: --- **LibModuleDBShare-1.0**\\ >@5: -- A description will eventually be here. >@5: -- >@5: -- @usage >@5: -- Also coming soon. >@5: -- @class file >@5: -- @name LibModuleDBShare-1.0.lua >@3: local MAJOR, MINOR = "LibModuleDBShare-1.0", 1 >@3: local LibModuleDBShare, oldminor = LibStub:NewLibrary(MAJOR, MINOR) >@3: >@4: if not LibModuleDBShare then return end -- No upgrade needed >@4: andrewtknoll@15: -- Lua APIs andrewtknoll@15: local assert = assert; andrewtknoll@15: andrewtknoll@17: -- Required Libraries @12: local AceDB = LibStub("AceDB-3.0"); andrewtknoll@17: local AceDBOptions = LibStub("AceDBOptions-3.0"); andrewtknoll@17: local AceConfigRegistry = LibStub("AceConfigRegistry-3.0"); andrewtknoll@17: local AceConfigDialog = LibStub("AceConfigDialog-3.0"); @12: >@4: LibModuleDBShare.groups = LibModuleDBShare.groups or {}; >@4: >@5: local DBGroup = {}; >@5: >@5: --- Creates a new DB group. >@5: -- @param groupName The name of the new DB group. @12: -- @param usesDualSpec True if this group should use LibDualSpec, false otherwise. (NYI) andrewtknoll@17: -- @param initialProfile The name of the profile to start with. (Defaults to character-specific) >@5: -- @usage >@5: -- local myAddonDBGroup = LibStub("LibModuleDBShare-1.0"):NewGroup("MyAddonGroupName", true) >@5: -- @return the new DB group object andrewtknoll@11: function LibModuleDBShare:NewGroup(groupName, usesDualSpec, initialProfile) andrewtknoll@17: assert(type(groupName) == "string", "Usage: LibModuleDBShare:NewGroup(groupName, usesDualSpec, initialProfile): 'groupName' must be a string."); andrewtknoll@15: assert(type(LibModuleDBShare.groups[groupName]) == "nil", "LibModuleDBShare:NewGroup(groupName, usesDualSpec, initialProfile): 'groupName' already exists"); @12: local group = {} @12: group.name = groupName; andrewtknoll@17: group.rootOptionsTable = { andrewtknoll@17: type = "group", andrewtknoll@17: name = groupName, andrewtknoll@17: args = { andrewtknoll@17: text = { andrewtknoll@17: type = "description", andrewtknoll@17: name = "placeholder text.", andrewtknoll@17: }, andrewtknoll@17: }, andrewtknoll@17: }; andrewtknoll@17: AceConfigRegistry:RegisterOptionsTable(groupName, group.rootOptionsTable); andrewtknoll@17: AceConfigDialog:AddToBlizOptions(groupName); @12: group.syncDBTable = {}; andrewtknoll@16: group.syncDB = AceDB:New(group.syncDBTable, nil, initialProfile); andrewtknoll@17: group.profileOptionsTable = AceDBOptions:GetOptionsTable(group.syncDB, false); andrewtknoll@17: AceConfigRegistry:RegisterOptionsTable(groupName.."Profiles", group.profileOptionsTable); andrewtknoll@18: AceConfigDialog:AddToBlizOptions(groupName.."Profiles", group.profileOptionsTable.name, groupName); andrewtknoll@18: group.members = {}; @12: for k, v in pairs(DBGroup) do @12: group[k] = v; @12: end andrewtknoll@19: group.syncDB.RegisterCallback(group, "OnProfileChanged", "OnProfileChanged"); andrewtknoll@19: group.syncDB.RegisterCallback(group, "OnProfileDeleted", "OnProfileDeleted"); andrewtknoll@19: group.syncDB.RegisterCallback(group, "OnProfileCopied", "OnProfileCopied"); andrewtknoll@19: group.syncDB.RegisterCallback(group, "OnProfileReset", "OnProfileReset"); andrewtknoll@19: LibModuleDBShare.groups[groupName] = group; @12: return group; >@4: end >@4: >@5: --- Retrieves an existing DB group. >@5: -- @param groupName The name of the DB group to retrieve. >@5: -- @usage >@5: -- local myAddonDBGroup = LibStub("LibModuleDBShare-1.0"):GetGroup("MyAddonGroupName") >@5: -- @return the DB group object, or nil if not found >@5: function LibModuleDBShare:GetGroup(groupName) andrewtknoll@17: assert(type(groupName) == "string", "Usage: LibModuleDBShare:GetGroup(groupName): 'groupName' must be a string"); @12: return LibModuleDBShare.groups[groupName]; >@4: end >@5: >@5: --- Adds a database to the group. >@5: -- @param db The name of the new DB group. >@5: -- @usage >@5: -- myAddonDBGroup:AddDB(MyAddon.db) >@5: function DBGroup:AddDB(db) >@5: >@5: end andrewtknoll@18: andrewtknoll@19: -- callback handlers (new profiles are handled by OnProfileChanged) andrewtknoll@19: andrewtknoll@19: function DBGroup:OnProfileChanged(callback, db, profile) andrewtknoll@19: print("Profile Changed"); andrewtknoll@19: print(self.name); andrewtknoll@18: print(type(profile)); andrewtknoll@18: print(tostring(profile)); andrewtknoll@18: end andrewtknoll@18: andrewtknoll@19: function DBGroup:OnProfileDeleted(callback, db, profile) andrewtknoll@19: print("Profile Deleted"); andrewtknoll@19: print(self.name); andrewtknoll@18: print(type(profile)); andrewtknoll@18: print(tostring(profile)); andrewtknoll@18: end andrewtknoll@18: andrewtknoll@19: function DBGroup:OnProfileCopied(callback, db, profile) andrewtknoll@19: print("Profile Copied"); andrewtknoll@19: print(self.name); andrewtknoll@18: print(type(profile)); andrewtknoll@18: print(tostring(profile)); andrewtknoll@18: end andrewtknoll@18: andrewtknoll@19: function DBGroup:OnProfileReset(callback, db) andrewtknoll@19: print("Profile Reset"); andrewtknoll@19: print(self.name); andrewtknoll@18: end