libspell: use proper caching index for ranked spells

This commit is contained in:
Kyriakos (Dominick) Sidiropoulos
2024-06-07 09:03:30 +02:00
committed by GitHub
parent 5a7ee5277b
commit 4da109a705
+4 -4
View File
@@ -46,8 +46,8 @@ end
-- return: [number],[string] spell index and spellbook id
local spellindex = {}
function libspell.GetSpellIndex(name, rank)
local name = string.lower(name)
local cache = spellindex[name..(rank or "")]
name = string.lower(name)
local cache = spellindex[name..(rank and ("("..rank..")") or "")]
if cache then return cache[1], cache[2] end
if not rank then rank = libspell.GetSpellMaxRank(name) end
@@ -58,7 +58,7 @@ function libspell.GetSpellIndex(name, rank)
for id = offset + 1, offset + num do
local spellName, spellRank = GetSpellName(id, bookType)
if rank and rank == spellRank and name == string.lower(spellName) then
spellindex[name..rank] = { id, bookType }
spellindex[name.."("..rank..")"] = { id, bookType }
return id, bookType
elseif not rank and name == string.lower(spellName) then
spellindex[name] = { id, bookType }
@@ -67,7 +67,7 @@ function libspell.GetSpellIndex(name, rank)
end
end
spellindex[name..(rank or "")] = { nil }
spellindex[name..(rank and ("("..rank..")") or "")] = { nil }
return nil
end