Mercurial > wow > libmoduledbshare-1-0
comparison LibModuleDBShare-1.0/LibModuleDBShare-1.0.lua @ 17:4ed8d6827ef7
basic implementation for LMDBS:NewGroup()
| author | Andrew Knoll <andrewtknoll@gmail.com> |
|---|---|
| date | Thu, 14 Mar 2013 00:00:45 -0400 |
| parents | 2384f5c2a707 |
| children | dacd01bf164f |
comparison
equal
deleted
inserted
replaced
| 16:2384f5c2a707 | 17:4ed8d6827ef7 |
|---|---|
| 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 = assert; | 14 local assert = assert; |
| 15 | 15 |
| 16 -- Required Libraries | |
| 16 local AceDB = LibStub("AceDB-3.0"); | 17 local AceDB = LibStub("AceDB-3.0"); |
| 18 local AceDBOptions = LibStub("AceDBOptions-3.0"); | |
| 19 local AceConfigRegistry = LibStub("AceConfigRegistry-3.0"); | |
| 20 local AceConfigDialog = LibStub("AceConfigDialog-3.0"); | |
| 17 | 21 |
| 18 LibModuleDBShare.groups = LibModuleDBShare.groups or {}; | 22 LibModuleDBShare.groups = LibModuleDBShare.groups or {}; |
| 19 | 23 |
| 20 local DBGroup = {}; | 24 local DBGroup = {}; |
| 21 | 25 |
| 22 --- Creates a new DB group. | 26 --- Creates a new DB group. |
| 23 -- @param groupName The name of the new DB group. | 27 -- @param groupName The name of the new DB group. |
| 24 -- @param usesDualSpec True if this group should use LibDualSpec, false otherwise. (NYI) | 28 -- @param usesDualSpec True if this group should use LibDualSpec, false otherwise. (NYI) |
| 25 -- @param initialProfile The name of the profile to start with. | 29 -- @param initialProfile The name of the profile to start with. (Defaults to character-specific) |
| 26 -- @usage | 30 -- @usage |
| 27 -- local myAddonDBGroup = LibStub("LibModuleDBShare-1.0"):NewGroup("MyAddonGroupName", true) | 31 -- local myAddonDBGroup = LibStub("LibModuleDBShare-1.0"):NewGroup("MyAddonGroupName", true) |
| 28 -- @return the new DB group object | 32 -- @return the new DB group object |
| 29 function LibModuleDBShare:NewGroup(groupName, usesDualSpec, initialProfile) | 33 function LibModuleDBShare:NewGroup(groupName, usesDualSpec, initialProfile) |
| 30 assert(type(groupName) == "string", "Usage: LibModuleDBShare:NewGroup(groupName, usesDualSpec, initialProfile): 'groupName' is not a string."); | 34 assert(type(groupName) == "string", "Usage: LibModuleDBShare:NewGroup(groupName, usesDualSpec, initialProfile): 'groupName' must be a string."); |
| 31 assert(type(LibModuleDBShare.groups[groupName]) == "nil", "LibModuleDBShare:NewGroup(groupName, usesDualSpec, initialProfile): 'groupName' already exists"); | 35 assert(type(LibModuleDBShare.groups[groupName]) == "nil", "LibModuleDBShare:NewGroup(groupName, usesDualSpec, initialProfile): 'groupName' already exists"); |
| 32 local group = {} | 36 local group = {} |
| 33 group.name = groupName; | 37 group.name = groupName; |
| 38 group.rootOptionsTable = { | |
| 39 type = "group", | |
| 40 name = groupName, | |
| 41 args = { | |
| 42 text = { | |
| 43 type = "description", | |
| 44 name = "placeholder text.", | |
| 45 }, | |
| 46 }, | |
| 47 }; | |
| 48 AceConfigRegistry:RegisterOptionsTable(groupName, group.rootOptionsTable); | |
| 49 AceConfigDialog:AddToBlizOptions(groupName); | |
| 34 group.syncDBTable = {}; | 50 group.syncDBTable = {}; |
| 35 group.syncDB = AceDB:New(group.syncDBTable, nil, initialProfile); | 51 group.syncDB = AceDB:New(group.syncDBTable, nil, initialProfile); |
| 52 group.profileOptionsTable = AceDBOptions:GetOptionsTable(group.syncDB, false); | |
| 53 AceConfigRegistry:RegisterOptionsTable(groupName.."Profiles", group.profileOptionsTable); | |
| 54 AceConfigDialog:AddToBlizOptions(groupName.."Profiles", "Profiles", groupName); -- need to figure out localization | |
| 55 -- profile change callbacks | |
| 36 for k, v in pairs(DBGroup) do | 56 for k, v in pairs(DBGroup) do |
| 37 group[k] = v; | 57 group[k] = v; |
| 38 end | 58 end |
| 39 return group; | 59 return group; |
| 40 end | 60 end |
| 43 -- @param groupName The name of the DB group to retrieve. | 63 -- @param groupName The name of the DB group to retrieve. |
| 44 -- @usage | 64 -- @usage |
| 45 -- local myAddonDBGroup = LibStub("LibModuleDBShare-1.0"):GetGroup("MyAddonGroupName") | 65 -- local myAddonDBGroup = LibStub("LibModuleDBShare-1.0"):GetGroup("MyAddonGroupName") |
| 46 -- @return the DB group object, or nil if not found | 66 -- @return the DB group object, or nil if not found |
| 47 function LibModuleDBShare:GetGroup(groupName) | 67 function LibModuleDBShare:GetGroup(groupName) |
| 68 assert(type(groupName) == "string", "Usage: LibModuleDBShare:GetGroup(groupName): 'groupName' must be a string"); | |
| 48 return LibModuleDBShare.groups[groupName]; | 69 return LibModuleDBShare.groups[groupName]; |
| 49 end | 70 end |
| 50 | 71 |
| 51 --- Adds a database to the group. | 72 --- Adds a database to the group. |
| 52 -- @param db The name of the new DB group. | 73 -- @param db The name of the new DB group. |
