View Single Post
05-21-18, 07:32 PM   #5
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
Alternative Spell Cache Option

After some further testing it appears that the SpellMixin way of working isn't exactly the greatest. It's definitely lightweight but it doesn't work for unknown spells until a second call. However, the following seems to work everytime on a fresh login.

Lua Code:
  1. --[[ Cache the on demand values ]]--
  2. local function CacheSpellData(spellID)
  3.     addonData.SpellCache = {}
  4.     addonData.SpellCache[spellID] = {}
  5.    
  6.     local id,fileID = GetSpellTexture(spellID)
  7.     local name = GetSpellInfo(spellID)
  8.     local isKnown = IsSpellKnown(spellID)
  9.    
  10.     addonData.SpellCache[spellID].TextureID = fileID    
  11.     addonData.SpellCache[spellID].Name = name
  12.     addonData.SpellCache[spellID].isKnown = isKnown
  13.    
  14. end
  15.  
  16. --[[ Get the required information for the spellID, if not cached, cache it ]]
  17. function addonData:GetSpellInfo(spellID)
  18.     if not self.SpellCache[spellID] then
  19.         CacheSpellData(spellID)
  20.     end
  21.     local cache = self.SpellCache[spellID]
  22.     return cache.Name, cache.TextureID, cache.isKnown
  23. end
  24.  
  25. --[[ Monitor for SpellCache Request Results ]]--
  26. local function EventWatcher(self,event,...)
  27.     if event == "PLAYER_ENTERING_WORLD" then
  28.         for i,v in pairs(addonData.Spells) do
  29.             C_Spell.RequestLoadSpellData(i)
  30.         end        
  31.     elseif event == "SPELL_DATA_LOAD_RESULT" then
  32.         local spellID,success = ...
  33.         if success and addonData.Spells[spellID] then
  34.             CacheSpellData(spellID)
  35.         end
  36.     end
  37. end
  38.  
  39. local f = CreateFrame("Frame")
  40. f:RegisterEvent("PLAYER_ENTERING_WORLD")
  41. f:RegisterEvent("SPELL_DATA_LOAD_RESULT")
  42. f:SetScript("OnEvent", EventWatcher)
__________________
  Reply With Quote