LibBagUtils-1.0

This project has become inactive.

This project is inactive and its default file will likely not work with the most recent version of World of Warcraft. The author may have abandoned it, or it may have outlived its usefulness.

Several useful bag related APIs that you wish were built into the WoW API:

  local LBU = LibStub("LibBagUtils-1.0")
  
  for bag,slot in LBU:Iterate("BANK", "Major Healing Potion") do
    LBU:PutItem("BAGS")
  end

:Iterate("which"[, "lookingfor"])

which
string: "BAGS", "BANK", "BAGSBANK"
lookingfor
OPTIONAL: itemLink, itemName, itemString or itemId(number). Will not match partial names.

Returns an iterator that can be used in a for loop, e.g.:

for bag,slot,link in LBU:Iterate("BAGS") do   -- loop all slots
for bag,slot,link in LBU:Iterate("BAGSBANK", 29434) do  -- find all badges of justice

:Find("where", "lookingfor"[, notLocked])

where
string: "BAGS", "BANK", "BAGSBANK"
lookingfor
itemLink, itemName, itemString or itemId(number)
notLocked
OPTIONAL: if true, will NOT return locked slots
Returns:
bag,slot,link or nil' on failure

Finds the first instance of what you are looking for. To find all, use :Iterate() instead.

:FindSmallestStack("where", "lookingfor"[, notLocked])

where
string: "BAGS", "BANK", "BAGSBANK"
lookingfor
itemLink, itemName, itemString or itemId(number)
notLocked
OPTIONAL: if true, will NOT return locked slots
Returns:
bag,slot,size or nil' on failure

Finds the smallest stack of what you are looking for. To find all, use :Iterate() instead.

:PutItem("where"[, count[, dontClearOnFail]])

The easiest way to move items between bags and bank is of course to simply "click" them, but that doesn't work when you split stacks. That's when this function is handy.

PutItem is ''smart''; it will try to use specialty bags before standard bags. (But it will not try to put e.g. herb bags in herb bags. Doh.)

where
string: "BAGS", "BANK", "BAGSBANK"
count
OPTIONAL: number: if given, PutItem() will attempt to stack the item on top of another suitable stack. This is not possible without knowing the count, so if not given, it will simply be put in an empty slot. Default: nil.
dontClearOnFail
OPTIONAL: boolean: If the put operation fails due to no room, do NOT clear the cursor. Default: false. (Note that some other wow client errors WILL clear the cursor)
Returns:
bag,slot or false for out-of-room.
If called without an item in the cursor, 0,0 will be returned (slot 0 does not exist)
fullLink
string: A full item link as given by WoW APIs
lookingfor
string: itemLink, itemName, itemString or itemId(number). Will not match partial names.

Returns true if "lookingfor" matches "fullLink". Ignores in-constant info (i.e. level / wobbly 3.2 randomstats) in links.

lookingfor
string: itemLink, itemName, itemString or itemId(number). Will not match partial names.

Returns a comparator function and two arguments, that can be used to rapidly compare several itemlinks to a set search pattern.

This comparator will

Example:

local comparator,arg1,arg2 = LBU:MakeLinkComparator(myItemString)
for _,itemLink in pairs(myItems) do
  if comparator(itemLink, arg1,arg2) then
    print(itemLink, "matches", myItemString)

:IterateBags("which", itemFamily)

which
string: "BAGS", "BANK", "BAGSBANK"
itemFamily
number: bitmasked itemFamily; will accept binary-OR:ed combinations of itemFamily values. 0 = iterate only regular bags.
nil: iterate ALL bags, including keyring and possible future "special" bags

Returns an iterator that can be used in a for loop, e.g.:

for bag in LBU:IterateBags("BAGS",0) do   -- loop all regular bags

:CountSlots("which", itemFamily)

which
string: "BAGS", "BANK", "BAGSBANK"
itemFamily
number: bitmasked itemFamily; will accept binary-OR:ed combinations of itemFamily values. 0 = iterate only regular bags.
nil: iterate ALL bags, including keyring and possible future "special" bags

Returns numFreeSlots, numTotalSlots. Note that the bank is considered to have 0 slots unless the bank frame is open.

:IsBank(bag)

Returns true if a bag is a bank bag (or the bag frame). Yes, easily coded yourself, but I did it right and used the FrameXML constants so it'll actually keep working when Blizzard adds yet another bag.

:GetContainerNumFreeSlots(bag)

Returns slots, family like you would expect. Except it actually works for the keyring also, which Blizzard's API does not.

:GetContainerFamily(bag)

Returns the bag's family. Including the correct bitmask for the keyring, which Blizzard's API does not.

You must login to post a comment. Don't have an account? Register to get one!

Facts

Date created
Nov 22, 2008
Category
Last update
May 24, 2013
Development stage
Inactive
Language
  • enUS
License
Public Domain
Curse link
LibBagUtils-1.0
Reverse relationships
3
Downloads
11,390
Recent files
  • A: r32 for 5.3.0 May 24, 2013
  • A: r31 for 5.2.0 Mar 09, 2013
  • A: r30 for 5.1.0 Dec 19, 2012
  • A: r29 for 5.0.4 Sep 02, 2012
  • R: 1.0.27 for 4.3 Dec 01, 2011

Authors

  • Avatar of mikk
    • Manager
    • Author