Quantcast New Item API - WoWInterface
Thread Tools Display Modes
05-30-18, 09:13 PM   #1
thomasjohnshannon
A Wyrmkin Dreamwalker
 
thomasjohnshannon's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 53
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
An Aku'mai Servant
 
runamonk's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 31
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 Wyrmkin Dreamwalker
 
thomasjohnshannon's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 53
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
An Aku'mai Servant
 
runamonk's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2007
Posts: 31
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 Warpwood Thunder Caller
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 94
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

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