Skip to content

Commit

Permalink
Use C_Item api and get ready for TWW
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbuds authored and Stanzilla committed May 9, 2024
1 parent b9f4c96 commit 6896366
Showing 1 changed file with 34 additions and 11 deletions.
45 changes: 34 additions & 11 deletions LibRangeCheck-3.0/LibRangeCheck-3.0.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ License: MIT
-- @class file
-- @name LibRangeCheck-3.0
local MAJOR_VERSION = "LibRangeCheck-3.0"
local MINOR_VERSION = 14
local MINOR_VERSION = 15

---@class lib
local lib, oldminor = LibStub:NewLibrary(MAJOR_VERSION, MINOR_VERSION)
Expand All @@ -67,11 +67,8 @@ local tremove = tremove
local tostring = tostring
local setmetatable = setmetatable
local BOOKTYPE_SPELL = BOOKTYPE_SPELL
local GetSpellInfo = GetSpellInfo
local GetSpellBookItemName = GetSpellBookItemName
local GetNumSpellTabs = GetNumSpellTabs
local GetSpellTabInfo = GetSpellTabInfo
local GetItemInfo = GetItemInfo
local C_Item = C_Item
local UnitCanAttack = UnitCanAttack
local UnitCanAssist = UnitCanAssist
local UnitExists = UnitExists
Expand All @@ -89,6 +86,32 @@ local HandSlotId = GetInventorySlotInfo("HANDSSLOT")
local math_floor = math.floor
local UnitIsVisible = UnitIsVisible

local GetSpellInfo = GetSpellInfo or function(spellID)
if not spellID then
return nil;
end

local spellInfo = C_Spell.GetSpellInfo(spellID);
if spellInfo then
return spellInfo.name, nil, spellInfo.iconID, spellInfo.castTime, spellInfo.minRange, spellInfo.maxRange, spellInfo.spellID, spellInfo.originalIconID;
end
end

local GetNumSpellTabs = GetNumSpellTabs or C_SpellBook.GetNumSpellBookSkillLines
local GetSpellTabInfo = GetSpellTabInfo or function(index)
local skillLineInfo = C_SpellBook.GetSpellBookSkillLineInfo(index);
if skillLineInfo then
return skillLineInfo.name,
skillLineInfo.iconID,
skillLineInfo.itemIndexOffset,
skillLineInfo.numSpellBookItems,
skillLineInfo.isGuild,
skillLineInfo.offSpecID,
skillLineInfo.shouldHide,
skillLineInfo.specID;
end
end

-- << STATIC CONFIG

local UpdateDelay = 0.5
Expand Down Expand Up @@ -676,7 +699,7 @@ local function createCheckerList(spellList, itemList, interactList)
for range, items in pairs(itemList) do
for i = 1, #items do
local item = items[i]
if Item:CreateFromItemID(item):IsItemDataCached() and GetItemInfo(item) then
if Item:CreateFromItemID(item):IsItemDataCached() and C_Item.GetItemInfo(item) then
addChecker(res, range, nil, checkers_Item[item], "item:" .. item)
break
end
Expand Down Expand Up @@ -912,9 +935,9 @@ local function createSmartChecker(friendChecker, harmChecker, miscChecker)
end

local minItemChecker = function(item)
if GetItemInfo(item) then
if C_Item.GetItemInfo(item) then
return function(unit)
return IsItemInRange(item, unit)
return C_Item.IsItemInRange(item, unit)
end
end
end
Expand Down Expand Up @@ -1271,7 +1294,7 @@ function lib:processItemRequests(itemRequests)
tremove(items, i)
elseif pendingItemRequest[item] and GetTime() < itemRequestTimeoutAt[item] then
return true -- still waiting for server response
elseif GetItemInfo(item) then
elseif C_Item.GetItemInfo(item) then
-- print("### processItemRequests: found: " .. tostring(item))
foundNewItems = true
itemRequestTimeoutAt[item] = nil
Expand Down Expand Up @@ -1409,7 +1432,7 @@ function lib:startMeasurement(unit, resultTable)
for range, items in pairs(itemList) do
for i = 1, #items do
local item = items[i]
local name = GetItemInfo(item)
local name = C_Item.GetItemInfo(item)
if name then
self.itemsToMeasure[name] = item
end
Expand Down Expand Up @@ -1449,7 +1472,7 @@ function lib:checkItems(itemList, verbose, color)
for range, items in pairsByKeys(itemList) do
for i = 1, #items do
local item = items[i]
local name = GetItemInfo(item)
local name = C_Item.GetItemInfo(item)
if not name then
print(MAJOR_VERSION .. ": |c" .. color .. tostring(item) .. "|r: " .. tostring(range) .. "yd: |cffeda500not in cache|r")
else
Expand Down

0 comments on commit 6896366

Please sign in to comment.