Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update spell cache to latest version #103

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 43 additions & 25 deletions WeakAurasOptions/Cache.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,24 @@ function spellCache.Build()
local co = coroutine.create(function()
local id = 0
local misses = 0

while misses < 53000 do
while misses < 50000 do
id = id + 1
local name, _, icon = GetSpellInfo(id)

if(icon == 136243) then -- 136243 is the a gear icon, we can ignore those spells
if(icon and icon:lower() == "interface\\icons\\trade_engineering") then -- 136243 is the a gear icon, we can ignore those spells
misses = 0;
elseif name and name ~= "" then
elseif name and name ~= "" and icon then
cache[name] = cache[name] or {}
cache[name].spells = cache[name].spells or {}
cache[name].spells[id] = icon

if not cache[name].spells or cache[name].spells == "" then
cache[name].spells = id .. "=" .. icon
else
cache[name].spells = cache[name].spells .. "," .. id .. "=" .. icon
end
misses = 0
else
misses = misses + 1
end

coroutine.yield()
end

Expand All @@ -56,8 +58,11 @@ function spellCache.Build()
local id,name,_,_,_,_,_,_,_,iconID = GetAchievementInfo(category, i)
if name and iconID then
cache[name] = cache[name] or {}
cache[name].achievements = cache[name].achievements or {}
cache[name].achievements[id] = iconID
if not cache[name].achievements or cache[name].achievements == "" then
cache[name].achievements = id .. "=" .. iconID
else
cache[name].achievements = cache[name].achievements .. "," .. id .. "=" .. iconID
end
end
end
coroutine.yield()
Expand Down Expand Up @@ -91,38 +96,50 @@ function spellCache.GetIcon(name)
local bestMatch = nil
if (icons) then
if (icons.spells) then
for spellId, icon in pairs(icons.spells) do
if not bestMatch or (type(spellId) == "number" and IsSpellKnown(spellId)) then
bestMatch = spellId
for spell, icon in icons.spells:gmatch("(%d+)=([^,]+)") do
local spellId = tonumber(spell)

if not bestMatch or (spellId and IsSpellKnown(spellId)) then
bestMatch = tonumber(icon)
end
end
end
end

bestIcon[name] = bestMatch and icons.spells[bestMatch];
return bestIcon[name];
bestIcon[name] = bestMatch
return bestIcon[name]
else
error("spellCache has not been loaded. Call WeakAuras.spellCache.Load(...) first.")
end
end

function spellCache.GetSpellsMatching(name)
if cache[name] then
return cache[name].spells
if cache[name].spells then
local result = {}
for spell, icon in cache[name].spells:gmatch("(%d+)=([^,]+)") do
local spellId = tonumber(spell)
local iconId = tonumber(icon)
result[spellId] = icon
end
return result
end
end
end

function spellCache.AddIcon(name, id, icon)
if cache then
if name then
cache[name] = cache[name] or {}
cache[name].spells = cache[name].spells or {}
if id and icon then
cache[name].spells[id] = icon
end
end
else
if not cache then
error("spellCache has not been loaded. Call WeakAuras.spellCache.Load(...) first.")
return
end

if name and id and icon then
cache[name] = cache[name] or {}
if not cache[name].spells or cache[name].spells == "" then
cache[name].spells = id .. "=" .. icon
else
cache[name].spells = cache[name].spells .. "," .. id .. "=" .. icon
end
end
end

Expand All @@ -147,11 +164,12 @@ function spellCache.Load(data)
num = num + 1;
end

if(num < 39000 or metaData.locale ~= locale or metaData.build ~= build or metaData.version ~= version or not metaData.spellCacheAchivements) then
if(num < 39000 or metaData.locale ~= locale or metaData.build ~= build or metaData.version ~= version or not metaData.spellCacheStrings) then
metaData.build = build;
metaData.locale = locale;
metaData.version = version;
metaData.spellCacheAchivements = true
metaData.spellCacheStrings = true
metaData.needsRebuild = true
wipe(cache)
end
Expand Down
4 changes: 2 additions & 2 deletions WeakAurasOptions/OptionsFrames/IconPicker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ local function ConstructIconPicker(frame)
for name, icons in pairs(spellCache.Get()) do
if(name:lower():find(subname, 1, true)) then
if icons.spells then
for spellId, icon in pairs(icons.spells) do
for spell, icon in icons.spells:gmatch("(%d+)=([^,]+)") do
if (not usedIcons[icon]) then
AddButton(name, icon)
num = num + 1;
Expand All @@ -76,7 +76,7 @@ local function ConstructIconPicker(frame)
end
end
elseif icons.achievements then
for _, icon in pairs(icons.achievements) do
for _, icon in icons.achievements:gmatch("(%d+)=([^,]+)") do
if (not usedIcons[icon]) then
AddButton(name, icon)
num = num + 1;
Expand Down