diff --git a/BetterBags.toc b/BetterBags.toc index 500d861a..1e500cb7 100644 --- a/BetterBags.toc +++ b/BetterBags.toc @@ -37,6 +37,7 @@ debug\frames.lua theme\masque.lua +data\categories.lua data\items.lua util\color.lua diff --git a/data/categories.lua b/data/categories.lua new file mode 100644 index 00000000..c9c7f361 --- /dev/null +++ b/data/categories.lua @@ -0,0 +1,31 @@ +local addonName = ... ---@type string + +---@class BetterBags: AceAddon +local addon = LibStub('AceAddon-3.0'):GetAddon(addonName) + +---@class Categories: AceModule +---@field private itemToCategory table +local categories = addon:NewModule('Categories') + +function categories:OnInitialize() + self.itemToCategory = {} +end + +---@param id number The ItemID of the item to add to a custom category. +---@param category string The name of the custom category to add the item to. +function categories:AddItemToCategory(id, category) + self.itemToCategory[id] = category +end + +---@param id number The ItemID of the item to lookup a custom category for. +---@return string +function categories:GetCustomCategory(id) + return self.itemToCategory[id] +end + +---@param id number The ItemID of the item to remove from a custom category. +function categories:RemoveItemFromCategory(id) + self.itemToCategory[id] = nil +end + +categories:Enable() \ No newline at end of file diff --git a/frames/item.lua b/frames/item.lua index fb6f6e66..c3e77263 100644 --- a/frames/item.lua +++ b/frames/item.lua @@ -21,6 +21,9 @@ local database = addon:GetModule('Database') ---@class Color: AceModule local color = addon:GetModule('Color') +---@class Categories: AceModule +local categories = addon:GetModule('Categories') + ---@class Localization: AceModule local L = addon:GetModule('Localization') @@ -213,6 +216,12 @@ function itemProto:SetFreeSlots(bagid, slotid, count, reagent) end function itemProto:GetCategory() + -- Return the custom category if it exists. + local customCategory = categories:GetCustomCategory(self:GetMixin().itemID) + if customCategory then + return customCategory + end + if not self.kind then return L:G('Everything') end -- TODO(lobato): Handle cases such as new items here instead of in the layout engine. if self:GetMixin().containerInfo.quality == Enum.ItemQuality.Poor then