Skip to content

Commit

Permalink
[Filters] Separate Out of Main file
Browse files Browse the repository at this point in the history
  • Loading branch information
doadin committed Jun 24, 2020
1 parent e0bcb98 commit db7b4a2
Show file tree
Hide file tree
Showing 13 changed files with 952 additions and 654 deletions.
659 changes: 5 additions & 654 deletions Baggins-Filtering.lua

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions Baggins.toc
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,19 @@ Baggins_ItemOps.lua

# Filters
src\filters\Bag.lua
src\filters\Category.lua
src\filters\ContainerType.lua
src\filters\Empty.lua
src\filters\EquipLocation.lua
src\filters\EquipmentSet.lua
src\filters\EquipmentSlot.lua
src\filters\ItemBind.lua
src\filters\ItemID.lua
src\filters\ItemLevel.lua
src\filters\ItemName.lua
src\filters\ItemType.lua
src\filters\NewItems.lua
src\filters\Other.lua
src\filters\PeriodicTable.lua
src\filters\Quality.lua
src\filters\Tooltip.lua
62 changes: 62 additions & 0 deletions src/filters/Category.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
--[[ ==========================================================================
Category.lua
========================================================================== ]]--

local _G = _G

local AddOnName, _ = ...
local AddOn = _G[AddOnName]

-- LUA Functions
local pairs = _G.pairs

-- Libs
local L = LibStub("AceLocale-3.0"):GetLocale(AddOnName)

-- Local storage
local BagTypes = {}
local bankcategorycache = {}
local categorycache = {}

local function Matches(bag,slot,rule)
if not (bag and slot and rule.category) then return end
local key = bag..":"..slot
if BagTypes[bag] == 2 or BagTypes[bag] == 4 then
return bankcategorycache[rule.category] and bankcategorycache[rule.category][key]
else
return categorycache[rule.category] and categorycache[rule.category][key]
end
end

local function GetName(rule)
if rule.category then
return L["Category"].." :"..rule.category
else
return L["Category"]
end
end

AddOn:AddCustomRule("Category",
{
DisplayName = L["Category"],
Description = L["Items that match another category"],
Matches = Matches,
GetName = GetName,
Ace3Options = {
category = {
name = L["Category"],
desc = "",
type = 'select',
values = function()
local tmp = {}
for k in pairs(AddOn.db.profile.categories) do
tmp[k] = k
end
return tmp
end,
},
},
}
)
70 changes: 70 additions & 0 deletions src/filters/Empty.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
--[[ ==========================================================================
Empty.lua
========================================================================== ]]--

local _G = _G

local AddOnName, _ = ...
local AddOn = _G[AddOnName]

-- WoW API
local GetContainerItemLink = _G.GetContainerItemLink

-- Libs
local L = LibStub("AceLocale-3.0"):GetLocale(AddOnName)

-- Local storage
local BagTypes = {}

-- Build list of bag types
local function BuildBagTypes()

-- Common bags
BagTypes[BACKPACK_CONTAINER] = 1
BagTypes[BANK_CONTAINER] = 2

for i = 1, NUM_BAG_SLOTS + NUM_BANKBAGSLOTS do

if i <= NUM_BAG_SLOTS then
BagTypes[i] = 1 -- Bags
else
BagTypes[i] = 2 -- Bank bags
end

end

-- Classic specific bag
--[===[@non-retail@
BagTypes[KEYRING_CONTAINER] = 3
--@end-non-retail@]===]

-- Retail specific bag
--@retail@
BagTypes[REAGENTBANK_CONTAINER] = 4
--@end-retail@

end

BuildBagTypes()

local function Matches(bag,slot,_)
if not (bag and slot) then return end
if BagTypes[bag] == 3 then return end
local link = GetContainerItemLink(bag, slot)
if not link then
return true
end
end

local function GetName()
return L["Empty Slots"]
end

AddOn:AddCustomRule("Empty", {
DisplayName = L["Empty Slots"],
Description = L["Empty bag slots"],
Matches = Matches,
GetName = GetName,
})
87 changes: 87 additions & 0 deletions src/filters/EquipLocation.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
--[[ ==========================================================================
EquipLocation.lua
========================================================================== ]]--

local _G = _G

local AddOnName, _ = ...
local AddOn = _G[AddOnName]

-- WoW API
local GetContainerItemLink = _G.GetContainerItemLink
local GetItemInfoInstant = _G.GetItemInfoInstant

-- Libs
local L = LibStub("AceLocale-3.0"):GetLocale(AddOnName)

local EquipLocs = {
"INVTYPE_AMMO",
"INVTYPE_HEAD",
"INVTYPE_NECK",
"INVTYPE_SHOULDER",
"INVTYPE_BODY",
"INVTYPE_CHEST",
"INVTYPE_ROBE",
"INVTYPE_WAIST",
"INVTYPE_LEGS",
"INVTYPE_FEET",
"INVTYPE_WRIST",
"INVTYPE_HAND",
"INVTYPE_FINGER",
"INVTYPE_TRINKET",
"INVTYPE_CLOAK",
"INVTYPE_WEAPON",
"INVTYPE_SHIELD",
"INVTYPE_2HWEAPON",
"INVTYPE_WEAPONMAINHAND",
"INVTYPE_WEAPONOFFHAND",
"INVTYPE_HOLDABLE",
"INVTYPE_RANGED",
"INVTYPE_THROWN",
"INVTYPE_RANGEDRIGHT",
"INVTYPE_RELIC",
"INVTYPE_TABARD",
"INVTYPE_BAG"
}

local EquipLocs2 = {}
for _,v in ipairs(EquipLocs) do
EquipLocs2[v] = _G[v] or v
end

local function Matches(bag,slot,rule)
if not rule.equiploc then return end
local link = GetContainerItemLink(bag, slot)
if link then
local _, _, _, EquipLoc = GetItemInfoInstant(link)
if EquipLoc then
return EquipLoc == rule.equiploc
end
end
end

local function GetName(rule)
return "Equip Location: "..(_G[rule.equiploc] or rule.equiploc or "*None*")
end

AddOn:AddCustomRule("EquipLoc",
{
DisplayName = L["Equip Location"],
Description = L["Filter by Equip Location as returned by GetItemInfo"],
Matches = Matches,
GetName = GetName,
Ace3Options = {
equiploc = {
name = L["Location"],
desc = "",
type = 'select',
values = EquipLocs2,
},
},
CleanRule = function(rule)
rule.equiploc = EquipLocs[1]
end,
}
)
104 changes: 104 additions & 0 deletions src/filters/EquipmentSlot.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
--[[ ==========================================================================
EquipmentSlot.lua
========================================================================== ]]--

local _G = _G

local AddOnName, _ = ...
local AddOn = _G[AddOnName]

-- LUA Functions
local pairs = _G.pairs

-- WoW API
local GetContainerItemID = _G.GetContainerItemID
local GetItemInfoInstant = _G.GetItemInfoInstant

-- Libs
local L = LibStub("AceLocale-3.0"):GetLocale(AddOnName)

local INV_TYPES = {
INVTYPE_HEAD = INVTYPE_HEAD,
INVTYPE_NECK = INVTYPE_NECK,
INVTYPE_SHOULDER = INVTYPE_SHOULDER,
INVTYPE_BODY = INVTYPE_BODY,
INVTYPE_CHEST = INVTYPE_CHEST,
INVTYPE_ROBE = INVTYPE_ROBE,
INVTYPE_WAIST = INVTYPE_WAIST,
INVTYPE_LEGS = INVTYPE_LEGS,
INVTYPE_FEET = INVTYPE_FEET,
INVTYPE_WRIST = INVTYPE_WRIST,
INVTYPE_HAND = INVTYPE_HAND,
INVTYPE_FINGER = INVTYPE_FINGER,
INVTYPE_TRINKET = INVTYPE_TRINKET,
INVTYPE_CLOAK = INVTYPE_CLOAK,
INVTYPE_WEAPON = INVTYPE_WEAPON,
INVTYPE_SHIELD = INVTYPE_SHIELD,
INVTYPE_2HWEAPON = INVTYPE_2HWEAPON,
INVTYPE_WEAPONMAINHAND = INVTYPE_WEAPONMAINHAND,
INVTYPE_WEAPONOFFHAND = INVTYPE_WEAPONOFFHAND,
INVTYPE_HOLDABLE = INVTYPE_HOLDABLE,
INVTYPE_RANGED = INVTYPE_RANGED,
INVTYPE_THROWN = INVTYPE_THROWN,
INVTYPE_RANGEDRIGHT = INVTYPE_RANGEDRIGHT,
INVTYPE_RELIC = INVTYPE_RELIC,
INVTYPE_TABARD = INVTYPE_TABARD,
INVTYPE_BAG = INVTYPE_BAG,
INVTYPE_QUIVER = INVTYPE_QUIVER,
}

local function getSlotValue(info, key)
return info.arg.slots and info.arg.slots[key]
end

local function toggleSlotValue(info, key, value)
if not info.arg.slots then
info.arg.slots = {}
end
info.arg.slots[key] = value
AddOn:OnRuleChanged()
end

local function Matches(bag, slot, rule)
local itemId = GetContainerItemID(bag, slot)
if not rule.slots then
return ""
end
if not itemId then return end
local _, _, _, equiploc = GetItemInfoInstant(itemId)
return rule.slots[equiploc] ~= nil
end

local function GetName(rule)
if not rule.slots then
return ""
end
local slotlist = {}
for k in pairs(rule.slots) do
tinsert(slotlist, k)
end
local result = (","):join(slotlist)
wipe(slotlist)
return result
end

AddOn:AddCustomRule("EquipmentSlot",
{
DisplayName = L["Equipment Slot"],
Description = L["Filter by Equipment Slot"],
GetName = GetName,
Matches = Matches,
Ace3Options = {
slots = {
name = L["Equipment Slots"],
desc = "",
type = 'multiselect',
values = INV_TYPES,
get = getSlotValue,
set = toggleSlotValue,
},
},
}
)
Loading

0 comments on commit db7b4a2

Please sign in to comment.