Quantcast
New Item API - WoWInterface
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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: 65
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
 

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