# HG changeset patch # User Zerotorescue # Date 1293026649 -3600 # Node ID d903b0a151d3cc6ffad670ff001176bd47a5504d # Parent 12c2b20ca8433bb1b76a434754135655800ee7d0 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. diff -r 12c2b20ca843 -r d903b0a151d3 Core.lua --- a/Core.lua Tue Dec 21 14:29:52 2010 +0100 +++ b/Core.lua Wed Dec 22 15:04:09 2010 +0100 @@ -4,16 +4,37 @@ local AceGUI = LibStub("AceGUI-3.0"); +--@debug@ +local addonRevision = 1; +--@end-debug@ +--[===[@non-debug@ +local addonRevision = @project-revision@; +--@end-non-debug@]===] + local AceConfigDialog, AceConfigRegistry, AceSerializer; local groupIdToName, groupIsVirtual, options = {}, {}, {}; local includeTradeSkillItems = 500; +local slashArgs = {}; +local slashError = "Wrong argument, the following arguments are available:"; + -- All modules must be able to retrieve our supported addons database, thus keep it public addon.supportedAddons = {}; addon.supportedAddons.auctionPricing = {}; addon.supportedAddons.itemCount = {}; addon.supportedAddons.crafting = {}; +local function CommandHandler(message) + local cmd, arg = string.split(" ", (message or ""), 2); + cmd = string.lower(cmd); + + if slashArgs[cmd] then + slashArgs[cmd](addon, arg); + else + print(slashError); + end +end + function addon:OnInitialize() self:Debug("OnInitialize"); @@ -21,16 +42,17 @@ local defaults = { global = { - groups = { - }, + version = nil, + }, + profile = { defaults = { auctionPricingAddon = "Auctioneer", itemCountAddon = "Altoholic", craftingAddon = "AdvancedTradeSkillWindow", - minimumLocalStock = 20, + minLocalStock = 20, alertBelowLocalMinimum = true, - minimumStock = 60, -- global stock - alertBelowMinimum = true, -- global stock + minGlobalStock = 60, + alertBelowGlobalMinimum = true, summaryThresholdShow = 10, restockTarget = 60, minCraftingQueue = 0.05, @@ -55,6 +77,8 @@ green = 0.95, }, }, + groups = { + }, }, factionrealm = { characters = { @@ -64,6 +88,70 @@ -- Register our saved variables database self.db = LibStub("AceDB-3.0"):New("InventoriumDB", defaults, true); + self.db.RegisterCallback(self, "OnProfileChanged", "RefreshConfig") + self.db.RegisterCallback(self, "OnProfileCopied", "RefreshConfig") + self.db.RegisterCallback(self, "OnProfileReset", "RefreshConfig") + + if not self.db.global.version or self.db.global.version < addonRevision then + -- Is our database outdated? Then patch it. + + if not self.db.global.version then + -- Old version was before version was saved, many changes were done in that revision + + print("Updating Inventorium database from version " .. (self.db.global.version or "Unknown") .. " to version " .. addonRevision .. "..."); + + if self.db.global and self.db.global.defaults then + print("Moving all global data into your current profile..."); + + -- All data mustn't be global but profile-based + self.db.profile.defaults = CopyTable(self.db.global.defaults); + self.db.profile.groups = CopyTable(self.db.global.groups); + + self.db.global.defaults = nil; + self.db.global.groups = nil; + + CommandHandler = function() + print("You must /reload once to finalize the database updates."); + end; + CommandHandler(); + end + + if self.db.profile.defaults.minimumStock then + print("Copying the minimum stock value into the minimum global stock..."); + + -- We added another stock option and renamed the old to be more obvious about what it means + self.db.profile.defaults.minGlobalStock = self.db.profile.defaults.minimumStock; + self.db.profile.defaults.minimumStock = nil; + end + + if self.db.profile.defaults.minimumLocalStock then + print("Renaming the minimum local stock property..."); + + -- We added another stock option and then renamed it + self.db.profile.defaults.minLocalStock = self.db.profile.defaults.minimumLocalStock; + self.db.profile.defaults.minimumLocalStock = nil; + end + + if self.db.profile.defaults.alertBelowMinimum then + print("Copying the alert below minimum value into the alert below global minimum value..."); + + -- We added another stock option and then renamed it + self.db.profile.defaults.alertBelowGlobalMinimum = self.db.profile.defaults.alertBelowMinimum; + self.db.profile.defaults.alertBelowMinimum = nil; + end + + -- Go through all groups to see if there's one with the above two renamed variables + for groupName, values in pairs(self.db.profile.groups) do + if values.minimumStock then + values.minGlobalStock = values.minimumStock; + values.minimumStock = nil; + end + end + end + + -- Remember the version of our database + self.db.global.version = addonRevision; + end -- SLASH COMMANDS @@ -74,7 +162,7 @@ -- Register our own slash commands SLASH_INVENTORIUM1 = "/inventorium"; SLASH_INVENTORIUM2 = "/im"; - SlashCmdList["INVENTORIUM"] = InventoriumCommandHandler; + SlashCmdList["INVENTORIUM"] = CommandHandler; -- Config command handling self:RegisterSlash(function(this) @@ -139,15 +227,19 @@ self.db.factionrealm.characters[playerName] = true; -- Default to tracking on all chars, untracking is a convenience, not tracking by default would probably get multiple issue reports. - self.db.global.defaults.trackAtCharacters[playerName] = true; + self.db.profile.defaults.trackAtCharacters[playerName] = true; end self:PremadeGroupsCheck(); end +function addon:RefreshConfig() + self:FillGroupOptions(); +end + local function InGroup(itemId) -- Go through all groups to see if this item is already somewhere - for groupName, values in pairs(addon.db.global.groups) do + for groupName, values in pairs(addon.db.profile.groups) do if values.items and values.items[itemId] then return groupName; end @@ -161,14 +253,14 @@ return false; end - if not addon.db.global.groups[groupName].items then - addon.db.global.groups[groupName].items = {}; + if not addon.db.profile.groups[groupName].items then + addon.db.profile.groups[groupName].items = {}; end -- Set this item - addon.db.global.groups[groupName].items[itemId] = true; + addon.db.profile.groups[groupName].items[itemId] = true; - if AceConfigRegistry then + if AceConfigRegistry then -- Now rebuild the list AceConfigRegistry:NotifyChange("InventoriumOptions"); end @@ -182,7 +274,7 @@ end -- Unset this item - addon.db.global.groups[groupName].items[itemId] = nil; + addon.db.profile.groups[groupName].items[itemId] = nil; return true; end @@ -193,7 +285,7 @@ for premadeGroupName, groupInfo in pairs(addon.defaultGroups) do -- Go through all default groups - for groupName, values in pairs(addon.db.global.groups) do + for groupName, values in pairs(addon.db.profile.groups) do -- Go through all groups to find those with this premade group if values.premadeGroups and values.premadeGroups[premadeGroupName] and values.premadeGroups[premadeGroupName] < groupInfo.version then @@ -428,9 +520,6 @@ AceGUI:RegisterWidgetType(widgetType, GetItemLinkButton, widgetVersion); end -local slashArgs = {}; -local slashError = "Wrong argument, the following arguements are available:"; - function addon:RegisterSlash(func, args, description) for _, arg in pairs(args) do slashArgs[arg] = func; @@ -441,17 +530,6 @@ end end -function InventoriumCommandHandler(message) - local cmd, arg = string.split(" ", (message or ""), 2); - cmd = string.lower(cmd); - - if slashArgs[cmd] then - slashArgs[cmd](addon, arg); - else - print(slashError); - end -end - function addon:Load() if not AceConfigDialog and not AceConfigRegistry then self:FillOptions(); @@ -592,7 +670,7 @@ 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"; local currentAddon, selectedAddonName = addon:GetItemCountAddon(); - local preferedAddon = self.db.global.defaults.itemCountAddon; + local preferedAddon = self.db.profile.defaults.itemCountAddon; if currentAddon then --GetCharacterCount @@ -633,9 +711,9 @@ return temp; end, - get = function() return self.db.global.defaults.auctionPricingAddon; end, + get = function() return self.db.profile.defaults.auctionPricingAddon; end, set = function(i, v) - self.db.global.defaults.auctionPricingAddon = v; + self.db.profile.defaults.auctionPricingAddon = v; if self.supportedAddons.auctionPricing[v].OnSelect then self.supportedAddons.auctionPricing[v].OnSelect(); @@ -655,9 +733,9 @@ return temp; end, - get = function() return self.db.global.defaults.itemCountAddon; end, + get = function() return self.db.profile.defaults.itemCountAddon; end, set = function(i, v) - self.db.global.defaults.itemCountAddon = v; + self.db.profile.defaults.itemCountAddon = v; if self.supportedAddons.itemCount[v].OnSelect then self.supportedAddons.itemCount[v].OnSelect(); @@ -677,9 +755,9 @@ return temp; end, - get = function() return self.db.global.defaults.craftingAddon; end, + get = function() return self.db.profile.defaults.craftingAddon; end, set = function(i, v) - self.db.global.defaults.craftingAddon = v; + self.db.profile.defaults.craftingAddon = v; if self.supportedAddons.crafting[v].OnSelect then self.supportedAddons.crafting[v].OnSelect(); @@ -697,8 +775,8 @@ ["Auction House"] = "Auction House", ["Mailbox"] = "Mailbox", }, - get = function(i, v) return self.db.global.defaults.localItemData and self.db.global.defaults.localItemData[v]; end, - set = function(i, v, e) self.db.global.defaults.localItemData[v] = e or nil; end, + get = function(i, v) return self.db.profile.defaults.localItemData and self.db.profile.defaults.localItemData[v]; end, + set = function(i, v, e) self.db.profile.defaults.localItemData[v] = e or nil; end, --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. }, }, @@ -728,16 +806,16 @@ step = 1, name = "Minimum local stock", desc = "You can manually enter a value between 100 and 100.000 in the text box below if the provided range is insufficient.", - get = function() return self.db.global.defaults.minimumLocalStock; end, - set = function(i, v) self.db.global.defaults.minimumLocalStock = v; end, + get = function() return self.db.profile.defaults.minLocalStock; end, + set = function(i, v) self.db.profile.defaults.minLocalStock = v; end, }, alertBelowLocalMinimum = { order = 11, type = "toggle", name = "Alert when below local minimum (NYI)", desc = "Show an alert when this item gets below this threshold.", - get = function() return self.db.global.defaults.alertBelowLocalMinimum; end, - set = function(i, v) self.db.global.defaults.alertBelowLocalMinimum = v; end, + get = function() return self.db.profile.defaults.alertBelowLocalMinimum; end, + set = function(i, v) self.db.profile.defaults.alertBelowLocalMinimum = v; end, }, minGlobalStock = { order = 20, @@ -748,16 +826,16 @@ step = 1, name = "Minimum global stock", desc = "You can manually enter a value between 100 and 100.000 in the text box below if the provided range is insufficient.", - get = function() return self.db.global.defaults.minimumStock; end, - set = function(i, v) self.db.global.defaults.minimumStock = v; end, + get = function() return self.db.profile.defaults.minGlobalStock; end, + set = function(i, v) self.db.profile.defaults.minGlobalStock = v; end, }, alertBelowGlobalMinimum = { order = 21, type = "toggle", name = "Alert when below global minimum (NYI)", desc = "Show an alert when this item gets below this threshold.", - get = function() return self.db.global.defaults.alertBelowMinimum; end, - set = function(i, v) self.db.global.defaults.alertBelowMinimum = v; end, + get = function() return self.db.profile.defaults.alertBelowGlobalMinimum; end, + set = function(i, v) self.db.profile.defaults.alertBelowGlobalMinimum = v; end, }, summaryThresholdShow = { order = 30, @@ -769,8 +847,8 @@ isPercent = true, name = "Show in summary when below", 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.", - get = function() return self.db.global.defaults.summaryThresholdShow; end, - set = function(i, v) self.db.global.defaults.summaryThresholdShow = v; end, + get = function() return self.db.profile.defaults.summaryThresholdShow; end, + set = function(i, v) self.db.profile.defaults.summaryThresholdShow = v; end, }, trackAtCharacters = { order = 40, @@ -785,8 +863,8 @@ return temp; end, - get = function(i, v) return self.db.global.defaults.trackAtCharacters[v]; end, - set = function(i, v, e) self.db.global.defaults.trackAtCharacters[v] = e or nil; end, + get = function(i, v) return self.db.profile.defaults.trackAtCharacters[v]; end, + set = function(i, v, e) self.db.profile.defaults.trackAtCharacters[v] = e or nil; end, --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. }, }, @@ -803,7 +881,7 @@ name = function() 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"; - 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."; + 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."; return r; end, @@ -822,8 +900,8 @@ step = 1, name = "Restock target", desc = "You can manually enter a value between 100 and 100.000 in the edit box if the provided range is insufficient.", - get = function() return self.db.global.defaults.restockTarget; end, - set = function(i, v) self.db.global.defaults.restockTarget = v; end, + get = function() return self.db.profile.defaults.restockTarget; end, + set = function(i, v) self.db.profile.defaults.restockTarget = v; end, }, minCraftingQueue = { order = 20, @@ -834,8 +912,8 @@ isPercent = true, name = "Don't queue if I only miss", 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.", - get = function() return self.db.global.defaults.minCraftingQueue; end, - set = function(i, v) self.db.global.defaults.minCraftingQueue = v; end, + get = function() return self.db.profile.defaults.minCraftingQueue; end, + set = function(i, v) self.db.profile.defaults.minCraftingQueue = v; end, }, bonusQueue = { order = 30, @@ -846,8 +924,8 @@ isPercent = true, name = "Bonus queue", 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.", - get = function() return self.db.global.defaults.bonusQueue; end, - set = function(i, v) self.db.global.defaults.bonusQueue = v; end, + get = function() return self.db.profile.defaults.bonusQueue; end, + set = function(i, v) self.db.profile.defaults.bonusQueue = v; end, }, priceThreshold = { order = 40, @@ -855,24 +933,24 @@ name = "Price threshold", 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.", validate = function(info, value) return self:ValidateReadableMoney(info, value); end, - get = function() return self:ReadableMoney(self.db.global.defaults.priceThreshold); end, - set = function(i, v) self.db.global.defaults.priceThreshold = self:ReadableMoneyToCopper(v); end, + get = function() return self:ReadableMoney(self.db.profile.defaults.priceThreshold); end, + set = function(i, v) self.db.profile.defaults.priceThreshold = self:ReadableMoneyToCopper(v); end, }, summaryHidePriceThreshold = { order = 50, type = "toggle", name = "Hide when below threshold", desc = "Hide items from the summary when their value is below the set price threshold.", - get = function() return self.db.global.defaults.summaryHidePriceThreshold; end, - set = function(i, v) self.db.global.defaults.summaryHidePriceThreshold = v; end, + get = function() return self.db.profile.defaults.summaryHidePriceThreshold; end, + set = function(i, v) self.db.profile.defaults.summaryHidePriceThreshold = v; end, }, alwaysGetAuctionValue = { order = 60, type = "toggle", name = "Always show auction value", desc = "Always cache and show the auction value of items, even if the price threshold is set to 0|cffeda55fc|r.", - get = function() return self.db.global.defaults.alwaysGetAuctionValue; end, - set = function(i, v) self.db.global.defaults.alwaysGetAuctionValue = v; end, + get = function() return self.db.profile.defaults.alwaysGetAuctionValue; end, + set = function(i, v) self.db.profile.defaults.alwaysGetAuctionValue = v; end, }, }, }, @@ -901,8 +979,8 @@ isPercent = true, name = "|cff00ff00Green|r", desc = "Show quantity in green when at least this much of the minimum stock is available.", - get = function() return self.db.global.defaults.colors.green; end, - set = function(i, v) self.db.global.defaults.colors.green = v; end, + get = function() return self.db.profile.defaults.colors.green; end, + set = function(i, v) self.db.profile.defaults.colors.green = v; end, }, yellow = { order = 20, @@ -913,8 +991,8 @@ isPercent = true, name = "|cffffff00Yellow|r", desc = "Show quantity in yellow when at least this much of the minimum stock is available.", - get = function() return self.db.global.defaults.colors.yellow; end, - set = function(i, v) self.db.global.defaults.colors.yellow = v; end, + get = function() return self.db.profile.defaults.colors.yellow; end, + set = function(i, v) self.db.profile.defaults.colors.yellow = v; end, }, orange = { order = 30, @@ -925,8 +1003,8 @@ isPercent = true, name = "|cffff9933Orange|r", desc = "Show quantity in orange when at least this much of the minimum stock is available.", - get = function() return self.db.global.defaults.colors.orange; end, - set = function(i, v) self.db.global.defaults.colors.orange = v; end, + get = function() return self.db.profile.defaults.colors.orange; end, + set = function(i, v) self.db.profile.defaults.colors.orange = v; end, }, red = { order = 40, @@ -937,8 +1015,8 @@ isPercent = true, name = "|cffff0000Red|r", desc = "Show quantity in red when at least this much of the minimum stock is available.", - get = function() return self.db.global.defaults.colors.red; end, - set = function(i, v) self.db.global.defaults.colors.red = v; end, + get = function() return self.db.profile.defaults.colors.red; end, + set = function(i, v) self.db.profile.defaults.colors.red = v; end, }, }, }, @@ -961,37 +1039,37 @@ value = nil; -- If this is an override toggler then also set the related field to nil - addon.db.global.groups[groupName][info.arg] = nil; + addon.db.profile.groups[groupName][info.arg] = nil; elseif value and info.arg then -- 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) - addon.db.global.groups[groupName][info.arg] = addon:GetOptionByKey(groupName, info.arg); + addon.db.profile.groups[groupName][info.arg] = addon:GetOptionByKey(groupName, info.arg); end end if multiSelectEnabled ~= nil then -- The saved vars for a multiselect will always be an array, it may not yet exist in which case it must be created. - if not addon.db.global.groups[groupName][optionName] then - addon.db.global.groups[groupName][optionName] = {}; + if not addon.db.profile.groups[groupName][optionName] then + addon.db.profile.groups[groupName][optionName] = {}; end - addon.db.global.groups[groupName][optionName][value] = multiSelectEnabled or nil; + addon.db.profile.groups[groupName][optionName][value] = multiSelectEnabled or nil; else - addon.db.global.groups[groupName][optionName] = value; + addon.db.profile.groups[groupName][optionName] = value; end end function addon:GetOptionByKey(groupName, optionName, noDefault) - if groupName and self.db.global.groups[groupName] and self.db.global.groups[groupName][optionName] ~= nil then + if groupName and self.db.profile.groups[groupName] and self.db.profile.groups[groupName][optionName] ~= nil then -- If this option exists within the settings of this group - return self.db.global.groups[groupName][optionName]; - elseif groupName and self.db.global.groups[groupName] and self.db.global.groups[groupName].virtualGroup ~= "" and not noDefault then + return self.db.profile.groups[groupName][optionName]; + elseif groupName and self.db.profile.groups[groupName] and self.db.profile.groups[groupName].virtualGroup ~= "" and not noDefault then -- If a virtual group was selected - return self:GetOptionByKey(self.db.global.groups[groupName].virtualGroup, optionName, noDefault); - elseif self.db.global.defaults[optionName] and not noDefault then - return self.db.global.defaults[optionName]; + return self:GetOptionByKey(self.db.profile.groups[groupName].virtualGroup, optionName, noDefault); + elseif self.db.profile.defaults[optionName] and not noDefault then + return self.db.profile.defaults[optionName]; else return nil; end @@ -1014,10 +1092,10 @@ local groupName = groupIdToName[info[2]]; local optionName = info[#info]; - if addon.db.global.groups[groupName][optionName] ~= nil then - return addon.db.global.groups[groupName][optionName][value]; - elseif addon.db.global.defaults[optionName] then - return addon.db.global.defaults[optionName][value]; + if addon.db.profile.groups[groupName][optionName] ~= nil then + return addon.db.profile.groups[groupName][optionName][value]; + elseif addon.db.profile.defaults[optionName] then + return addon.db.profile.defaults[optionName][value]; else return nil; end @@ -1037,7 +1115,7 @@ local function ValidateGroupName(_, value) value = string.lower(string.trim(value or "")); - for name, _ in pairs(addon.db.global.groups) do + for name, _ in pairs(addon.db.profile.groups) do if string.lower(name) == value then return ("A group named \"%s\" already exists."):format(name); end @@ -1100,13 +1178,13 @@ local function UpdateAddItemList(info) local groupName = groupIdToName[info[2]]; - if not addon.db.global.groups[groupName].items then - addon.db.global.groups[groupName].items = {}; + if not addon.db.profile.groups[groupName].items then + addon.db.profile.groups[groupName].items = {}; end -- Merge all items from all groups together local items = {}; - for groupName, values in pairs(addon.db.global.groups) do + for groupName, values in pairs(addon.db.profile.groups) do if values.items then for itemId, _ in pairs(values.items) do items[itemId] = true; @@ -1176,8 +1254,8 @@ local function UpdateRemoveItemList(info) local groupName = groupIdToName[info[2]]; - if not addon.db.global.groups[groupName].items then - addon.db.global.groups[groupName].items = {}; + if not addon.db.profile.groups[groupName].items then + addon.db.profile.groups[groupName].items = {}; end local ref = options.args.groups.args[info[2]].args.remove.args.list.args; @@ -1188,7 +1266,7 @@ end -- Parse items in group and show these - for itemId, _ in pairs(addon.db.global.groups[groupName].items) do + for itemId, _ in pairs(addon.db.profile.groups[groupName].items) do ref[itemId] = tblRemoveItemTemplate; end end @@ -1296,7 +1374,7 @@ local groupName = groupIdToName[info[2]]; local optionName = info[#info]; - addon.db.global.groups[groupName][optionName] = value ~= "" and value; + addon.db.profile.groups[groupName][optionName] = value ~= "" and value; if addon.supportedAddons.auctionPricing[value].OnSelect then addon.supportedAddons.auctionPricing[value].OnSelect(); @@ -1328,7 +1406,7 @@ local groupName = groupIdToName[info[2]]; local optionName = info[#info]; - addon.db.global.groups[groupName][optionName] = value ~= "" and value; + addon.db.profile.groups[groupName][optionName] = value ~= "" and value; if addon.supportedAddons.itemCount[value].OnSelect then addon.supportedAddons.itemCount[value].OnSelect(); @@ -1360,7 +1438,7 @@ local groupName = groupIdToName[info[2]]; local optionName = info[#info]; - addon.db.global.groups[groupName][optionName] = value ~= "" and value; + addon.db.profile.groups[groupName][optionName] = value ~= "" and value; if addon.supportedAddons.crafting[value].OnSelect then addon.supportedAddons.crafting[value].OnSelect(); @@ -1401,7 +1479,7 @@ local temp = {}; temp[""] = ""; - for name, values in pairs(addon.db.global.groups) do + for name, values in pairs(addon.db.profile.groups) do if values.isVirtual and name ~= groupName then temp[name] = name; end @@ -1413,7 +1491,7 @@ local groupName = groupIdToName[info[2]]; local optionName = info[#info]; - addon.db.global.groups[groupName][optionName] = value ~= "" and value; + addon.db.profile.groups[groupName][optionName] = value ~= "" and value; end, disabled = false, }, @@ -1706,8 +1784,8 @@ set = function(info, value) local oldGroupName = groupIdToName[info[2]]; - addon.db.global.groups[value] = CopyTable(addon.db.global.groups[oldGroupName]); - addon.db.global.groups[oldGroupName] = nil; + addon.db.profile.groups[value] = CopyTable(addon.db.profile.groups[oldGroupName]); + addon.db.profile.groups[oldGroupName] = nil; groupIdToName[info[2]] = value; groupIdToName[value] = true; @@ -1728,10 +1806,10 @@ set = function(info, value) local oldGroupName = groupIdToName[info[2]]; - addon.db.global.groups[value] = CopyTable(addon.db.global.groups[oldGroupName]); + addon.db.profile.groups[value] = CopyTable(addon.db.profile.groups[oldGroupName]); -- Reset item data (duplicate items me no want) - addon.db.global.groups[value].items = nil; + addon.db.profile.groups[value].items = nil; addon:FillGroupOptions(); end, @@ -1747,7 +1825,7 @@ func = function(info) local groupName = groupIdToName[info[2]]; - addon.db.global.groups[groupName] = nil; + addon.db.profile.groups[groupName] = nil; addon:FillGroupOptions(); end, @@ -1772,7 +1850,7 @@ local groupName = groupIdToName[info[2]]; -- We want to include the group name, so we copy the table then set another value - local temp = CopyTable(addon.db.global.groups[groupName]); + local temp = CopyTable(addon.db.profile.groups[groupName]); temp.name = groupName; temp.trackAtCharacters = nil; temp.overrideTrackAtCharacters = nil; @@ -1883,10 +1961,10 @@ print(("Importing items from the premade group \"|cfffed000%s|r\"."):format(value)); -- Remember we imported this group and it's version so if it is ever changed, people can be notified - if not addon.db.global.groups[groupName].premadeGroups then - addon.db.global.groups[groupName].premadeGroups = {}; + if not addon.db.profile.groups[groupName].premadeGroups then + addon.db.profile.groups[groupName].premadeGroups = {}; end - addon.db.global.groups[groupName].premadeGroups[value] = addon.defaultGroups[value].version; + addon.db.profile.groups[groupName].premadeGroups[value] = addon.defaultGroups[value].version; for itemId, version in pairs(addon.defaultGroups[value].items) do if version > 0 then @@ -2049,8 +2127,8 @@ local groupName = groupIdToName[info[2]]; local temp = {}; - if addon.db.global.groups[groupName].premadeGroups then - for name, version in pairs(addon.db.global.groups[groupName].premadeGroups) do + if addon.db.profile.groups[groupName].premadeGroups then + for name, version in pairs(addon.db.profile.groups[groupName].premadeGroups) do temp[name] = name; end end @@ -2061,7 +2139,7 @@ -- Remove premade group from this group local groupName = groupIdToName[info[2]]; - addon.db.global.groups[groupName].premadeGroups[value] = nil; + addon.db.profile.groups[groupName].premadeGroups[value] = nil; print(("No longer notifying you about changes made to the premade group named \"|cfffed000%s|r\"."):format(value)); end, @@ -2069,7 +2147,7 @@ disabled = function(info) local groupName = groupIdToName[info[2]]; - return (not addon.db.global.groups[groupName].premadeGroups); + return (not addon.db.profile.groups[groupName].premadeGroups); end, }, }, @@ -2102,7 +2180,7 @@ local combinedItemIds; -- Parse items in group and show these - for itemId, _ in pairs(addon.db.global.groups[groupName].items) do + for itemId, _ in pairs(addon.db.profile.groups[groupName].items) do if not combinedItemIds then combinedItemIds = tostring(itemId); else @@ -2141,9 +2219,9 @@ desc = "The name of the group. You can also use item links as you wish.", validate = ValidateGroupName, set = function(_, value) - self.db.global.groups[value] = {}; + self.db.profile.groups[value] = {}; if currentGroupType == "Virtual" then - self.db.global.groups[value].isVirtual = true; + self.db.profile.groups[value].isVirtual = true; end addon:FillGroupOptions(); @@ -2196,20 +2274,22 @@ temp.name = nil; print(("Importing %s..."):format(name)); - -- Remove items that are already in another group - for value, _ in pairs(temp.items) do - local itemId = tonumber(value); - - if not itemId then - print(("\"%s\" is not a number."):format(value)); - temp.items[value] = nil; - elseif InGroup(itemId) then - print(("Skipping %s (#%d) as it is already in the group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, InGroup(itemId))); - temp.items[value] = nil; - else - -- Ensure the keys are numeric - temp.items[value] = nil; - temp.items[itemId] = true; + if temp.items then + -- Remove items that are already in another group + for value, _ in pairs(temp.items) do + local itemId = tonumber(value); + + if not itemId then + print(("\"%s\" is not a number."):format(value)); + temp.items[value] = nil; + elseif InGroup(itemId) then + print(("Skipping %s (#%d) as it is already in the group |cfffed000%s|r."):format(select(2, GetItemInfo(itemId)) or "Unknown", itemId, InGroup(itemId))); + temp.items[value] = nil; + else + -- Ensure the keys are numeric + temp.items[value] = nil; + temp.items[itemId] = true; + end end end @@ -2217,7 +2297,7 @@ temp.trackAtCharacters = nil; temp.overrideTrackAtCharacters = nil; - self.db.global.groups[name] = temp; + self.db.profile.groups[name] = temp; end end @@ -2234,7 +2314,7 @@ function addon:FillGroupOptions() for id, name in pairs(groupIdToName) do - if type(name) == "string" and not self.db.global.groups[name] then + if type(name) == "string" and not self.db.profile.groups[name] then options.args.groups.args[id] = nil; groupIdToName[id] = nil; groupIdToName[name] = nil; @@ -2242,7 +2322,7 @@ end end - for name, values in pairs(self.db.global.groups) do + for name, values in pairs(self.db.profile.groups) do if not groupIdToName[name] then options.args.groups.args[tostring(count)] = defaultGroup; diff -r 12c2b20ca843 -r d903b0a151d3 Queue.lua --- a/Queue.lua Tue Dec 21 14:29:52 2010 +0100 +++ b/Queue.lua Wed Dec 22 15:04:09 2010 +0100 @@ -23,8 +23,8 @@ local playerName = UnitName("player"); -- Go through all groups - for groupName, values in pairs(addon.db.global.groups) do - local trackAt = (values.trackAtCharacters or (values.trackAtCharacters == nil and addon.db.global.defaults.trackAtCharacters)); + for groupName, values in pairs(addon.db.profile.groups) do + local trackAt = (values.trackAtCharacters or (values.trackAtCharacters == nil and addon.db.profile.defaults.trackAtCharacters)); if trackAt[playerName] then self:QueueGroup(groupName); @@ -33,7 +33,7 @@ end function mod:QueueGroup(groupName) - if not addon.db.global.groups[groupName] then + if not addon.db.profile.groups[groupName] then print(("Tried to queue items from a group named \"%s\", but no such group exists."):format(groupName)); return; end @@ -46,8 +46,8 @@ self:ProcessTradeSkill(i, groupName, temp); end - if addon.db.global.groups[groupName].items then - for itemId, _ in pairs(addon.db.global.groups[groupName].items) do + if addon.db.profile.groups[groupName].items then + for itemId, _ in pairs(addon.db.profile.groups[groupName].items) do if not temp[itemId] then local itemLink = select(2, GetItemInfo(itemId)); @@ -70,7 +70,7 @@ itemId = addon.scrollIds[itemId]; -- change enchantIds into scrollIds end - if addon.db.global.groups[groupName].items[itemId] then + if addon.db.profile.groups[groupName].items[itemId] then -- This item is in this group, queue it! if temp then diff -r 12c2b20ca843 -r d903b0a151d3 Summary.lua --- a/Summary.lua Tue Dec 21 14:29:52 2010 +0100 +++ b/Summary.lua Wed Dec 22 15:04:09 2010 +0100 @@ -103,13 +103,13 @@ mod:CancelTimer(self.tmrUpdater, true); mod:CloseFrame(); end); - mod.frame:SetWidth(addon.db.global.defaults.summary.width); - mod.frame:SetHeight(addon.db.global.defaults.summary.height); + mod.frame:SetWidth(addon.db.profile.defaults.summary.width); + mod.frame:SetHeight(addon.db.profile.defaults.summary.height); mod.frame.OnWidthSet = function(_, width) - addon.db.global.defaults.summary.width = width; + addon.db.profile.defaults.summary.width = width; end; mod.frame.OnHeightSet = function(_, height) - addon.db.global.defaults.summary.height = height; + addon.db.profile.defaults.summary.height = height; end; -- Close on escape @@ -208,11 +208,11 @@ sdrSpeed:SetIsPercent(true); sdrSpeed:SetRelativeWidth(.3); sdrSpeed:SetCallback("OnMouseUp", function(self, event, value) - addon.db.global.defaults.summary.speed = ceil( value * 100 / 5 ); + addon.db.profile.defaults.summary.speed = ceil( value * 100 / 5 ); - CACHE_ITEMS_PER_UPDATE = addon.db.global.defaults.summary.speed; -- max = 20, min = 1 + CACHE_ITEMS_PER_UPDATE = addon.db.profile.defaults.summary.speed; -- max = 20, min = 1 end); - sdrSpeed:SetValue( addon.db.global.defaults.summary.speed * 5 / 100 ); + sdrSpeed:SetValue( addon.db.profile.defaults.summary.speed * 5 / 100 ); sdrSpeed:SetCallback("OnEnter", ShowTooltip); sdrSpeed:SetCallback("OnLeave", HideTooltip); sdrSpeed.frame.tooltipTitle = "Caching Processing Speed"; @@ -265,7 +265,7 @@ local playerName = UnitName("player"); -- Go through all our stored groups - for groupName, values in pairsByKeys(addon.db.global.groups, function(a, b) return a:lower() < b:lower(); end) do + for groupName, values in pairsByKeys(addon.db.profile.groups, function(a, b) return a:lower() < b:lower(); end) do local groupStartTime, groupTimes = GetTime(), {}; local trackAt = addon:GetOptionByKey(groupName, "trackAtCharacters"); @@ -531,8 +531,8 @@ local i = 0; for groupName, items in pairs(itemsCache) do - local minGlobalStock = addon:GetOptionByKey(groupName, "minimumStock"); - local minLocalStock = addon:GetOptionByKey(groupName, "minimumLocalStock"); + local minGlobalStock = addon:GetOptionByKey(groupName, "minGlobalStock"); + local minLocalStock = addon:GetOptionByKey(groupName, "minLocalStock"); local priceThreshold = addon:GetOptionByKey(groupName, "priceThreshold"); for _, item in pairs(items) do @@ -576,7 +576,7 @@ mod.frame:SetStatusText(("Caching auction values and item-counts... %d%% has already been processed."):format(floor(CACHE_ITEMS_CURRENT / CACHE_ITEMS_TOTAL * 100))); end - if i >= addon.db.global.defaults.summary.speed then + if i >= addon.db.profile.defaults.summary.speed then return; end end @@ -603,13 +603,13 @@ function mod:ColorCode(num, required) local percentage = ( num / required ); - if percentage >= addon.db.global.defaults.colors.green then + if percentage >= addon.db.profile.defaults.colors.green then return ("|cff00ff00%d|r"):format(num); - elseif percentage >= addon.db.global.defaults.colors.yellow then + elseif percentage >= addon.db.profile.defaults.colors.yellow then return ("|cffffff00%d|r"):format(num); - elseif percentage >= addon.db.global.defaults.colors.orange then + elseif percentage >= addon.db.profile.defaults.colors.orange then return ("|cffff9933%d|r"):format(num); - elseif percentage >= addon.db.global.defaults.colors.red then + elseif percentage >= addon.db.profile.defaults.colors.red then return ("|cffff0000%d|r"):format(num); end end