Repository navigation
Expand file tree
/
Copy pathSpellbook.lua
More file actions
59 lines (55 loc) · 2.59 KB
/
Copy pathSpellbook.lua
File metadata and controls
59 lines (55 loc) · 2.59 KB
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
local MM = _G.MacroMaker
local function Lower(text)
return MM:NormalizeSearch(text)
end
function MM:ScanSpellbook()
self.spellTabs = {}
self.spells = {}
local seen = {}
local tabCount = GetNumSpellTabs and GetNumSpellTabs() or 0
for tabIndex = 1, tabCount do
local tabName, tabTexture, offset, numSpells = GetSpellTabInfo(tabIndex)
local tab = { name = tabName or MM:Text("Category %d", tabIndex), texture = tabTexture, spells = {} }
table.insert(self.spellTabs, tab)
for slot = (offset or 0) + 1, (offset or 0) + (numSpells or 0) do
local name, rank = GetSpellName(slot, BOOKTYPE_SPELL)
if name then
local passive = IsPassiveSpell and IsPassiveSpell(slot, BOOKTYPE_SPELL)
local link = GetSpellLink and GetSpellLink(slot, BOOKTYPE_SPELL)
local spellID = link and tonumber(string.match(link, "spell:(%d+)"))
local entry = {
name = name, rank = rank or "", tab = tab.name, tabIndex = tabIndex,
slot = slot, texture = GetSpellTexture and GetSpellTexture(slot, BOOKTYPE_SPELL),
passive = passive and true or false, spellID = spellID,
}
if self.db and self.db.showRanks then
table.insert(tab.spells, entry)
table.insert(self.spells, entry)
else
local key = Lower(name)
local previous = seen[key]
if previous then
previous.name, previous.rank, previous.slot, previous.texture = entry.name, entry.rank, entry.slot, entry.texture
else
seen[key] = entry
table.insert(tab.spells, entry)
table.insert(self.spells, entry)
end
end
end
end
end
end
function MM:GetFilteredSpells(query, tabName)
local results = {}
query = Lower(query)
for _, spell in ipairs(self.spells or {}) do
local matchesTab = not tabName or tabName == "All" or spell.tab == tabName
local haystack = Lower(spell.name .. " " .. spell.rank .. " " .. spell.tab)
local matchesText = query == "" or string.find(haystack, query, 1, true)
local matchesPassive = (self.db and self.db.showPassive) or not spell.passive
if matchesTab and matchesText and matchesPassive then table.insert(results, spell) end
end
table.sort(results, function(a, b) return Lower(a.name) < Lower(b.name) end)
return results
end