-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathCache.lua
More file actions
129 lines (121 loc) · 5 KB
/
Copy pathCache.lua
File metadata and controls
129 lines (121 loc) · 5 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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
local _, wt = ...
-- Spell Cache
wt.petAbilities = {}
wt.spellInfoCache = {}
wt.allRanksCache = {}
wt.idToRanks = {}
if wt.currentClass == "WARLOCK" then
wt.TomeIds = {}
-- Succubus and Incubus share tomes, but you need to buy them twice to train both
wt.SayaadTomes = {}
end
-- done has params cacheHit: bool, spellInfo
function wt:CacheSpell(spell, level, done)
if (self.spellInfoCache[spell.id] ~= nil) then
done(true, self.spellInfoCache[spell.id])
return
end
local si = Spell:CreateFromSpellID(spell.id)
si:ContinueOnSpellLoad(function()
if (self.spellInfoCache[spell.id] ~= nil) then
done(true, self.spellInfoCache[spell.id])
return
end
-- some stuff, like subtext, might be nil even though we're in the load continuation
-- delaying it seems to fix it, and subtext always appears
RunNextFrame(function()
local subText = si:GetSpellSubtext() -- C_Spell.GetSpellSubtext(spell.id)
local formattedSubText = (subText and subText ~= "") and
format(PARENS_TEMPLATE, subText) or ""
local spellName = si:GetSpellName()
local name = wt.stripRankNumeral(spellName, subText)
local formattedFullName = (subText and subText ~= "") and format("%s %s", name, formattedSubText) or name
self.spellInfoCache[spell.id] = {
id = spell.id,
name = name,
subText = subText,
formattedSubText = formattedSubText,
icon = select(3, GetSpellInfo(spell.id)),
cost = spell.cost,
tooltipType = "spell",
tooltipId = spell.id,
formattedCost = GetCoinTextureString(spell.cost),
level = level,
formattedLevel = format(wt.L.LEVEL_FORMAT, level),
formattedFullName = formattedFullName,
searchText = strlower(formattedFullName),
link = string.format("|cff71d5ff|Hspell:%d:0|h[%s]|h|r", spell.id, spellName),
}
if self.allRanksCache[name] == nil then
self.allRanksCache[name] = {}
end
tinsert(self.allRanksCache[name], spell.id)
self.idToRanks[spell.id] = self.allRanksCache[name]
if (self:IsPetAbility(spell.id)) then
if (formattedSubText ~= "") then
self.petAbilities[name .. " " .. formattedSubText] =
self.spellInfoCache[spell.id]
else
self.petAbilities[name] =
self.spellInfoCache[spell.id]
end
end
done(false, self.spellInfoCache[spell.id])
end)
end)
end
function wt:SpellInfo(spellId) return self.spellInfoCache[spellId] end
function wt:PetAbility(forName) return self.petAbilities[forName] end
function wt:AllRanks(spellId) return self.idToRanks[spellId] end
-- Item Cache
wt.itemInfoCache = {}
-- for warlock pet tomes, the name includes the rank
-- however, this will cause overlap with the level text and there's no good way to fix it with setting points
-- instead, strip the rank text out of the name and put it as the subText
local parensPattern = " (%(.+%))"
function wt:CacheItem(item, level, done, taughtSpell)
if (self.itemInfoCache[item.id] ~= nil) then
done(true)
return
end
local ii = Item:CreateFromItemID(item.itemId)
ii:ContinueOnItemLoad(function()
if (self.itemInfoCache[item.id] ~= nil) then
done(true)
return
end
local rankText = string.match(ii:GetItemName(), parensPattern)
local ranklessName = string.gsub(ii:GetItemName(), parensPattern, "")
local rankCacheKey = ranklessName
if wt.SayaadTomes[item.itemId] then
rankCacheKey = item.family..ranklessName
end
self.itemInfoCache[item.id] = {
id = item.id,
itemId = item.itemId,
name = ranklessName,
formattedSubText = rankText,
icon = ii:GetItemIcon(),
cost = item.cost,
formattedCost = GetCoinTextureString(item.cost),
level = level,
formattedLevel = format(wt.L.LEVEL_FORMAT, level),
tooltipType = "item",
tooltipId = wt.TomeTaughtSpells[item.itemId],
searchText = strlower(ii:GetItemName()),
formattedFullName = ii:GetItemName(),
localFamily = item.localFamily,
family = item.family,
altIcon = item.altIcon,
link = ii:GetItemLink(),
taughtSpell = taughtSpell
}
if self.allRanksCache[rankCacheKey] == nil then
self.allRanksCache[rankCacheKey] = {}
end
tinsert(self.allRanksCache[rankCacheKey], item.id)
self.idToRanks[item.id] = self.allRanksCache[rankCacheKey]
done(false)
end)
end
function wt:ItemInfo(itemId) return self.itemInfoCache[itemId] end