-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.lua
109 lines (95 loc) · 3.46 KB
/
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
---@type string
local addonName = ...
---@class ns
local addon = select(2, ...)
--@debug@
_G["BBBound"] = addon
--@end-debug@
-- BetterBags namespace
-----------------------------------------------------------
---@class BetterBags: AceAddon
local BetterBags = LibStub('AceAddon-3.0'):GetAddon("BetterBags")
assert(BetterBags, addonName .. " requires BetterBags")
---@class Categories: AceModule
local Categories = BetterBags:GetModule('Categories')
---@class Events: AceModule
local Events = BetterBags:GetModule('Events')
-- Use the L:G() function to get the localized string.
---@class Localization: AceModule
---@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')
---@class Config: AceModule
---@field AddPluginConfig fun(self: Config, name: string, options: AceConfig.OptionsTable): nil
local Config = BetterBags:GetModule('Config')
addon.ctx = context:New('Bound_Event')
-- Lua API
-----------------------------------------------------------
local _G = _G
-- WoW API
-----------------------------------------------------------
local CreateFrame = _G.CreateFrame
-- Default settings.
-----------------------------------------------------------
addon.db = {
enableBop = false,
enableWue = true,
enableBoe = true,
enableBoa = true,
onlyEquippable = true,
wipeOnLoad = true,
}
-- Addon Constants
-----------------------------------------------------------
addon.S_BOA = "BoA"
addon.S_BOE = "BoE"
addon.S_WUE = "WuE"
addon.S_BOP = "Soulbound"
-- Addon Core
addon.eventFrame = CreateFrame("Frame", addonName .. "EventFrame", UIParent)
addon.eventFrame:RegisterEvent("ADDON_LOADED")
addon.eventFrame:RegisterEvent("EQUIP_BIND_CONFIRM")
addon.eventFrame:RegisterEvent("PLAYER_EQUIPMENT_CHANGED")
addon.eventFrame:SetScript("OnEvent", function(_, event, ...)
if event == "ADDON_LOADED" then
local name = ...
if name == addonName then
addon.eventFrame:UnregisterEvent("ADDON_LOADED")
if (type(BetterBags_Bound_SavedVars) ~= "table") 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
if (db[key] == nil) then db[key] = addon.db[key] end
-- Migrate DB for backwards compatibility
if (db.enableWoe ~= nil) then
db.enableWue = db.enableWoe
db.enableWoe = nil
end
end
-- Update our reference so that changed options are saved on logout
addon.db = db
-- Wipe categories on load.
if (addon.db.wipeOnLoad) then
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_WUE))
end
-- Load config only after populating the DB, since BetterBags will cache the get function
Config:AddPluginConfig(L:G("Bound"), addon.options)
end
elseif event == "EQUIP_BIND_CONFIRM" then
local _, itemLocation = ...
local bag, slot = itemLocation:GetBagAndSlot()
local id = C_Item.GetItemID(itemLocation)
local category = addon:GetItemCategory(bag, slot, nil)
addon.bindConfirm = { id = id, category = category }
elseif event == "PLAYER_EQUIPMENT_CHANGED" then
local slot, hasCurrent = ...
-- hasCurrent is false if the slot was just equipped
if (slot ~= nil and not hasCurrent) then
addon:RemoveBindConfirmFromCategory(slot)
end
end
end)