Skip to content

Commit

Permalink
Add support for BetterBags Contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasvienna committed Sep 2, 2024
1 parent c372768 commit 56ba25b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
"WOW_PROJECT_MAINLINE"
],
"Lua.workspace.library": [
"~\\.vscode\\extensions\\ketho.wow-api-0.17.5\\Annotations"
"~\\.vscode\\extensions\\ketho.wow-api-0.17.6\\Annotations"
],
"Lua.runtime.version": "Lua 5.1",
"Lua.runtime.builtin": {
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. Be aware th

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased] 2024-09-02
### Added
- Support for BetterBags Contexts

## [1.6.1] 2024-09-01
### Fixed
- Fixed a typo in the configuration options.
Expand Down
40 changes: 20 additions & 20 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ local addon = select(2, ...)
local BetterBags = LibStub('AceAddon-3.0'):GetAddon("BetterBags")

---@class Categories: AceModule
---@field CreateCategory fun(self: Categories, category: CustomCategoryFilter): nil
---@field DeleteCategory fun(self: Categories, name: string): nil
---@field WipeCategory fun(self: Categories, name: string): nil
---@field ReprocessAllItems fun(self: Categories): nil
---@field CreateCategory fun(self: Categories, ctx: Context, category: CustomCategoryFilter): nil
---@field DeleteCategory fun(self: Categories, ctx: Context, name: string): nil
---@field WipeCategory fun(self: Categories, ctx: Context, name: string): nil
---@field ReprocessAllItems fun(self: Categories, ctx: Context): nil
local Categories = BetterBags:GetModule('Categories')

---@class Localization: AceModule
Expand Down Expand Up @@ -45,14 +45,14 @@ local options = {
set = function(_, value)
addon.db.enableBoe = value
if (addon.db.enableBoe) then
Categories:CreateCategory({
Categories:CreateCategory(addon.ctx:Copy(), {
name = L:G(addon.S_BOE),
itemList = {},
save = false,
})
Categories:ReprocessAllItems()
Categories:ReprocessAllItems(addon.ctx:Copy())
else
Categories:DeleteCategory(L:G(addon.S_BOE))
Categories:DeleteCategory(addon.ctx:Copy(), L:G(addon.S_BOE))
end
end,
},
Expand All @@ -67,14 +67,14 @@ local options = {
set = function(_, value)
addon.db.enableWoe = value
if (addon.db.enableWoe) then
Categories:CreateCategory({
Categories:CreateCategory(addon.ctx:Copy(), {
name = L:G(addon.S_WOE),
itemList = {},
save = false,
})
Categories:ReprocessAllItems()
Categories:ReprocessAllItems(addon.ctx:Copy())
else
Categories:DeleteCategory(L:G(addon.S_WOE))
Categories:DeleteCategory(addon.ctx:Copy(), L:G(addon.S_WOE))
end
end,
},
Expand All @@ -89,14 +89,14 @@ local options = {
set = function(_, value)
addon.db.enableBoa = value
if (addon.db.enableBoa) then
Categories:CreateCategory({
Categories:CreateCategory(addon.ctx:Copy(), {
name = L:G(addon.S_BOA),
itemList = {},
save = false,
})
Categories:ReprocessAllItems()
Categories:ReprocessAllItems(addon.ctx:Copy())
else
Categories:DeleteCategory(L:G(addon.S_BOA))
Categories:DeleteCategory(addon.ctx:Copy(), L:G(addon.S_BOA))
end
end,
},
Expand All @@ -111,14 +111,14 @@ local options = {
set = function(_, value)
addon.db.enableBop = value
if (addon.db.enableBop) then
Categories:CreateCategory({
Categories:CreateCategory(addon.ctx:Copy(), {
name = L:G(addon.S_BOP),
itemList = {},
save = true,
})
Categories:ReprocessAllItems()
Categories:ReprocessAllItems(addon.ctx:Copy())
else
Categories:DeleteCategory(L:G(addon.S_BOP))
Categories:DeleteCategory(addon.ctx:Copy(), L:G(addon.S_BOP))
end
end,
},
Expand All @@ -134,10 +134,10 @@ local options = {
set = function(_, value)
addon.db.onlyEquippable = value
if (addon.db.onlyEquippable) then
Categories:WipeCategory(L:G(addon.S_BOA))
Categories:WipeCategory(L:G(addon.S_BOE))
Categories:WipeCategory(L:G(addon.S_WOE))
Categories:ReprocessAllItems()
Categories:WipeCategory(addon.ctx:Copy(), L:G(addon.S_BOA))
Categories:WipeCategory(addon.ctx:Copy(), L:G(addon.S_BOE))
Categories:WipeCategory(addon.ctx:Copy(), L:G(addon.S_WOE))
Categories:ReprocessAllItems(addon.ctx:Copy())
end
end,
},
Expand Down
4 changes: 3 additions & 1 deletion filter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ local BetterBags = LibStub('AceAddon-3.0'):GetAddon("BetterBags")
---@field GetCategoryByName fun(self: Categories, name: string): CustomCategoryFilter|nil
---@field RemoveItemFromCategory fun(self: Categories, itemID: number): nil
---@field RegisterCategoryFunction fun(self: Categories, name: string, fn: fun(data: ItemData): string|nil): nil
---@field ephemeralCategories table<string, CustomCategoryFilter> -- private
---@field ephemeralCategoryByItemID table<number, CustomCategoryFilter>
local Categories = BetterBags:GetModule('Categories')

---@class Events: AceModule
Expand Down Expand Up @@ -224,7 +226,7 @@ if (priorityEnabled) then
-- this is required because we have multiple categories and can't really register a single function for all of them
local cat = Categories:GetCategoryByName(L:G("Bound"))
if not cat then
Categories:CreateCategory({
Categories:CreateCategory(addon.ctx:Copy(), {
name = L:G("Bound"),
itemList = {},
})
Expand Down
14 changes: 10 additions & 4 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ local Events = BetterBags:GetModule('Events')
---@field G fun(self: AceModule, key: string): string
local L = BetterBags:GetModule('Localization')

---@class Context: AceModule
---@field New fun(self: AceModule, key: string): table
local context = BetterBags:GetModule('Context')

addon.ctx = context:New('Bound_Event')

-- Lua API
-----------------------------------------------------------
local _G = _G
Expand Down Expand Up @@ -56,7 +62,7 @@ addon.eventFrame:SetScript("OnEvent", function(_, event, ...)
local name = ...
if name == addonName then
addon.eventFrame:UnregisterEvent("ADDON_LOADED")
if (type(BetterBags_Bound_SavedVars) ~= "table") then BetterBags_Bound_SavedVars = {} end
if (type(BetterBags_Bound_SavedVars) ~= "tagle") then BetterBags_Bound_SavedVars = {} end
local db = BetterBags_Bound_SavedVars
for key in pairs(addon.db) do
-- If our option is not present, set default value
Expand All @@ -66,9 +72,9 @@ addon.eventFrame:SetScript("OnEvent", function(_, event, ...)
addon.db = db
-- Wipe categories on load.
if (addon.db.wipeOnLoad) then
Categories:WipeCategory(L:G(addon.S_BOA))
Categories:WipeCategory(L:G(addon.S_BOE))
Categories:WipeCategory(L:G(addon.S_WOE))
Categories:WipeCategory(addon.ctx:Copy(), L:G(addon.S_BOA))
Categories:WipeCategory(addon.ctx:Copy(), L:G(addon.S_BOE))
Categories:WipeCategory(addon.ctx:Copy(), L:G(addon.S_WOE))
end
end
elseif event == "EQUIP_BIND_CONFIRM" then
Expand Down

0 comments on commit 56ba25b

Please sign in to comment.