View Single Post
02/12/22, 09:35 AM   #4
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,964
Also notable:
New table searching functions were added
https://github.com/esoui/esoui/blob/...tableutils.lua

Lua Code:
  1. -- Creates a non-contiguous table, the keys of which are the unique values
  2. -- in the numerically indexed table t or, if t is scalar, the value of t.
  3. function ZO_CreateSet(t)
  4.     local s = {}
  5.     local tType = type(t)
  6.     if tType == "table" then
  7.         for _, v in ipairs(t) do
  8.             s[v] = true
  9.         end
  10.     elseif tType ~= "nil" then
  11.         s[t] = true
  12.     end
  13.     return s
  14. end
  15.  
  16. -- Returns a non-contiguous table, the keys of which are the intersecting keys
  17. -- shared between the non-contiguous sets s1 and s2.
  18. function ZO_IntersectSets(s1, s2)
  19.     local s = {}
  20.     for k in pairs(s1) do
  21.         if s2[k] then
  22.             s[k] = true
  23.         end
  24.     end
  25.     return s
  26. end
  27.  
  28. -- Returns true if the non-contiguous sets s1 and s2 share one or more keys.
  29. function ZO_AreIntersectingSets(s1, s2)
  30.     return next(ZO_IntersectSets(s1, s2)) ~= nil
  31. end
  32.  
  33. -- Returns a non-contiguous table, the keys of which are the intersecting values
  34. -- shared between the numerically indexed tables t1 and t2.
  35. function ZO_IntersectNumericallyIndexedTables(t1, t2)
  36.     local s1 = ZO_CreateSet(t1)
  37.     local s2 = ZO_CreateSet(t2)
  38.     return ZO_IntersectSets(s1, s2)
  39. end
  40.  
  41. -- Returns true if the numerically indexed tables t1 and t2 share one or more values.
  42. function ZO_AreIntersectingNumericallyIndexedTables(t1, t2)
  43.     local s = ZO_IntersectNumericallyIndexedTables(t1, t2)
  44.     return next(s) ~= nil
  45. end
  46.  
  47. -- Returns true if the non-contiguous sets s1 and s2 contain the same keys.
  48. function ZO_AreEqualSets(s1, s2)
  49.     local size1 = NonContiguousCount(s1)
  50.     local size2 = NonContiguousCount(s2)
  51.     if size1 ~= size2 then
  52.         return false
  53.     end
  54.     for k in pairs(s1) do
  55.         if not s2[k] then
  56.             return false
  57.         end
  58.     end
  59.     return true
  60. end

Used in the new universal deconstruction filter function e.g. to compare the filterType's itemFilter (enchantments) or itemTypeFilters (armor, weapon, jewelry) with the itemType/itemFilterType of an inventory item.
Lua Code:
  1. function ZO_UniversalDeconstructionPanel_Shared.DoesItemPassFilter(bagId, slotIndex, filterType)
  2.     local itemFilterTypes = {GetItemFilterTypeInfo(bagId, slotIndex)}
  3.     if ZO_IsElementInNumericallyIndexedTable(itemFilterTypes, ITEMFILTERTYPE_JEWELRY) and not ZO_IsJewelryCraftingEnabled() then
  4.         return false
  5.     end
  6.  
  7.     if filterType then
  8.         if filterType.itemTypes then
  9.             local itemType = GetItemType(bagId, slotIndex)
  10.             if not ZO_AreIntersectingNumericallyIndexedTables(filterType.itemTypes, itemType) then
  11.                 return false
  12.             end
  13.         end
  14.  
  15.         if filterType.itemFilterTypes then
  16.             if not ZO_AreIntersectingNumericallyIndexedTables(filterType.itemFilterTypes, itemFilterTypes) then
  17.                 return false
  18.             end
  19.         end
  20.     end
  21.  
  22.     return true
  23. end

Last edited by Baertram : 02/12/22 at 09:38 AM.
  Reply With Quote