comparison Core.lua @ 61:d903b0a151d3

Command handler function is now private, no need to keep it global when you can use the global SlashCmdList["INVENTORIUM"](msg) instead. Added database updating mechanism. All database vars are now stored in profiles rather than global. Now refreshing options when a different profile is selected. Fixed an issue with minimum local and global stock values not being inherited from the defaults.
author Zerotorescue
date Wed, 22 Dec 2010 15:04:09 +0100
parents 03c0610e9c1e
children fee06221176f
comparison
equal deleted inserted replaced
60:12c2b20ca843 61:d903b0a151d3
2 local addon = select(2, ...); 2 local addon = select(2, ...);
3 addon = LibStub("AceAddon-3.0"):NewAddon(addon, "Inventorium", "AceEvent-3.0"); 3 addon = LibStub("AceAddon-3.0"):NewAddon(addon, "Inventorium", "AceEvent-3.0");
4 4
5 local AceGUI = LibStub("AceGUI-3.0"); 5 local AceGUI = LibStub("AceGUI-3.0");
6 6
7 --@debug@
8 local addonRevision = 1;
9 --@end-debug@
10 --[===[@non-debug@
11 local addonRevision = @project-revision@;
12 --@end-non-debug@]===]
13
7 local AceConfigDialog, AceConfigRegistry, AceSerializer; 14 local AceConfigDialog, AceConfigRegistry, AceSerializer;
8 local groupIdToName, groupIsVirtual, options = {}, {}, {}; 15 local groupIdToName, groupIsVirtual, options = {}, {}, {};
9 local includeTradeSkillItems = 500; 16 local includeTradeSkillItems = 500;
17
18 local slashArgs = {};
19 local slashError = "Wrong argument, the following arguments are available:";
10 20
11 -- All modules must be able to retrieve our supported addons database, thus keep it public 21 -- All modules must be able to retrieve our supported addons database, thus keep it public
12 addon.supportedAddons = {}; 22 addon.supportedAddons = {};
13 addon.supportedAddons.auctionPricing = {}; 23 addon.supportedAddons.auctionPricing = {};
14 addon.supportedAddons.itemCount = {}; 24 addon.supportedAddons.itemCount = {};
15 addon.supportedAddons.crafting = {}; 25 addon.supportedAddons.crafting = {};
16 26
27 local function CommandHandler(message)
28 local cmd, arg = string.split(" ", (message or ""), 2);
29 cmd = string.lower(cmd);
30
31 if slashArgs[cmd] then
32 slashArgs[cmd](addon, arg);
33 else
34 print(slashError);
35 end
36 end
37
17 function addon:OnInitialize() 38 function addon:OnInitialize()
18 self:Debug("OnInitialize"); 39 self:Debug("OnInitialize");
19 40
20 -- SAVED VARIABLES 41 -- SAVED VARIABLES
21 42
22 local defaults = { 43 local defaults = {
23 global = { 44 global = {
24 groups = { 45 version = nil,
25 }, 46 },
47 profile = {
26 defaults = { 48 defaults = {
27 auctionPricingAddon = "Auctioneer", 49 auctionPricingAddon = "Auctioneer",
28 itemCountAddon = "Altoholic", 50 itemCountAddon = "Altoholic",
29 craftingAddon = "AdvancedTradeSkillWindow", 51 craftingAddon = "AdvancedTradeSkillWindow",
30 minimumLocalStock = 20, 52 minLocalStock = 20,
31 alertBelowLocalMinimum = true, 53 alertBelowLocalMinimum = true,
32 minimumStock = 60, -- global stock 54 minGlobalStock = 60,
33 alertBelowMinimum = true, -- global stock 55 alertBelowGlobalMinimum = true,
34 summaryThresholdShow = 10, 56 summaryThresholdShow = 10,
35 restockTarget = 60, 57 restockTarget = 60,
36 minCraftingQueue = 0.05, 58 minCraftingQueue = 0.05,
37 bonusQueue = 0.1, 59 bonusQueue = 0.1,
38 priceThreshold = 0, 60 priceThreshold = 0,
53 orange = 0.3, 75 orange = 0.3,
54 yellow = 0.6, 76 yellow = 0.6,
55 green = 0.95, 77 green = 0.95,
56 }, 78 },
57 }, 79 },
80 groups = {
81 },
58 }, 82 },
59 factionrealm = { 83 factionrealm = {
60 characters = { 84 characters = {
61 }, 85 },
62 }, 86 },
63 }; 87 };
64 88
65 -- Register our saved variables database 89 -- Register our saved variables database
66 self.db = LibStub("AceDB-3.0"):New("InventoriumDB", defaults, true); 90 self.db = LibStub("AceDB-3.0"):New("InventoriumDB", defaults, true);
91 self.db.RegisterCallback(self, "OnProfileChanged", "RefreshConfig")
92 self.db.RegisterCallback(self, "OnProfileCopied", "RefreshConfig")
93 self.db.RegisterCallback(self, "OnProfileReset", "RefreshConfig")
94
95 if not self.db.global.version or self.db.global.version < addonRevision then
96 -- Is our database outdated? Then patch it.
97
98 if not self.db.global.version then
99 -- Old version was before version was saved, many changes were done in that revision
100
101 print("Updating Inventorium database from version " .. (self.db.global.version or "Unknown") .. " to version " .. addonRevision .. "...");
102
103 if self.db.global and self.db.global.defaults then
104 print("Moving all global data into your current profile...");
105
106 -- All data mustn't be global but profile-based
107 self.db.profile.defaults = CopyTable(self.db.global.defaults);
108 self.db.profile.groups = CopyTable(self.db.global.groups);
109
110 self.db.global.defaults = nil;
111 self.db.global.groups = nil;
112
113 CommandHandler = function()
114 print("You must /reload once to finalize the database updates.");
115 end;
116 CommandHandler();
117 end
118
119 if self.db.profile.defaults.minimumStock then
120 print("Copying the minimum stock value into the minimum global stock...");
121
122 -- We added another stock option and renamed the old to be more obvious about what it means
123 self.db.profile.defaults.minGlobalStock = self.db.profile.defaults.minimumStock;
124 self.db.profile.defaults.minimumStock = nil;
125 end
126
127 if self.db.profile.defaults.minimumLocalStock then
128 print("Renaming the minimum local stock property...");
129
130 -- We added another stock option and then renamed it
131 self.db.profile.defaults.minLocalStock = self.db.profile.defaults.minimumLocalStock;
132 self.db.profile.defaults.minimumLocalStock = nil;
133 end
134
135 if self.db.profile.defaults.alertBelowMinimum then
136 print("Copying the alert below minimum value into the alert below global minimum value...");
137
138 -- We added another stock option and then renamed it
139 self.db.profile.defaults.alertBelowGlobalMinimum = self.db.profile.defaults.alertBelowMinimum;
140 self.db.profile.defaults.alertBelowMinimum = nil;
141 end
142
143 -- Go through all groups to see if there's one with the above two renamed variables
144 for groupName, values in pairs(self.db.profile.groups) do
145 if values.minimumStock then
146 values.minGlobalStock = values.minimumStock;
147 values.minimumStock = nil;
148 end
149 end
150 end
151
152 -- Remember the version of our database
153 self.db.global.version = addonRevision;
154 end
67 155
68 -- SLASH COMMANDS 156 -- SLASH COMMANDS
69 157
70 -- Disable the AddonLoader slash commands 158 -- Disable the AddonLoader slash commands
71 SLASH_INVENTORIUM1 = nil; 159 SLASH_INVENTORIUM1 = nil;
72 SLASH_IY1 = nil; 160 SLASH_IY1 = nil;
73 161
74 -- Register our own slash commands 162 -- Register our own slash commands
75 SLASH_INVENTORIUM1 = "/inventorium"; 163 SLASH_INVENTORIUM1 = "/inventorium";
76 SLASH_INVENTORIUM2 = "/im"; 164 SLASH_INVENTORIUM2 = "/im";
77 SlashCmdList["INVENTORIUM"] = InventoriumCommandHandler; 165 SlashCmdList["INVENTORIUM"] = CommandHandler;
78 166
79 -- Config command handling 167 -- Config command handling
80 self:RegisterSlash(function(this) 168 self:RegisterSlash(function(this)
81 -- We don't want any other windows open at this time. 169 -- We don't want any other windows open at this time.
82 for name, module in this:IterateModules() do 170 for name, module in this:IterateModules() do
137 local playerName = UnitName("player"); 225 local playerName = UnitName("player");
138 if not self.db.factionrealm.characters[playerName] then 226 if not self.db.factionrealm.characters[playerName] then
139 self.db.factionrealm.characters[playerName] = true; 227 self.db.factionrealm.characters[playerName] = true;
140 228
141 -- Default to tracking on all chars, untracking is a convenience, not tracking by default would probably get multiple issue reports. 229 -- Default to tracking on all chars, untracking is a convenience, not tracking by default would probably get multiple issue reports.
142 self.db.global.defaults.trackAtCharacters[playerName] = true; 230 self.db.profile.defaults.trackAtCharacters[playerName] = true;
143 end 231 end
144 232
145 self:PremadeGroupsCheck(); 233 self:PremadeGroupsCheck();
234 end
235
236 function addon:RefreshConfig()
237 self:FillGroupOptions();
146 end 238 end
147 239
148 local function InGroup(itemId) 240 local function InGroup(itemId)
149 -- Go through all groups to see if this item is already somewhere 241 -- Go through all groups to see if this item is already somewhere
150 for groupName, values in pairs(addon.db.global.groups) do 242 for groupName, values in pairs(addon.db.profile.groups) do
151 if values.items and values.items[itemId] then 243 if values.items and values.items[itemId] then
152 return groupName; 244 return groupName;
153 end 245 end
154 end 246 end
155 247
159 local function AddToGroup(groupName, itemId) 251 local function AddToGroup(groupName, itemId)
160 if InGroup(itemId) then 252 if InGroup(itemId) then
161 return false; 253 return false;
162 end 254 end
163 255
164 if not addon.db.global.groups[groupName].items then 256 if not addon.db.profile.groups[groupName].items then
165 addon.db.global.groups[groupName].items = {}; 257 addon.db.profile.groups[groupName].items = {};
166 end 258 end
167 259
168 -- Set this item 260 -- Set this item
169 addon.db.global.groups[groupName].items[itemId] = true; 261 addon.db.profile.groups[groupName].items[itemId] = true;
170 262
171 if AceConfigRegistry then 263 if AceConfigRegistry then
172 -- Now rebuild the list 264 -- Now rebuild the list
173 AceConfigRegistry:NotifyChange("InventoriumOptions"); 265 AceConfigRegistry:NotifyChange("InventoriumOptions");
174 end 266 end
175 267
176 return true; 268 return true;
180 if InGroup(itemId) ~= groupName then 272 if InGroup(itemId) ~= groupName then
181 return false; 273 return false;
182 end 274 end
183 275
184 -- Unset this item 276 -- Unset this item
185 addon.db.global.groups[groupName].items[itemId] = nil; 277 addon.db.profile.groups[groupName].items[itemId] = nil;
186 278
187 return true; 279 return true;
188 end 280 end
189 281
190 function addon:PremadeGroupsCheck(updateGroupName, updateKey, accept) 282 function addon:PremadeGroupsCheck(updateGroupName, updateKey, accept)
191 -- Compare the current premade groups with those used, notify about changes 283 -- Compare the current premade groups with those used, notify about changes
192 if addon.defaultGroups then 284 if addon.defaultGroups then
193 for premadeGroupName, groupInfo in pairs(addon.defaultGroups) do 285 for premadeGroupName, groupInfo in pairs(addon.defaultGroups) do
194 -- Go through all default groups 286 -- Go through all default groups
195 287
196 for groupName, values in pairs(addon.db.global.groups) do 288 for groupName, values in pairs(addon.db.profile.groups) do
197 -- Go through all groups to find those with this premade group 289 -- Go through all groups to find those with this premade group
198 290
199 if values.premadeGroups and values.premadeGroups[premadeGroupName] and values.premadeGroups[premadeGroupName] < groupInfo.version then 291 if values.premadeGroups and values.premadeGroups[premadeGroupName] and values.premadeGroups[premadeGroupName] < groupInfo.version then
200 -- Outdated group 292 -- Outdated group
201 293
426 end 518 end
427 519
428 AceGUI:RegisterWidgetType(widgetType, GetItemLinkButton, widgetVersion); 520 AceGUI:RegisterWidgetType(widgetType, GetItemLinkButton, widgetVersion);
429 end 521 end
430 522
431 local slashArgs = {};
432 local slashError = "Wrong argument, the following arguements are available:";
433
434 function addon:RegisterSlash(func, args, description) 523 function addon:RegisterSlash(func, args, description)
435 for _, arg in pairs(args) do 524 for _, arg in pairs(args) do
436 slashArgs[arg] = func; 525 slashArgs[arg] = func;
437 end 526 end
438 527
439 if description then 528 if description then
440 slashError = slashError .. "\n" .. description; 529 slashError = slashError .. "\n" .. description;
441 end
442 end
443
444 function InventoriumCommandHandler(message)
445 local cmd, arg = string.split(" ", (message or ""), 2);
446 cmd = string.lower(cmd);
447
448 if slashArgs[cmd] then
449 slashArgs[cmd](addon, arg);
450 else
451 print(slashError);
452 end 530 end
453 end 531 end
454 532
455 function addon:Load() 533 function addon:Load()
456 if not AceConfigDialog and not AceConfigRegistry then 534 if not AceConfigDialog and not AceConfigRegistry then
590 type = "description", 668 type = "description",
591 name = function() 669 name = function()
592 local t = "Here you can set general settings. The settings entered here will be used when you choose not to override the settings within an individual group.\n\n"; 670 local t = "Here you can set general settings. The settings entered here will be used when you choose not to override the settings within an individual group.\n\n";
593 671
594 local currentAddon, selectedAddonName = addon:GetItemCountAddon(); 672 local currentAddon, selectedAddonName = addon:GetItemCountAddon();
595 local preferedAddon = self.db.global.defaults.itemCountAddon; 673 local preferedAddon = self.db.profile.defaults.itemCountAddon;
596 674
597 if currentAddon then 675 if currentAddon then
598 --GetCharacterCount 676 --GetCharacterCount
599 --self.supportedAddons.itemCount[selectedExternalAddon] 677 --self.supportedAddons.itemCount[selectedExternalAddon]
600 t = t .. "Currently using |cfffed000" .. selectedAddonName .. "|r as your item count addon. This addon is " .. ((currentAddon.IsEnabled() and "|cff00ff00enabled|r") or "|cffff0000disabled|r") .. "."; 678 t = t .. "Currently using |cfffed000" .. selectedAddonName .. "|r as your item count addon. This addon is " .. ((currentAddon.IsEnabled() and "|cff00ff00enabled|r") or "|cffff0000disabled|r") .. ".";
631 temp[name] = name; 709 temp[name] = name;
632 end 710 end
633 711
634 return temp; 712 return temp;
635 end, 713 end,
636 get = function() return self.db.global.defaults.auctionPricingAddon; end, 714 get = function() return self.db.profile.defaults.auctionPricingAddon; end,
637 set = function(i, v) 715 set = function(i, v)
638 self.db.global.defaults.auctionPricingAddon = v; 716 self.db.profile.defaults.auctionPricingAddon = v;
639 717
640 if self.supportedAddons.auctionPricing[v].OnSelect then 718 if self.supportedAddons.auctionPricing[v].OnSelect then
641 self.supportedAddons.auctionPricing[v].OnSelect(); 719 self.supportedAddons.auctionPricing[v].OnSelect();
642 end 720 end
643 end, 721 end,
653 temp[name] = name; 731 temp[name] = name;
654 end 732 end
655 733
656 return temp; 734 return temp;
657 end, 735 end,
658 get = function() return self.db.global.defaults.itemCountAddon; end, 736 get = function() return self.db.profile.defaults.itemCountAddon; end,
659 set = function(i, v) 737 set = function(i, v)
660 self.db.global.defaults.itemCountAddon = v; 738 self.db.profile.defaults.itemCountAddon = v;
661 739
662 if self.supportedAddons.itemCount[v].OnSelect then 740 if self.supportedAddons.itemCount[v].OnSelect then
663 self.supportedAddons.itemCount[v].OnSelect(); 741 self.supportedAddons.itemCount[v].OnSelect();
664 end 742 end
665 end, 743 end,
675 temp[name] = name; 753 temp[name] = name;
676 end 754 end
677 755
678 return temp; 756 return temp;
679 end, 757 end,
680 get = function() return self.db.global.defaults.craftingAddon; end, 758 get = function() return self.db.profile.defaults.craftingAddon; end,
681 set = function(i, v) 759 set = function(i, v)
682 self.db.global.defaults.craftingAddon = v; 760 self.db.profile.defaults.craftingAddon = v;
683 761
684 if self.supportedAddons.crafting[v].OnSelect then 762 if self.supportedAddons.crafting[v].OnSelect then
685 self.supportedAddons.crafting[v].OnSelect(); 763 self.supportedAddons.crafting[v].OnSelect();
686 end 764 end
687 end, 765 end,
695 ["Bag"] = "Bag", 773 ["Bag"] = "Bag",
696 ["Bank"] = "Bank", 774 ["Bank"] = "Bank",
697 ["Auction House"] = "Auction House", 775 ["Auction House"] = "Auction House",
698 ["Mailbox"] = "Mailbox", 776 ["Mailbox"] = "Mailbox",
699 }, 777 },
700 get = function(i, v) return self.db.global.defaults.localItemData and self.db.global.defaults.localItemData[v]; end, 778 get = function(i, v) return self.db.profile.defaults.localItemData and self.db.profile.defaults.localItemData[v]; end,
701 set = function(i, v, e) self.db.global.defaults.localItemData[v] = e or nil; end, 779 set = function(i, v, e) self.db.profile.defaults.localItemData[v] = e or nil; end,
702 --dialogControl = "Dropdown", -- this is not standard, normal multiselect control gives us a list of all chars with toggle-boxes. UGLY! We want a multiselect-box instead. 780 --dialogControl = "Dropdown", -- this is not standard, normal multiselect control gives us a list of all chars with toggle-boxes. UGLY! We want a multiselect-box instead.
703 }, 781 },
704 }, 782 },
705 }, 783 },
706 minimumStock = { 784 minimumStock = {
726 max = 100000, 804 max = 100000,
727 softMax = 100, 805 softMax = 100,
728 step = 1, 806 step = 1,
729 name = "Minimum local stock", 807 name = "Minimum local stock",
730 desc = "You can manually enter a value between 100 and 100.000 in the text box below if the provided range is insufficient.", 808 desc = "You can manually enter a value between 100 and 100.000 in the text box below if the provided range is insufficient.",
731 get = function() return self.db.global.defaults.minimumLocalStock; end, 809 get = function() return self.db.profile.defaults.minLocalStock; end,
732 set = function(i, v) self.db.global.defaults.minimumLocalStock = v; end, 810 set = function(i, v) self.db.profile.defaults.minLocalStock = v; end,
733 }, 811 },
734 alertBelowLocalMinimum = { 812 alertBelowLocalMinimum = {
735 order = 11, 813 order = 11,
736 type = "toggle", 814 type = "toggle",
737 name = "Alert when below local minimum (NYI)", 815 name = "Alert when below local minimum (NYI)",
738 desc = "Show an alert when this item gets below this threshold.", 816 desc = "Show an alert when this item gets below this threshold.",
739 get = function() return self.db.global.defaults.alertBelowLocalMinimum; end, 817 get = function() return self.db.profile.defaults.alertBelowLocalMinimum; end,
740 set = function(i, v) self.db.global.defaults.alertBelowLocalMinimum = v; end, 818 set = function(i, v) self.db.profile.defaults.alertBelowLocalMinimum = v; end,
741 }, 819 },
742 minGlobalStock = { 820 minGlobalStock = {
743 order = 20, 821 order = 20,
744 type = "range", 822 type = "range",
745 min = 0, 823 min = 0,
746 max = 100000, 824 max = 100000,
747 softMax = 100, 825 softMax = 100,
748 step = 1, 826 step = 1,
749 name = "Minimum global stock", 827 name = "Minimum global stock",
750 desc = "You can manually enter a value between 100 and 100.000 in the text box below if the provided range is insufficient.", 828 desc = "You can manually enter a value between 100 and 100.000 in the text box below if the provided range is insufficient.",
751 get = function() return self.db.global.defaults.minimumStock; end, 829 get = function() return self.db.profile.defaults.minGlobalStock; end,
752 set = function(i, v) self.db.global.defaults.minimumStock = v; end, 830 set = function(i, v) self.db.profile.defaults.minGlobalStock = v; end,
753 }, 831 },
754 alertBelowGlobalMinimum = { 832 alertBelowGlobalMinimum = {
755 order = 21, 833 order = 21,
756 type = "toggle", 834 type = "toggle",
757 name = "Alert when below global minimum (NYI)", 835 name = "Alert when below global minimum (NYI)",
758 desc = "Show an alert when this item gets below this threshold.", 836 desc = "Show an alert when this item gets below this threshold.",
759 get = function() return self.db.global.defaults.alertBelowMinimum; end, 837 get = function() return self.db.profile.defaults.alertBelowGlobalMinimum; end,
760 set = function(i, v) self.db.global.defaults.alertBelowMinimum = v; end, 838 set = function(i, v) self.db.profile.defaults.alertBelowGlobalMinimum = v; end,
761 }, 839 },
762 summaryThresholdShow = { 840 summaryThresholdShow = {
763 order = 30, 841 order = 30,
764 type = "range", 842 type = "range",
765 min = 0, 843 min = 0,
767 softMax = 100, 845 softMax = 100,
768 step = 0.05, 846 step = 0.05,
769 isPercent = true, 847 isPercent = true,
770 name = "Show in summary when below", 848 name = "Show in summary when below",
771 desc = "Show items in the summary when below this percentage of the minimum stock. This can be either below the minimum or the global stock.\n\nYou can manually enter a value between 1.000% and 10.000% in the edit box if the provided range is insufficient.", 849 desc = "Show items in the summary when below this percentage of the minimum stock. This can be either below the minimum or the global stock.\n\nYou can manually enter a value between 1.000% and 10.000% in the edit box if the provided range is insufficient.",
772 get = function() return self.db.global.defaults.summaryThresholdShow; end, 850 get = function() return self.db.profile.defaults.summaryThresholdShow; end,
773 set = function(i, v) self.db.global.defaults.summaryThresholdShow = v; end, 851 set = function(i, v) self.db.profile.defaults.summaryThresholdShow = v; end,
774 }, 852 },
775 trackAtCharacters = { 853 trackAtCharacters = {
776 order = 40, 854 order = 40,
777 type = "multiselect", 855 type = "multiselect",
778 name = "Track at", 856 name = "Track at",
783 temp[charName] = charName; 861 temp[charName] = charName;
784 end 862 end
785 863
786 return temp; 864 return temp;
787 end, 865 end,
788 get = function(i, v) return self.db.global.defaults.trackAtCharacters[v]; end, 866 get = function(i, v) return self.db.profile.defaults.trackAtCharacters[v]; end,
789 set = function(i, v, e) self.db.global.defaults.trackAtCharacters[v] = e or nil; end, 867 set = function(i, v, e) self.db.profile.defaults.trackAtCharacters[v] = e or nil; end,
790 --dialogControl = "Dropdown", -- this is not standard, normal multiselect control gives us a list of all chars with toggle-boxes. UGLY! We want a multiselect-box instead. 868 --dialogControl = "Dropdown", -- this is not standard, normal multiselect control gives us a list of all chars with toggle-boxes. UGLY! We want a multiselect-box instead.
791 }, 869 },
792 }, 870 },
793 }, 871 },
794 refill = { 872 refill = {
801 order = 0, 879 order = 0,
802 type = "description", 880 type = "description",
803 name = function() 881 name = function()
804 local r = "Here you can specify the default amount of items to which you wish to restock when you are collecting new items. This may be higher than the minimum stock. The settings entered here will be used when you choose not to override the settings within an individual group.\n\n"; 882 local r = "Here you can specify the default amount of items to which you wish to restock when you are collecting new items. This may be higher than the minimum stock. The settings entered here will be used when you choose not to override the settings within an individual group.\n\n";
805 883
806 r = r .. "When restocking the target amount is |cfffed000" .. self.db.global.defaults.restockTarget .. "|r of every item. Not queueing craftable items when only missing |cfffed000" .. floor( self.db.global.defaults.minCraftingQueue * self.db.global.defaults.restockTarget ) .. "|r (|cfffed000" .. ( self.db.global.defaults.minCraftingQueue * 100 ) .. "%|r) of the restock target."; 884 r = r .. "When restocking the target amount is |cfffed000" .. self.db.profile.defaults.restockTarget .. "|r of every item. Not queueing craftable items when only missing |cfffed000" .. floor( self.db.profile.defaults.minCraftingQueue * self.db.profile.defaults.restockTarget ) .. "|r (|cfffed000" .. ( self.db.profile.defaults.minCraftingQueue * 100 ) .. "%|r) of the restock target.";
807 885
808 return r; 886 return r;
809 end, 887 end,
810 }, 888 },
811 header = { 889 header = {
820 max = 100000, 898 max = 100000,
821 softMax = 100, 899 softMax = 100,
822 step = 1, 900 step = 1,
823 name = "Restock target", 901 name = "Restock target",
824 desc = "You can manually enter a value between 100 and 100.000 in the edit box if the provided range is insufficient.", 902 desc = "You can manually enter a value between 100 and 100.000 in the edit box if the provided range is insufficient.",
825 get = function() return self.db.global.defaults.restockTarget; end, 903 get = function() return self.db.profile.defaults.restockTarget; end,
826 set = function(i, v) self.db.global.defaults.restockTarget = v; end, 904 set = function(i, v) self.db.profile.defaults.restockTarget = v; end,
827 }, 905 },
828 minCraftingQueue = { 906 minCraftingQueue = {
829 order = 20, 907 order = 20,
830 type = "range", 908 type = "range",
831 min = 0, 909 min = 0,
832 max = 1, 910 max = 1,
833 step = 0.01, -- 1% 911 step = 0.01, -- 1%
834 isPercent = true, 912 isPercent = true,
835 name = "Don't queue if I only miss", 913 name = "Don't queue if I only miss",
836 desc = "Don't add a craftable item to the queue if I only miss this much or less of the restock target.\n\nExample: if your restock target is set to 60 and this is set to 5%, an item won't be queued unless you are missing more than 3 of it.", 914 desc = "Don't add a craftable item to the queue if I only miss this much or less of the restock target.\n\nExample: if your restock target is set to 60 and this is set to 5%, an item won't be queued unless you are missing more than 3 of it.",
837 get = function() return self.db.global.defaults.minCraftingQueue; end, 915 get = function() return self.db.profile.defaults.minCraftingQueue; end,
838 set = function(i, v) self.db.global.defaults.minCraftingQueue = v; end, 916 set = function(i, v) self.db.profile.defaults.minCraftingQueue = v; end,
839 }, 917 },
840 bonusQueue = { 918 bonusQueue = {
841 order = 30, 919 order = 30,
842 type = "range", 920 type = "range",
843 min = 0, 921 min = 0,
844 max = 10, -- 1000% 922 max = 10, -- 1000%
845 step = 0.01, -- 1% 923 step = 0.01, -- 1%
846 isPercent = true, 924 isPercent = true,
847 name = "Bonus queue", 925 name = "Bonus queue",
848 desc = "Get additional items when there are none left.\n\nExample: if your restock target is set to 60 and this is set to 10%, you will get 66 items instead of just 60 if you end up with none left while queueing.", 926 desc = "Get additional items when there are none left.\n\nExample: if your restock target is set to 60 and this is set to 10%, you will get 66 items instead of just 60 if you end up with none left while queueing.",
849 get = function() return self.db.global.defaults.bonusQueue; end, 927 get = function() return self.db.profile.defaults.bonusQueue; end,
850 set = function(i, v) self.db.global.defaults.bonusQueue = v; end, 928 set = function(i, v) self.db.profile.defaults.bonusQueue = v; end,
851 }, 929 },
852 priceThreshold = { 930 priceThreshold = {
853 order = 40, 931 order = 40,
854 type = "input", 932 type = "input",
855 name = "Price threshold", 933 name = "Price threshold",
856 desc = "Only queue craftable items when they are worth at least this much according to your auction house addon.\n\nSet to 0 to ignore auction prices.", 934 desc = "Only queue craftable items when they are worth at least this much according to your auction house addon.\n\nSet to 0 to ignore auction prices.",
857 validate = function(info, value) return self:ValidateReadableMoney(info, value); end, 935 validate = function(info, value) return self:ValidateReadableMoney(info, value); end,
858 get = function() return self:ReadableMoney(self.db.global.defaults.priceThreshold); end, 936 get = function() return self:ReadableMoney(self.db.profile.defaults.priceThreshold); end,
859 set = function(i, v) self.db.global.defaults.priceThreshold = self:ReadableMoneyToCopper(v); end, 937 set = function(i, v) self.db.profile.defaults.priceThreshold = self:ReadableMoneyToCopper(v); end,
860 }, 938 },
861 summaryHidePriceThreshold = { 939 summaryHidePriceThreshold = {
862 order = 50, 940 order = 50,
863 type = "toggle", 941 type = "toggle",
864 name = "Hide when below threshold", 942 name = "Hide when below threshold",
865 desc = "Hide items from the summary when their value is below the set price threshold.", 943 desc = "Hide items from the summary when their value is below the set price threshold.",
866 get = function() return self.db.global.defaults.summaryHidePriceThreshold; end, 944 get = function() return self.db.profile.defaults.summaryHidePriceThreshold; end,
867 set = function(i, v) self.db.global.defaults.summaryHidePriceThreshold = v; end, 945 set = function(i, v) self.db.profile.defaults.summaryHidePriceThreshold = v; end,
868 }, 946 },
869 alwaysGetAuctionValue = { 947 alwaysGetAuctionValue = {
870 order = 60, 948 order = 60,
871 type = "toggle", 949 type = "toggle",
872 name = "Always show auction value", 950 name = "Always show auction value",
873 desc = "Always cache and show the auction value of items, even if the price threshold is set to 0|cffeda55fc|r.", 951 desc = "Always cache and show the auction value of items, even if the price threshold is set to 0|cffeda55fc|r.",
874 get = function() return self.db.global.defaults.alwaysGetAuctionValue; end, 952 get = function() return self.db.profile.defaults.alwaysGetAuctionValue; end,
875 set = function(i, v) self.db.global.defaults.alwaysGetAuctionValue = v; end, 953 set = function(i, v) self.db.profile.defaults.alwaysGetAuctionValue = v; end,
876 }, 954 },
877 }, 955 },
878 }, 956 },
879 colorCodes = { 957 colorCodes = {
880 order = 30, 958 order = 30,
899 max = 1, 977 max = 1,
900 step = 0.01, 978 step = 0.01,
901 isPercent = true, 979 isPercent = true,
902 name = "|cff00ff00Green|r", 980 name = "|cff00ff00Green|r",
903 desc = "Show quantity in green when at least this much of the minimum stock is available.", 981 desc = "Show quantity in green when at least this much of the minimum stock is available.",
904 get = function() return self.db.global.defaults.colors.green; end, 982 get = function() return self.db.profile.defaults.colors.green; end,
905 set = function(i, v) self.db.global.defaults.colors.green = v; end, 983 set = function(i, v) self.db.profile.defaults.colors.green = v; end,
906 }, 984 },
907 yellow = { 985 yellow = {
908 order = 20, 986 order = 20,
909 type = "range", 987 type = "range",
910 min = 0, 988 min = 0,
911 max = 1, 989 max = 1,
912 step = 0.01, 990 step = 0.01,
913 isPercent = true, 991 isPercent = true,
914 name = "|cffffff00Yellow|r", 992 name = "|cffffff00Yellow|r",
915 desc = "Show quantity in yellow when at least this much of the minimum stock is available.", 993 desc = "Show quantity in yellow when at least this much of the minimum stock is available.",
916 get = function() return self.db.global.defaults.colors.yellow; end, 994 get = function() return self.db.profile.defaults.colors.yellow; end,
917 set = function(i, v) self.db.global.defaults.colors.yellow = v; end, 995 set = function(i, v) self.db.profile.defaults.colors.yellow = v; end,
918 }, 996 },
919 orange = { 997 orange = {
920 order = 30, 998 order = 30,
921 type = "range", 999 type = "range",
922 min = 0, 1000 min = 0,
923 max = 1, 1001 max = 1,
924 step = 0.01, 1002 step = 0.01,
925 isPercent = true, 1003 isPercent = true,
926 name = "|cffff9933Orange|r", 1004 name = "|cffff9933Orange|r",
927 desc = "Show quantity in orange when at least this much of the minimum stock is available.", 1005 desc = "Show quantity in orange when at least this much of the minimum stock is available.",
928 get = function() return self.db.global.defaults.colors.orange; end, 1006 get = function() return self.db.profile.defaults.colors.orange; end,
929 set = function(i, v) self.db.global.defaults.colors.orange = v; end, 1007 set = function(i, v) self.db.profile.defaults.colors.orange = v; end,
930 }, 1008 },
931 red = { 1009 red = {
932 order = 40, 1010 order = 40,
933 type = "range", 1011 type = "range",
934 min = 0, 1012 min = 0,
935 max = 1, 1013 max = 1,
936 step = 0.01, 1014 step = 0.01,
937 isPercent = true, 1015 isPercent = true,
938 name = "|cffff0000Red|r", 1016 name = "|cffff0000Red|r",
939 desc = "Show quantity in red when at least this much of the minimum stock is available.", 1017 desc = "Show quantity in red when at least this much of the minimum stock is available.",
940 get = function() return self.db.global.defaults.colors.red; end, 1018 get = function() return self.db.profile.defaults.colors.red; end,
941 set = function(i, v) self.db.global.defaults.colors.red = v; end, 1019 set = function(i, v) self.db.profile.defaults.colors.red = v; end,
942 }, 1020 },
943 }, 1021 },
944 }, 1022 },
945 }, 1023 },
946 }; 1024 };
959 -- If this override was disabled and a saved variable name was provided, set it to nil rather than false 1037 -- If this override was disabled and a saved variable name was provided, set it to nil rather than false
960 1038
961 value = nil; 1039 value = nil;
962 1040
963 -- If this is an override toggler then also set the related field to nil 1041 -- If this is an override toggler then also set the related field to nil
964 addon.db.global.groups[groupName][info.arg] = nil; 1042 addon.db.profile.groups[groupName][info.arg] = nil;
965 elseif value and info.arg then 1043 elseif value and info.arg then
966 -- If this override is now enabled, we need to copy the default into this field (unless it is not nil (which is supposed to be impossible), in which case we'll use the already selected value) 1044 -- If this override is now enabled, we need to copy the default into this field (unless it is not nil (which is supposed to be impossible), in which case we'll use the already selected value)
967 1045
968 addon.db.global.groups[groupName][info.arg] = addon:GetOptionByKey(groupName, info.arg); 1046 addon.db.profile.groups[groupName][info.arg] = addon:GetOptionByKey(groupName, info.arg);
969 end 1047 end
970 end 1048 end
971 1049
972 if multiSelectEnabled ~= nil then 1050 if multiSelectEnabled ~= nil then
973 -- The saved vars for a multiselect will always be an array, it may not yet exist in which case it must be created. 1051 -- The saved vars for a multiselect will always be an array, it may not yet exist in which case it must be created.
974 if not addon.db.global.groups[groupName][optionName] then 1052 if not addon.db.profile.groups[groupName][optionName] then
975 addon.db.global.groups[groupName][optionName] = {}; 1053 addon.db.profile.groups[groupName][optionName] = {};
976 end 1054 end
977 1055
978 addon.db.global.groups[groupName][optionName][value] = multiSelectEnabled or nil; 1056 addon.db.profile.groups[groupName][optionName][value] = multiSelectEnabled or nil;
979 else 1057 else
980 addon.db.global.groups[groupName][optionName] = value; 1058 addon.db.profile.groups[groupName][optionName] = value;
981 end 1059 end
982 end 1060 end
983 1061
984 function addon:GetOptionByKey(groupName, optionName, noDefault) 1062 function addon:GetOptionByKey(groupName, optionName, noDefault)
985 if groupName and self.db.global.groups[groupName] and self.db.global.groups[groupName][optionName] ~= nil then 1063 if groupName and self.db.profile.groups[groupName] and self.db.profile.groups[groupName][optionName] ~= nil then
986 -- If this option exists within the settings of this group 1064 -- If this option exists within the settings of this group
987 1065
988 return self.db.global.groups[groupName][optionName]; 1066 return self.db.profile.groups[groupName][optionName];
989 elseif groupName and self.db.global.groups[groupName] and self.db.global.groups[groupName].virtualGroup ~= "" and not noDefault then 1067 elseif groupName and self.db.profile.groups[groupName] and self.db.profile.groups[groupName].virtualGroup ~= "" and not noDefault then
990 -- If a virtual group was selected 1068 -- If a virtual group was selected
991 1069
992 return self:GetOptionByKey(self.db.global.groups[groupName].virtualGroup, optionName, noDefault); 1070 return self:GetOptionByKey(self.db.profile.groups[groupName].virtualGroup, optionName, noDefault);
993 elseif self.db.global.defaults[optionName] and not noDefault then 1071 elseif self.db.profile.defaults[optionName] and not noDefault then
994 return self.db.global.defaults[optionName]; 1072 return self.db.profile.defaults[optionName];
995 else 1073 else
996 return nil; 1074 return nil;
997 end 1075 end
998 end 1076 end
999 1077
1012 1090
1013 local function GetMultiOption(info, value) 1091 local function GetMultiOption(info, value)
1014 local groupName = groupIdToName[info[2]]; 1092 local groupName = groupIdToName[info[2]];
1015 local optionName = info[#info]; 1093 local optionName = info[#info];
1016 1094
1017 if addon.db.global.groups[groupName][optionName] ~= nil then 1095 if addon.db.profile.groups[groupName][optionName] ~= nil then
1018 return addon.db.global.groups[groupName][optionName][value]; 1096 return addon.db.profile.groups[groupName][optionName][value];
1019 elseif addon.db.global.defaults[optionName] then 1097 elseif addon.db.profile.defaults[optionName] then
1020 return addon.db.global.defaults[optionName][value]; 1098 return addon.db.profile.defaults[optionName][value];
1021 else 1099 else
1022 return nil; 1100 return nil;
1023 end 1101 end
1024 end 1102 end
1025 1103
1035 end 1113 end
1036 1114
1037 local function ValidateGroupName(_, value) 1115 local function ValidateGroupName(_, value)
1038 value = string.lower(string.trim(value or "")); 1116 value = string.lower(string.trim(value or ""));
1039 1117
1040 for name, _ in pairs(addon.db.global.groups) do 1118 for name, _ in pairs(addon.db.profile.groups) do
1041 if string.lower(name) == value then 1119 if string.lower(name) == value then
1042 return ("A group named \"%s\" already exists."):format(name); 1120 return ("A group named \"%s\" already exists."):format(name);
1043 end 1121 end
1044 end 1122 end
1045 1123
1098 }; 1176 };
1099 1177
1100 local function UpdateAddItemList(info) 1178 local function UpdateAddItemList(info)
1101 local groupName = groupIdToName[info[2]]; 1179 local groupName = groupIdToName[info[2]];
1102 1180
1103 if not addon.db.global.groups[groupName].items then 1181 if not addon.db.profile.groups[groupName].items then
1104 addon.db.global.groups[groupName].items = {}; 1182 addon.db.profile.groups[groupName].items = {};
1105 end 1183 end
1106 1184
1107 -- Merge all items from all groups together 1185 -- Merge all items from all groups together
1108 local items = {}; 1186 local items = {};
1109 for groupName, values in pairs(addon.db.global.groups) do 1187 for groupName, values in pairs(addon.db.profile.groups) do
1110 if values.items then 1188 if values.items then
1111 for itemId, _ in pairs(values.items) do 1189 for itemId, _ in pairs(values.items) do
1112 items[itemId] = true; 1190 items[itemId] = true;
1113 end 1191 end
1114 end 1192 end
1174 end 1252 end
1175 1253
1176 local function UpdateRemoveItemList(info) 1254 local function UpdateRemoveItemList(info)
1177 local groupName = groupIdToName[info[2]]; 1255 local groupName = groupIdToName[info[2]];
1178 1256
1179 if not addon.db.global.groups[groupName].items then 1257 if not addon.db.profile.groups[groupName].items then
1180 addon.db.global.groups[groupName].items = {}; 1258 addon.db.profile.groups[groupName].items = {};
1181 end 1259 end
1182 1260
1183 local ref = options.args.groups.args[info[2]].args.remove.args.list.args; 1261 local ref = options.args.groups.args[info[2]].args.remove.args.list.args;
1184 1262
1185 -- Unset all 1263 -- Unset all
1186 for itemId, _ in pairs(ref) do 1264 for itemId, _ in pairs(ref) do
1187 ref[itemId] = nil; 1265 ref[itemId] = nil;
1188 end 1266 end
1189 1267
1190 -- Parse items in group and show these 1268 -- Parse items in group and show these
1191 for itemId, _ in pairs(addon.db.global.groups[groupName].items) do 1269 for itemId, _ in pairs(addon.db.profile.groups[groupName].items) do
1192 ref[itemId] = tblRemoveItemTemplate; 1270 ref[itemId] = tblRemoveItemTemplate;
1193 end 1271 end
1194 end 1272 end
1195 1273
1196 function addon:GetItemId(itemLink) 1274 function addon:GetItemId(itemLink)
1294 end, 1372 end,
1295 set = function(info, value) 1373 set = function(info, value)
1296 local groupName = groupIdToName[info[2]]; 1374 local groupName = groupIdToName[info[2]];
1297 local optionName = info[#info]; 1375 local optionName = info[#info];
1298 1376
1299 addon.db.global.groups[groupName][optionName] = value ~= "" and value; 1377 addon.db.profile.groups[groupName][optionName] = value ~= "" and value;
1300 1378
1301 if addon.supportedAddons.auctionPricing[value].OnSelect then 1379 if addon.supportedAddons.auctionPricing[value].OnSelect then
1302 addon.supportedAddons.auctionPricing[value].OnSelect(); 1380 addon.supportedAddons.auctionPricing[value].OnSelect();
1303 end 1381 end
1304 end, 1382 end,
1326 end, 1404 end,
1327 set = function(info, value) 1405 set = function(info, value)
1328 local groupName = groupIdToName[info[2]]; 1406 local groupName = groupIdToName[info[2]];
1329 local optionName = info[#info]; 1407 local optionName = info[#info];
1330 1408
1331 addon.db.global.groups[groupName][optionName] = value ~= "" and value; 1409 addon.db.profile.groups[groupName][optionName] = value ~= "" and value;
1332 1410
1333 if addon.supportedAddons.itemCount[value].OnSelect then 1411 if addon.supportedAddons.itemCount[value].OnSelect then
1334 addon.supportedAddons.itemCount[value].OnSelect(); 1412 addon.supportedAddons.itemCount[value].OnSelect();
1335 end 1413 end
1336 end, 1414 end,
1358 end, 1436 end,
1359 set = function(info, value) 1437 set = function(info, value)
1360 local groupName = groupIdToName[info[2]]; 1438 local groupName = groupIdToName[info[2]];
1361 local optionName = info[#info]; 1439 local optionName = info[#info];
1362 1440
1363 addon.db.global.groups[groupName][optionName] = value ~= "" and value; 1441 addon.db.profile.groups[groupName][optionName] = value ~= "" and value;
1364 1442
1365 if addon.supportedAddons.crafting[value].OnSelect then 1443 if addon.supportedAddons.crafting[value].OnSelect then
1366 addon.supportedAddons.crafting[value].OnSelect(); 1444 addon.supportedAddons.crafting[value].OnSelect();
1367 end 1445 end
1368 end, 1446 end,
1399 local groupName = groupIdToName[info[2]]; 1477 local groupName = groupIdToName[info[2]];
1400 1478
1401 local temp = {}; 1479 local temp = {};
1402 1480
1403 temp[""] = ""; 1481 temp[""] = "";
1404 for name, values in pairs(addon.db.global.groups) do 1482 for name, values in pairs(addon.db.profile.groups) do
1405 if values.isVirtual and name ~= groupName then 1483 if values.isVirtual and name ~= groupName then
1406 temp[name] = name; 1484 temp[name] = name;
1407 end 1485 end
1408 end 1486 end
1409 1487
1411 end, 1489 end,
1412 set = function(info, value) 1490 set = function(info, value)
1413 local groupName = groupIdToName[info[2]]; 1491 local groupName = groupIdToName[info[2]];
1414 local optionName = info[#info]; 1492 local optionName = info[#info];
1415 1493
1416 addon.db.global.groups[groupName][optionName] = value ~= "" and value; 1494 addon.db.profile.groups[groupName][optionName] = value ~= "" and value;
1417 end, 1495 end,
1418 disabled = false, 1496 disabled = false,
1419 }, 1497 },
1420 }, 1498 },
1421 }, 1499 },
1704 desc = "Change the name of this group to something else. You can also use item links here as you wish.", 1782 desc = "Change the name of this group to something else. You can also use item links here as you wish.",
1705 validate = ValidateGroupName, 1783 validate = ValidateGroupName,
1706 set = function(info, value) 1784 set = function(info, value)
1707 local oldGroupName = groupIdToName[info[2]]; 1785 local oldGroupName = groupIdToName[info[2]];
1708 1786
1709 addon.db.global.groups[value] = CopyTable(addon.db.global.groups[oldGroupName]); 1787 addon.db.profile.groups[value] = CopyTable(addon.db.profile.groups[oldGroupName]);
1710 addon.db.global.groups[oldGroupName] = nil; 1788 addon.db.profile.groups[oldGroupName] = nil;
1711 1789
1712 groupIdToName[info[2]] = value; 1790 groupIdToName[info[2]] = value;
1713 groupIdToName[value] = true; 1791 groupIdToName[value] = true;
1714 groupIdToName[oldGroupName] = nil; 1792 groupIdToName[oldGroupName] = nil;
1715 1793
1726 desc = "Duplicate this group. You can also use item links here as you wish.\n\nAll item data will be erased.", 1804 desc = "Duplicate this group. You can also use item links here as you wish.\n\nAll item data will be erased.",
1727 validate = ValidateGroupName, 1805 validate = ValidateGroupName,
1728 set = function(info, value) 1806 set = function(info, value)
1729 local oldGroupName = groupIdToName[info[2]]; 1807 local oldGroupName = groupIdToName[info[2]];
1730 1808
1731 addon.db.global.groups[value] = CopyTable(addon.db.global.groups[oldGroupName]); 1809 addon.db.profile.groups[value] = CopyTable(addon.db.profile.groups[oldGroupName]);
1732 1810
1733 -- Reset item data (duplicate items me no want) 1811 -- Reset item data (duplicate items me no want)
1734 addon.db.global.groups[value].items = nil; 1812 addon.db.profile.groups[value].items = nil;
1735 1813
1736 addon:FillGroupOptions(); 1814 addon:FillGroupOptions();
1737 end, 1815 end,
1738 get = false, 1816 get = false,
1739 }, 1817 },
1745 confirm = true, 1823 confirm = true,
1746 confirmText = "Are you sure you wish to |cffff0000DELETE|r this group? This action is not reversable!", 1824 confirmText = "Are you sure you wish to |cffff0000DELETE|r this group? This action is not reversable!",
1747 func = function(info) 1825 func = function(info)
1748 local groupName = groupIdToName[info[2]]; 1826 local groupName = groupIdToName[info[2]];
1749 1827
1750 addon.db.global.groups[groupName] = nil; 1828 addon.db.profile.groups[groupName] = nil;
1751 1829
1752 addon:FillGroupOptions(); 1830 addon:FillGroupOptions();
1753 end, 1831 end,
1754 }, 1832 },
1755 }, 1833 },
1770 set = false, 1848 set = false,
1771 get = function(info) 1849 get = function(info)
1772 local groupName = groupIdToName[info[2]]; 1850 local groupName = groupIdToName[info[2]];
1773 1851
1774 -- We want to include the group name, so we copy the table then set another value 1852 -- We want to include the group name, so we copy the table then set another value
1775 local temp = CopyTable(addon.db.global.groups[groupName]); 1853 local temp = CopyTable(addon.db.profile.groups[groupName]);
1776 temp.name = groupName; 1854 temp.name = groupName;
1777 temp.trackAtCharacters = nil; 1855 temp.trackAtCharacters = nil;
1778 temp.overrideTrackAtCharacters = nil; 1856 temp.overrideTrackAtCharacters = nil;
1779 1857
1780 if not AceSerializer then 1858 if not AceSerializer then
1881 local groupName = groupIdToName[info[2]]; 1959 local groupName = groupIdToName[info[2]];
1882 1960
1883 print(("Importing items from the premade group \"|cfffed000%s|r\"."):format(value)); 1961 print(("Importing items from the premade group \"|cfffed000%s|r\"."):format(value));
1884 1962
1885 -- Remember we imported this group and it's version so if it is ever changed, people can be notified 1963 -- Remember we imported this group and it's version so if it is ever changed, people can be notified
1886 if not addon.db.global.groups[groupName].premadeGroups then 1964 if not addon.db.profile.groups[groupName].premadeGroups then
1887 addon.db.global.groups[groupName].premadeGroups = {}; 1965 addon.db.profile.groups[groupName].premadeGroups = {};
1888 end 1966 end
1889 addon.db.global.groups[groupName].premadeGroups[value] = addon.defaultGroups[value].version; 1967 addon.db.profile.groups[groupName].premadeGroups[value] = addon.defaultGroups[value].version;
1890 1968
1891 for itemId, version in pairs(addon.defaultGroups[value].items) do 1969 for itemId, version in pairs(addon.defaultGroups[value].items) do
1892 if version > 0 then 1970 if version > 0 then
1893 itemId = itemId and tonumber(itemId); 1971 itemId = itemId and tonumber(itemId);
1894 1972
2047 desc = "This is a list of all premade groups that were imported into this group. You will be notified when any of these premade groups have changed and you will be able to import these changes.\n\nSelect a group to stop reminding you of changes to the premade group (the item list will be unaffected). Doing so will require you to manually update this when new items are added to the game.", 2125 desc = "This is a list of all premade groups that were imported into this group. You will be notified when any of these premade groups have changed and you will be able to import these changes.\n\nSelect a group to stop reminding you of changes to the premade group (the item list will be unaffected). Doing so will require you to manually update this when new items are added to the game.",
2048 values = function(info) 2126 values = function(info)
2049 local groupName = groupIdToName[info[2]]; 2127 local groupName = groupIdToName[info[2]];
2050 2128
2051 local temp = {}; 2129 local temp = {};
2052 if addon.db.global.groups[groupName].premadeGroups then 2130 if addon.db.profile.groups[groupName].premadeGroups then
2053 for name, version in pairs(addon.db.global.groups[groupName].premadeGroups) do 2131 for name, version in pairs(addon.db.profile.groups[groupName].premadeGroups) do
2054 temp[name] = name; 2132 temp[name] = name;
2055 end 2133 end
2056 end 2134 end
2057 2135
2058 return temp; 2136 return temp;
2059 end, 2137 end,
2060 set = function(info, value) 2138 set = function(info, value)
2061 -- Remove premade group from this group 2139 -- Remove premade group from this group
2062 local groupName = groupIdToName[info[2]]; 2140 local groupName = groupIdToName[info[2]];
2063 2141
2064 addon.db.global.groups[groupName].premadeGroups[value] = nil; 2142 addon.db.profile.groups[groupName].premadeGroups[value] = nil;
2065 2143
2066 print(("No longer notifying you about changes made to the premade group named \"|cfffed000%s|r\"."):format(value)); 2144 print(("No longer notifying you about changes made to the premade group named \"|cfffed000%s|r\"."):format(value));
2067 end, 2145 end,
2068 get = false, 2146 get = false,
2069 disabled = function(info) 2147 disabled = function(info)
2070 local groupName = groupIdToName[info[2]]; 2148 local groupName = groupIdToName[info[2]];
2071 2149
2072 return (not addon.db.global.groups[groupName].premadeGroups); 2150 return (not addon.db.profile.groups[groupName].premadeGroups);
2073 end, 2151 end,
2074 }, 2152 },
2075 }, 2153 },
2076 }, 2154 },
2077 list = { 2155 list = {
2100 get = function(info) 2178 get = function(info)
2101 local groupName = groupIdToName[info[2]]; 2179 local groupName = groupIdToName[info[2]];
2102 2180
2103 local combinedItemIds; 2181 local combinedItemIds;
2104 -- Parse items in group and show these 2182 -- Parse items in group and show these
2105 for itemId, _ in pairs(addon.db.global.groups[groupName].items) do 2183 for itemId, _ in pairs(addon.db.profile.groups[groupName].items) do
2106 if not combinedItemIds then 2184 if not combinedItemIds then
2107 combinedItemIds = tostring(itemId); 2185 combinedItemIds = tostring(itemId);
2108 else 2186 else
2109 combinedItemIds = combinedItemIds .. (";%d"):format(itemId); 2187 combinedItemIds = combinedItemIds .. (";%d"):format(itemId);
2110 end 2188 end
2139 type = "input", 2217 type = "input",
2140 name = "Group name", 2218 name = "Group name",
2141 desc = "The name of the group. You can also use item links as you wish.", 2219 desc = "The name of the group. You can also use item links as you wish.",
2142 validate = ValidateGroupName, 2220 validate = ValidateGroupName,
2143 set = function(_, value) 2221 set = function(_, value)
2144 self.db.global.groups[value] = {}; 2222 self.db.profile.groups[value] = {};
2145 if currentGroupType == "Virtual" then 2223 if currentGroupType == "Virtual" then
2146 self.db.global.groups[value].isVirtual = true; 2224 self.db.profile.groups[value].isVirtual = true;
2147 end 2225 end
2148 2226
2149 addon:FillGroupOptions(); 2227 addon:FillGroupOptions();
2150 end, 2228 end,
2151 get = false, 2229 get = false,
2194 else 2272 else
2195 local name = temp.name; 2273 local name = temp.name;
2196 temp.name = nil; 2274 temp.name = nil;
2197 print(("Importing %s..."):format(name)); 2275 print(("Importing %s..."):format(name));
2198 2276
2199 -- Remove items that are already in another group 2277 if temp.items then
2200 for value, _ in pairs(temp.items) do 2278 -- Remove items that are already in another group
2201 local itemId = tonumber(value); 2279 for value, _ in pairs(temp.items) do
2202 2280 local itemId = tonumber(value);
2203 if not itemId then 2281
2204 print(("\"%s\" is not a number."):format(value)); 2282 if not itemId then
2205 temp.items[value] = nil; 2283 print(("\"%s\" is not a number."):format(value));
2206 elseif InGroup(itemId) then 2284 temp.items[value] = nil;
2207 print(("Skipping %s (#%d) as it is already in the group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, InGroup(itemId))); 2285 elseif InGroup(itemId) then
2208 temp.items[value] = nil; 2286 print(("Skipping %s (#%d) as it is already in the group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, InGroup(itemId)));
2209 else 2287 temp.items[value] = nil;
2210 -- Ensure the keys are numeric 2288 else
2211 temp.items[value] = nil; 2289 -- Ensure the keys are numeric
2212 temp.items[itemId] = true; 2290 temp.items[value] = nil;
2291 temp.items[itemId] = true;
2292 end
2213 end 2293 end
2214 end 2294 end
2215 2295
2216 -- Ensure this data isn't received (this would be silly/buggy as exports from other accounts - with different characters - won't know what to do with this) 2296 -- Ensure this data isn't received (this would be silly/buggy as exports from other accounts - with different characters - won't know what to do with this)
2217 temp.trackAtCharacters = nil; 2297 temp.trackAtCharacters = nil;
2218 temp.overrideTrackAtCharacters = nil; 2298 temp.overrideTrackAtCharacters = nil;
2219 2299
2220 self.db.global.groups[name] = temp; 2300 self.db.profile.groups[name] = temp;
2221 end 2301 end
2222 end 2302 end
2223 2303
2224 self:FillGroupOptions(); 2304 self:FillGroupOptions();
2225 end, 2305 end,
2232 }; 2312 };
2233 end 2313 end
2234 2314
2235 function addon:FillGroupOptions() 2315 function addon:FillGroupOptions()
2236 for id, name in pairs(groupIdToName) do 2316 for id, name in pairs(groupIdToName) do
2237 if type(name) == "string" and not self.db.global.groups[name] then 2317 if type(name) == "string" and not self.db.profile.groups[name] then
2238 options.args.groups.args[id] = nil; 2318 options.args.groups.args[id] = nil;
2239 groupIdToName[id] = nil; 2319 groupIdToName[id] = nil;
2240 groupIdToName[name] = nil; 2320 groupIdToName[name] = nil;
2241 groupIsVirtual[id] = nil; 2321 groupIsVirtual[id] = nil;
2242 end 2322 end
2243 end 2323 end
2244 2324
2245 for name, values in pairs(self.db.global.groups) do 2325 for name, values in pairs(self.db.profile.groups) do
2246 if not groupIdToName[name] then 2326 if not groupIdToName[name] then
2247 options.args.groups.args[tostring(count)] = defaultGroup; 2327 options.args.groups.args[tostring(count)] = defaultGroup;
2248 2328
2249 groupIdToName[tostring(count)] = name; 2329 groupIdToName[tostring(count)] = name;
2250 groupIdToName[name] = true; 2330 groupIdToName[name] = true;