Quantcast New Item API - WoWInterface
Thread Tools Display Modes
05-30-18, 09:13 PM   #1
thomasjohnshannon
A Theradrim Guardian
 
thomasjohnshannon's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 62
New Item API

If any of you have had to deal with getting item info in the past you will love the new item api. I have a bag addon that I use (my version isn't public) and always had problems getting the correct item level since GetItemInfo hadn't been fixed to deal with scaling item level. The new API made it really easy all it took was a few lines.

Lua Code:
  1. local item = Item:CreateFromBagAndSlot(bagID, slotID)
  2.  
  3. if ( item ) then
  4.     ilevel = item:GetCurrentItemLevel()
  5. end

I'm creating from the bagID and slotID because the code was already setup that way but you can also set it up from an item link, equipment slot, or the new item location mixin.

Lua Code:
  1. --[[static]] function Item:CreateFromItemLocation(itemLocation)
  2.     if type(itemLocation) ~= "table" or type(itemLocation.HasAnyLocation) ~= "function" or not itemLocation:HasAnyLocation() then
  3.         error("Usage: Item:CreateFromItemLocation(notEmptyItemLocation)", 2);
  4.     end
  5.     local item = CreateFromMixins(ItemMixin);
  6.     item:SetItemLocation(itemLocation);
  7.     return item;
  8. end
  9.  
  10. --[[static]] function Item:CreateFromBagAndSlot(bagID, slotIndex)
  11.     if type(bagID) ~= "number" or type(slotIndex) ~= "number" then
  12.         error("Usage: Item:CreateFromBagAndSlot(bagID, slotIndex)", 2);
  13.     end
  14.     local item = CreateFromMixins(ItemMixin);
  15.     item:SetItemLocation(ItemLocation:CreateFromBagAndSlot(bagID, slotIndex));
  16.     return item;
  17. end
  18.  
  19. --[[static]] function Item:CreateFromEquipmentSlot(equipmentSlotIndex)
  20.     if type(equipmentSlotIndex) ~= "number" then
  21.         error("Usage: Item:CreateFromEquipmentSlot(equipmentSlotIndex)", 2);
  22.     end
  23.     local item = CreateFromMixins(ItemMixin);
  24.     item:SetItemLocation(ItemLocation:CreateFromEquipmentSlot(equipmentSlotIndex));
  25.     return item;
  26. end
  27.  
  28. --[[static]] function Item:CreateFromItemLink(itemLink)
  29.     if type(itemLink) ~= "string" then
  30.         error("Usage: Item:CreateFromItemLink(itemLinkString)", 2);
  31.     end
  32.     local item = CreateFromMixins(ItemMixin);
  33.     item:SetItemLink(itemLink);
  34.     return item;
  35. end

I'm still looking into the new api so that is probably just scratching the surface of what you can do with it. If you want the full details you can find them in ItemDocumentation.lua in the API folder and under Item.lua in FrameXML\ObjectAPI.
__________________
Thomas aka Urnn
  Reply With Quote
05-31-18, 02:08 AM   #2
runamonk
A Wyrmkin Dreamwalker
 
runamonk's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 56
I scan the tooltip and pull the scaled item level from there, it works everytime.

This looks interesting.
  Reply With Quote
05-31-18, 03:28 AM   #3
thomasjohnshannon
A Theradrim Guardian
 
thomasjohnshannon's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 62
Originally Posted by runamonk View Post
I scan the tooltip and pull the scaled item level from there, it works everytime.

This looks interesting.
That is what I was using before but this is a lot easier. One side note is you may need to wrap the code in the following code if it is going to load at startup.

Lua Code:
  1. local item = Item:CreateFromBagAndSlot(bagID, slotID)
  2. item:ContinueOnItemLoad(function()
  3.   -- Do thing with the data here.
  4. end)

The way they have item and spell data it needs to make sure everything is loaded before when the player first logs in.

-----

Oh and it also has a function to check if an item is soulbound or not.

Lua Code:
  1. local item = Item:CreateFromBagAndSlot(bagID, slotID)
  2.  
  3. item:ContinueOnItemLoad(function()
  4.     local location = item:GetItemLocation()
  5.     local isSoulbound = C_Item.IsBound(location)
  6.  
  7.     -- Do stuff here.
  8. end)
__________________
Thomas aka Urnn

Last edited by thomasjohnshannon : 05-31-18 at 03:35 AM.
  Reply With Quote
05-31-18, 03:33 AM   #4
runamonk
A Wyrmkin Dreamwalker
 
runamonk's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 56
Cool deal, it will certainly be much more efficient than pulling back a tooltip data for every armor or weapon to get the level.
  Reply With Quote
05-31-18, 09:49 AM   #5
sezz
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 100
doesn't seem to work well when using item links

sample link (random weapon from a random level 120 guy in orgrimmar, since my highest char in beta is only 111)
Code:
"|cffa335ee|Hitem:154416:3370:::::::111:63:512:11:2:4811:4815:120:::|h[Trogg Saurolisk-Breaker]|h|r"
new api returns 229, that's the item level of the weapon scaled down to level 111 (my level)

i'll try it again in a month

edit: the problem is that the linkLevel in the itemString returned by GetInventoryItemLink() has to be adjusted, still faster than tooltip scanning

Last edited by sezz : 06-09-18 at 04:16 PM.
  Reply With Quote
09-04-18, 12:44 AM   #6
runamonk
A Wyrmkin Dreamwalker
 
runamonk's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 56
I think they might have fixed GetDetailedItemLevelInfo(). It appears to be returning the correct level information now.
  Reply With Quote
09-04-18, 06:29 AM   #7
Ammako
A Frostmaul Preserver
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 256
Huh, that'd be interesting if they had fixed that already. I'm going to have to verify that later.
  Reply With Quote
09-04-18, 08:44 AM   #8
runamonk
A Wyrmkin Dreamwalker
 
runamonk's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 56
and surprising to say the least. I haven't tested scaling down yet. So that could still be borked.
  Reply With Quote
09-04-18, 04:34 PM   #9
Ammako
A Frostmaul Preserver
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 256
False alarm, it's still borked in the same way sadly.
  Reply With Quote
09-05-18, 05:12 AM   #10
runamonk
A Wyrmkin Dreamwalker
 
runamonk's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 56
Yep..Scaled levels are still wacked out.
  Reply With Quote
10-22-18, 01:37 AM   #11
doofus
A Theradrim Guardian
Join Date: Feb 2018
Posts: 63
An old thread, sorry.

I am trying to get the item level, and as far as I can tell, there are two, main API functions

GetItemInfo

and

GetDetailedItemLevelInfo


and they are both currently not working properly, definitely for down-scaling.

Is there another API we can use? How does the item tooltip deduce the correct iLvl ?

Edit: to provide more information, parsing the tooltip is also wrong, I parse "Item Level 280" and on screen it shows as "Item Level 266".

Last edited by doofus : 10-22-18 at 02:19 AM.
  Reply With Quote
10-22-18, 04:09 AM   #12
runamonk
A Wyrmkin Dreamwalker
 
runamonk's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 56
You can parse the item level out of the tooltip, that is accurate. That's what we're all doing at this point.

Lua Code:
  1. function mnkDurability.GetItemLevel(slotID)
  2.     local tip = CreateFrame("GameTooltip", "scanTip", UIParent, "GameTooltipTemplate")
  3.     tip:ClearLines()
  4.     tip:SetOwner(UIParent,"ANCHOR_NONE")
  5.     tip:SetInventoryItem("player", slotID)
  6.     for i=1, 5 do
  7.         local l = _G["scanTipTextLeft"..i]:GetText()
  8.         if l and l:find('Item Level') then
  9.             local _, i = string.find(l, 'Item Level%s%d')
  10.             -- check for boosted levels ie Chromeie scenarios.
  11.             local _, x = string.find(l, " (", 1, true)
  12.             --print(t, ' ', x)
  13.             if x then
  14.                 return string.sub(l, i, x-2) or '-'
  15.             end
  16.             return string.sub(l, i) or -'-'            
  17.         end
  18.     end
  19.  
  20.     return '-'
  21. end
  Reply With Quote
10-22-18, 07:41 AM   #13
doofus
A Theradrim Guardian
Join Date: Feb 2018
Posts: 63
I already parse the tooltip, and instead of using GameTooltip:SetInventoryItem as you have suggested, I use GameTooltip:SetHyperlink which allows me to inquire about items not in my bags.

But your comment made me look deeper and I have found one bug (at least) with GetCursorInfo. Imagine Green item, BoE, in guild bank, level = 120 and ilvl = 266.

When the item is in the guild bank and I pick it up, I get something like
"Sandscout Tunic" ilvl = 280. When the item is in my inventory I get something like "Sandscout tunic of the quickblade" ilvl = 266.
  Reply With Quote
10-22-18, 07:42 AM   #14
runamonk
A Wyrmkin Dreamwalker
 
runamonk's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 56
Yeah that method is from a durability addon I wrote so I can see all my gear I'm wearing. It tracks the items, durability and item levels blah blah blah hehe.. I use a similar but different routine for my bags and bank addon.

Hopefully they'll fix the actual methods and we won't have to jump through these silly hoops.

Becareful how much tooltip scanning you do, I ran into a situation were I was doing too much and it was causing my UI to randomly go totally blank lol. It was good stuff.

Last edited by runamonk : 10-22-18 at 07:48 AM.
  Reply With Quote

WoWInterface » PTR » PTR API and Graphics Changes » New Item API

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