Thread Tools Display Modes
06-28-16, 02:23 AM   #1
Ketho
A Pyroguard Emberseer
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,026
Caching C_TransmogCollection.GetAppearanceSources names

This was in response to http://www.wowinterface.com/forums/s...ad.php?t=53787, but it had little to do with it

I've been sorting the visuals alphabetically in WardrobeSort but GetAppearanceSources would not include the name and quality half of the time
So I first had to cache them all

There is TRANSMOG_COLLECTION_ITEM_UPDATE but it doesn't have any return values for the respective item, instead it uses WardrobeCollectionFrame.tooltipAppearanceID or something

Is there a better way to go about this?





Lua Code:
  1. local f = CreateFrame("Frame")
  2.  
  3. local visualAppearance, visualIllusion = {}, {}
  4. local cacheAppearance, cacheIllusion = {}, {}
  5. local completed = {}
  6.  
  7. local function IsAppearance()
  8.     return (WardrobeCollectionFrame.transmogType == LE_TRANSMOG_TYPE_APPEARANCE)
  9. end
  10.  
  11. -- appearances/transmogs get the name via visualID
  12. -- illusions/enchants get the name via sourceID
  13. local function CheckVisuals()
  14.     -- grab all our data first
  15.     if not completed[WardrobeCollectionFrame.activeSlot] then
  16.         local isApp = IsAppearance()
  17.         local cache = isApp and cacheAppearance or cacheIllusion
  18.         local idType = isApp and "visualID" or "sourceID"
  19.  
  20.         for k, v in pairs(WardrobeCollectionFrame.filteredVisualsList) do
  21.             cache[v[idType]] = true -- queue data to be cached 
  22.         end
  23.        
  24.         f:SetScript("OnUpdate", f.GetVisuals)
  25.     else -- go ahead and sort
  26.         f:SortVisuals()
  27.     end
  28. end
  29.  
  30. -- takes around 30 onupdates
  31. function f:GetVisuals()
  32.     local isApp = IsAppearance()
  33.     if isApp then
  34.         -- need to use WardrobeCollectionFrame_GetSortedAppearanceSources
  35.         -- otherwise cant get the used header name consistently
  36.         for k in pairs(cacheAppearance) do
  37.             local t = WardrobeCollectionFrame_GetSortedAppearanceSources(k)
  38.             if t[1].name then
  39.                 visualAppearance[k] = t[1].name
  40.                 cacheAppearance[k] = nil -- remove
  41.             end
  42.         end
  43.     else
  44.         for k in pairs(cacheIllusion) do
  45.             local _, name = C_TransmogCollection.GetIllusionSourceInfo(k)
  46.             visualIllusion[k] = name
  47.             cacheIllusion[k] = nil
  48.         end
  49.     end
  50.     -- got all visuals for the wardrobe slot
  51.     if not next(isApp and cacheAppearance or cacheIllusion) then
  52.         completed[WardrobeCollectionFrame.activeSlot] = true -- remember
  53.         self:SetScript("OnUpdate", nil)
  54.         self:SortVisuals()
  55.     end
  56. end
  57.  
  58. function f:SortVisuals() -- finally we can sort
  59.     local isApp = IsAppearance()
  60.     local visual = isApp and visualAppearance or visualIllusion
  61.     local idType = isApp and "visualID" or "sourceID"
  62.    
  63.     sort(WardrobeCollectionFrame.filteredVisualsList, function(source1, source2)
  64.         if source1.isCollected ~= source2.isCollected then
  65.             return source1.isCollected
  66.         end
  67.         if source1.isUsable ~= source2.isUsable then
  68.             return source1.isUsable
  69.         end
  70.         if source1.isFavorite ~= source2.isFavorite then
  71.             return source1.isFavorite
  72.         end
  73.         if source1.isHideVisual ~= source2.isHideVisual then
  74.             return source1.isHideVisual
  75.         end
  76.        
  77.         local name1 = visual[source1[idType]]
  78.         local name2 = visual[source2[idType]]
  79.        
  80.         if name1 ~= name2 then
  81.             return name1 < name2 -- alphabetic
  82.         end
  83.        
  84.         if source1.uiOrder and source2.uiOrder then
  85.             return source1.uiOrder > source2.uiOrder
  86.         end
  87.         return source1.sourceID > source2.sourceID
  88.     end)
  89.    
  90.     WardrobeCollectionFrame_Update() -- update
  91. end
  92.  
  93. hooksecurefunc("WardrobeCollectionFrame_SortVisuals", CheckVisuals)

Last edited by Ketho : 06-30-16 at 01:28 PM.
 
06-28-16, 05:00 AM   #2
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Don't know if this helps, but you could try responding to the event and setting the next frame-OnUpdate there. That's what I do when mass querying item info.
__________________
Grab your sword and fight the Horde!
 
06-30-16, 12:58 PM   #3
Ketho
A Pyroguard Emberseer
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,026
Originally Posted by Lombra View Post
Don't know if this helps, but you could try responding to the event and setting the next frame-OnUpdate there. That's what I do when mass querying item info.

I thought of different ways to do it, but it mostly seemed to only complicate things further for me

Especially since TRANSMOG_COLLECTION_ITEM_UPDATE doesn't have any arguments like GET_ITEM_INFO_RECEIVED does, and is generally not used for mass querying, but only for the mouseovered visual on the gametooltip
_____

Another question, the previously posted code is generating a lot of garbage when caching(?) or sorting. It jumps between 1-9 MB of memory, but I have no idea why

I do call WardrobeCollectionFrame_GetSortedAppearanceSources for every visual until the name is cached, but that shouldn't use that much memory ... right?

(Edit 7/17) I finally realized discarding tables every OnUpdate until name was finally included is not really a memory-efficient way to do this

(╯°□°)╯︵ ┻━┻


Last edited by Ketho : 07-17-16 at 12:43 PM.
 
 

WoWInterface » Site Forums » Archived Beta Forums » Legion Beta archived threads » Caching C_TransmogCollection.GetAppearanceSources names

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off