aggixx

Untitled

Feb 19th, 2013
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.12 KB | None | 0 0
  1. function FARaidTools:itemCache(itemLink)
  2.     if debugOn then print("cacheItem(): Item info for item "..itemLink.." requested from server.") end
  3.     if #table_itemQuery == 0 then
  4.         table.insert(table_itemQuery, GetTime()+(cacheInterval/1000)) -- add a time so that onupdate knows when to check if the data is ready yet
  5.     end
  6.     table.insert(table_itemQuery, itemLink) -- add to the query queue
  7. end
  8.  
  9. function FARaidTools:itemAdd(itemLink)
  10.     if not GetItemInfo(itemLink) then -- check if the item needs to be cached
  11.         FARaidTools:itemCache(itemLink) -- we don't have item data so we have to cache the item
  12.         return                                     -- itemAdd will be called again via onUpdate once it's ready
  13.                                                      -- potential problem here if this code triggers from onUpdate, but it shouldnt
  14.     end
  15.    
  16.     local id
  17.     for i=1,#table_mainData do
  18.         local match = string.match(table_mainData[i]["cols"][1]["value"], hyperlinkPattern)
  19.         if match == nil then
  20.             print("Error: match returned nil. i="..i)
  21.             DevTools_Dump(table_mainData[i])
  22.             return
  23.         end
  24.         local link1 = stripItemData(match)
  25.         local link2 = stripItemData(itemLink)
  26.         if link1 == link2 then
  27.             id = i
  28.             if debugOn then print("addToLootWindow(): Found match in data table. ID #"..id) end
  29.             break
  30.         end
  31.     end
  32.     if id then
  33.         local quantity = tonumber(string.match(table_mainData[id]["cols"][1]["value"], "x(%d+)$")) or 1
  34.         table_mainData[id]["cols"][1]["value"] = string.match(table_mainData[id]["cols"][1]["value"], hyperlinkPattern).."x"..tostring(quantity+1)
  35.     else
  36.         table.insert(table_mainData, {
  37.             ["cols"] = {
  38.                 {
  39.                     ["value"] = itemLink,
  40.                     ["args"] = nil,
  41.                     ["color"] = {
  42.                         ["r"] = 1.0,
  43.                         ["g"] = 1.0,
  44.                         ["b"] = 1.0,
  45.                         ["a"] = 1.0,
  46.                     },
  47.                     ["colorargs"] = nil,
  48.                     ["DoCellUpdate"] = nil,
  49.                 },
  50.                 {
  51.                     ["value"] = "30",
  52.                     ["args"] = nil,
  53.                     ["color"] = {
  54.                         ["r"] = 0.5,
  55.                         ["g"] = 0.5,
  56.                         ["b"] = 0.5,
  57.                         ["a"] = 1.0,
  58.                     },
  59.                     ["colorargs"] = nil,
  60.                     ["DoCellUpdate"] = nil,
  61.                 },
  62.                 {
  63.                     ["value"] = "",
  64.                     ["args"] = nil,
  65.                     ["color"] = {
  66.                         ["r"] = 1.0,
  67.                         ["g"] = 1.0,
  68.                         ["b"] = 1.0,
  69.                         ["a"] = 1.0,
  70.                     },
  71.                     ["colorargs"] = nil,
  72.                     ["DoCellUpdate"] = nil,
  73.                 },
  74.             },
  75.             ["color"] = {
  76.                 ["r"] = 1.0,
  77.                 ["g"] = 0.0,
  78.                 ["b"] = 0.0,
  79.                 ["a"] = 1.0,
  80.             },
  81.             ["colorargs"] = nil,
  82.             ["DoCellUpdate"] = nil,
  83.         })
  84.     end
  85.     FA_RTscrollingtable:SetData(table_mainData, false)
  86.     FARaidTools:generateIcons()
  87.     if not FA_RTframe:IsShown() then
  88.         if UnitAffectingCombat("PLAYER") then
  89.             showAfterCombat = true
  90.             print("RT: "..itemLink.." was found but the player is in combat.")
  91.         else
  92.             FA_RTframe:Show()
  93.         end
  94.     end
  95. end
  96.  
  97. local function onUpdate(self,elapsed)
  98.     local currentTime = GetTime() -- get the time and put it in a variable so we don't have to call it a billion times throughout this function
  99.    
  100.     --[[ some other stuff --]]
  101.  
  102.     -- Item caching stuff
  103.     if table_itemQuery[1] and currentTime >= table_itemQuery[1] then
  104.         if debugOn then print("Checking for item info for "..(#table_itemQuery-1).." items...") end
  105.         table_itemQuery[1] = currentTime+(cacheInterval/1000)
  106.        
  107.         local list_size = #table_itemQuery
  108.         for i=0,list_size-2 do -- loop backwards through list of items waiting to be cached
  109.             if GetItemInfo(table_itemQuery[list_size-i]) then -- check if this item in the list is cached yet
  110.                 if debugOn then print("Item info for "..table_itemQuery[list_size-i].." is ready, adding to loot window.") end
  111.                 FARaidTools:itemAdd(table_itemQuery[list_size-i]) -- it's ready so add it to the loot window
  112.                 table.remove(table_itemQuery, list_size-i) -- remove the entry from the query list
  113.             --[[else
  114.                 if debugOn then print("Item info for "..table_itemQuery[list_size-i].." was not found.") end--]]
  115.             end
  116.         end
  117.        
  118.         if #table_itemQuery == 1 then
  119.             table_itemQuery = {}
  120.         elseif debugOn then
  121.             print("Item info for "..(#table_itemQuery-1).." items is not ready. Checking again in "..cacheInterval.."ms.")
  122.         end
  123.     end
  124. end
  125.  
  126. local ouframe = CreateFrame("frame")
  127. ouframe:SetScript("OnUpdate", onUpdate)
Advertisement
Add Comment
Please, Sign In to add comment