Skip to content

Commit

Permalink
Added a custom category API (WIP).
Browse files Browse the repository at this point in the history
  • Loading branch information
Cidan committed Dec 2, 2023
1 parent 61d282f commit ec69648
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions BetterBags.toc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ debug\frames.lua

theme\masque.lua

data\categories.lua
data\items.lua

util\color.lua
Expand Down
31 changes: 31 additions & 0 deletions data/categories.lua
Original file line number Diff line number Diff line change
@@ -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<number, string>
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()
9 changes: 9 additions & 0 deletions frames/item.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ec69648

Please sign in to comment.