diff --git a/.vscode/settings.json b/.vscode/settings.json index fa777d4..38eebbb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -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": { diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ecc9a9..13cef9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/config.lua b/config.lua index cc872e3..1d09a6a 100644 --- a/config.lua +++ b/config.lua @@ -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 @@ -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, }, @@ -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, }, @@ -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, }, @@ -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, }, @@ -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, }, diff --git a/filter.lua b/filter.lua index cbe170b..55a10e5 100644 --- a/filter.lua +++ b/filter.lua @@ -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 -- private +---@field ephemeralCategoryByItemID table local Categories = BetterBags:GetModule('Categories') ---@class Events: AceModule @@ -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 = {}, }) diff --git a/main.lua b/main.lua index 55a93b8..63998a9 100644 --- a/main.lua +++ b/main.lua @@ -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 @@ -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 @@ -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