-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.lua
115 lines (99 loc) · 2.82 KB
/
core.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
110
111
112
113
114
115
-- Created by @project-author@ character is Bearesquishy - dalaran please credit whenever.
-- Source on GitHub: https://n6rej.github.io
-- some changes demo
---@type
local addonName, addonTable = ...
-- Get the common Release names from Release.lua
--local E = addonTable.Shadowlands
local db = {}
-- Get reference to AdiBags addon
local AdiBags = LibStub("AceAddon-3.0"):GetAddon("AdiBags")
local Result = {}
-- Debug mode switch
local debugMode = false
if debugMode then
--@debug@
--"Version: " .. '@project-version@'
--@end-debug@
end
-- Merge filters if duplicate
local function MergeItems(filters1, filters2)
local result = {}
for item, value in pairs(filters1) do
result[item] = value
end
for item, value in pairs(filters2) do
result[item] = value
end
return result
end
-- Get list of existing filters
local function GetFilter(filterName)
for key, value in AdiBags:IterateFilters() do
if value.filterName == filterName then
return value
end
end
end
-- Create Filters
local function CreateFilter(name, uiName, uiDesc, title, items)
local filter = AdiBags:RegisterFilter(uiName, 98, "ABEvent-1.0")
-- Register Filter with AdiBags
filter.uiName = uiName
filter.uiDesc = uiDesc .. " Version: " .. "@project-version@"
filter.items = items
function filter:OnInitialize()
-- Assign item table to filter
self.items = filter.items
end
function filter:Update()
self:SendMessage("AdiBags_FiltersChanged")
end
function filter:OnEnable()
AdiBags:UpdateFilters()
end
function filter:OnDisable()
AdiBags:UpdateFilters()
end
function filter:Filter(slotData)
if self.items[tonumber(slotData.itemId)] then
return title
end
end
end
-- Run filters
local function AllFilters(db)
for name, group in pairs(db.Filters) do
-- Get known filters
local existingFilter = GetFilter(group.uiName)
-- Does filter already exist?
if existingFilter ~= nil then
existingFilter.items = MergeItems(existingFilter.items, group.items)
AdiBags:UpdateFilters()
else
-- name = Name of table
-- group.uiName = Name to use in filter listing
-- group.uiDesc = Description to show in filter listing
-- group.items = table of items to sort
CreateFilter(name, group.uiName, group.uiDesc, group.title, group.items)
end
end
end
-- START HERE
-- This will cycle thru each expansion listed in expansion.lua and run the database for that expansion.
for key, value in pairs(addonTable.expansion) do
db = addonTable[value]
if (db ~= nil) then
AllFilters(db)
end
end
-- Check if globaldbs is being used in toc
if (addonTable.Globaldbs ~= nil) then
-- Now process global databases
for key, value in pairs(addonTable.Globaldbs) do
db = addonTable[value]
if (db ~= nil) then
AllFilters(db)
end
end
end