Skip to content

Commit

Permalink
4.2: Downport icon caching from retail
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew6180 committed Dec 13, 2023
1 parent 2552730 commit acd2b0d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 33 deletions.
2 changes: 1 addition & 1 deletion WeakAuras/WeakAuras.toc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Interface: 30300
## Title: WeakAuras
## Author: The WeakAuras Team
## Version: 4.1.7
## Version: 4.2
## Notes: A powerful, comprehensive utility for displaying graphics and information based on buffs, debuffs, and other triggers.
## Notes-esES: Potente y completa aplicación que te permitirá mostrar por pantalla múltiples diseños, basados en beneficios, perjuicios y otros activadores.
## Notes-deDE: Ein leistungsfähiges, umfassendes Addon zur grafischen Darstellung von Informationen von Auren, Cooldowns, Timern und vielem mehr.
Expand Down
75 changes: 47 additions & 28 deletions WeakAurasOptions/Cache.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,38 @@ function spellCache.Build()
local co = coroutine.create(function()
local id = 0
local misses = 0

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

if(icon == 136243) 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

for _, category in pairs(GetCategoryList()) do
local total = GetCategoryNumAchievements(category, true)
for i = 1, total do
local id,name,_,_,_,_,_,_,_,iconID = GetAchievementInfo(category, i)
if name and iconID then
local id,name,_,_,_,_,_,_,_,icon = GetAchievementInfo(category, i)
if name and icon 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 .. "=" .. icon
else
cache[name].achievements = cache[name].achievements .. "," .. id .. "=" .. icon
end
end
end
coroutine.yield()
Expand Down Expand Up @@ -91,38 +96,49 @@ 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 = 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)
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 +163,14 @@ 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.spellCacheAchievements = true
metaData.spellCacheStrings = true
metaData.needsRebuild = true
wipe(cache)
end
Expand Down Expand Up @@ -229,4 +248,4 @@ function spellCache.CorrectAuraName(input)
return ret, nil;
end
end
end
end
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 _, 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
2 changes: 0 additions & 2 deletions WeakAurasOptions/WeakAurasOptions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,7 @@ loadedFrame:SetScript("OnEvent", function(self, event, addon)
if(addon == ADDON_NAME) then
db = WeakAurasSaved;
WeakAurasOptionsSaved = WeakAurasOptionsSaved or {};

odb = WeakAurasOptionsSaved;

-- Remove icon and id cache (replaced with spellCache)
if (odb.iconCache) then
odb.iconCache = nil;
Expand Down

0 comments on commit acd2b0d

Please sign in to comment.