From 150051a79ae1a75aa6bb7205877220f7e9a7cc52 Mon Sep 17 00:00:00 2001 From: shagu Date: Sat, 4 Sep 2021 21:05:52 +0200 Subject: [PATCH] libspell: make spell queries case insensitive --- libs/libspell.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libs/libspell.lua b/libs/libspell.lua index da8f02d0..75150652 100644 --- a/libs/libspell.lua +++ b/libs/libspell.lua @@ -45,6 +45,7 @@ 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 "")] if cache then return cache[1], cache[2] end @@ -55,15 +56,16 @@ function libspell.GetSpellIndex(name, rank) local bookType = BOOKTYPE_SPELL for id = offset + 1, offset + num do local spellName, spellRank = GetSpellName(id, bookType) - if rank and rank == spellRank and name == spellName then + if rank and rank == spellRank and name == string.lower(spellName) then spellindex[name..rank] = { id, bookType } return id, bookType - elseif not rank and name == spellName then + elseif not rank and name == string.lower(spellName) then spellindex[name] = { id, bookType } return id, bookType end end end + spellindex[name..(rank or "")] = { nil } return nil end @@ -96,6 +98,11 @@ function libspell.GetSpellInfo(index, bookType) name = sname or index rank = srank or libspell.GetSpellMaxRank(name) id, bookType = libspell.GetSpellIndex(name, rank) + + -- correct name in case of wrong upper/lower cases + if id and bookType then + name = GetSpellName(id, bookType) + end else name, rank = GetSpellName(index, bookType) id, bookType = libspell.GetSpellIndex(name, rank)