WoWInterface SVN kRestack

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /trunk
    from Rev 12 to Rev 13
    Reverse comparison

Rev 12 → Rev 13

kRestack/changelog.txt New file
0,0 → 1,2
r13 release 2009-05-13
- Added option to auto-stack when opening bags or bank, off by default. Toggle with '/restack auto'
\ No newline at end of file
kRestack/kRestack.lua
1,18 → 1,33
--[[ kRestack() is a global function and can be used in any addon or macro
Some of the functionality is based on ArkInventory's restacking function, kudos!
 
Usage: /restack [bags, bank, auto] ]]
Usage: /restack [bags, bank, auto]
Devs: kRestack("bags") and kRestack("bank") can be used in your addons. ]]
 
SlashCmdList["RESTACK"] = function(s) kRestack(s) end
SLASH_RESTACK1 = "/restack"
 
--[[ insert backpack and default bank container ]]
local container = { bags = { 0 }, bank = { -1 } }
 
--[[ initialize user's bag and bank identifiers ]]
for i = 1, NUM_BAG_SLOTS do table.insert(container.bags, i) end
for i = NUM_BAG_SLOTS + 1, NUM_BAG_SLOTS + NUM_BANKBAGSLOTS do table.insert(container.bank, i) end
 
local frame = CreateFrame("FRAME")
frame:RegisterEvent("BANKFRAME_OPENED")
frame:SetScript("OnEvent", function(_, event)
if event == "BANKFRAME_OPENED" and AutoRestack then
kRestack("bank", true)
end
end)
 
local oToggleBackpack = ToggleBackpack
ToggleBackpack = function()
if AutoRestack and not InCombatLockdown() and (type(restacker) ~= "thread" or coroutine.status(restacker) == "dead") then
kRestack("bags", true)
end
return oToggleBackpack()
end
 
local function DecodeItemId(itemlink)
return select(3, strfind(itemlink, "item:(%d+)"))
end
27,9 → 42,9
if itemId == id then
local _, count, locked = GetContainerItemInfo(bag, slot)
local stack = select(8, GetItemInfo(itemId))
if count < stack then return true, bag, slot, count end
if stack > count then return true, bag, slot end
end
 
end
end
end
end
79,8 → 94,8
local locked, ok, pb, ps, pc
 
while true do
ok, pb, ps, pc = RestackFindPartial(bag, slot, itemId, loc)
locked = ok and select(3, GetContainerItemInfo(pb, ps)) or false
ok, pbag, pslot = RestackFindPartial(bag, slot, itemId, loc)
locked = ok and select(3, GetContainerItemInfo(pbag, pslot)) or false
 
if locked then
coroutine.yield()
91,10 → 106,9
 
if ok then
ClearCursor()
PickupContainerItem(pb, ps)
PickupContainerItem(pbag, pslot)
PickupContainerItem(bag, slot)
ClearCursor()
 
ClearCursor()
changed = true
end
end
104,35 → 118,34
return changed
end
 
local frame = CreateFrame("FRAME")
frame:RegisterEvent("BAG_UPDATE")
frame:SetScript("OnEvent", function()
if AutoRestack and type(restacker) ~= "thread" then
kRestack("bags", true)
end
end)
 
function kRestack(loc, nowarn)
if loc ~= "bags" and loc ~= "bank" then
local col = { w = "|cffFFFFFF", g = "|cff55FF55", r = "|cffFF5555" }
local krstr = "|cff44CCFFk|cffFFFFAARestack"..col.w
if loc == "auto" then
if not AutoStack then
AutoStack = true
local tog = "|cff55FF55ON"
local togl
if not AutoRestack then
AutoRestack = true
togl = col.g.."ON"
else
AutoStack = false
local tog = "|cffFF5555OFF"
end
print("|cff44CCFFk|cffFFFFAARestack |cffFFFFFFAuto-stacking toggled", tog)
else
print("|cff44CCFFk|cffFFFFAARestack")
print("- Usage: /restack [bags, bank]")
print("- /restack auto (toggles auto-stacking. default: off)")
AutoRestack = false
togl = col.r.."OFF"
end
print(krstr, "Auto-stacking toggled", togl)
else
local status = AutoRestack and col.g.."on" or col.r.."off"
print(krstr, "Usage:")
print("- /restack [bags, bank]")
print("- /restack auto - toggles auto-stacking ("..status..col.w..")")
end
 
do return end
end
 
if type(restacker) ~= "thread" or coroutine.status(restacker) == "dead" then
frame:SetScript("OnUpdate", function()
if type(restacker) == "thread" then coroutine.resume(restacker) end
end)
restacker = coroutine.create(function()
local changed = true
while changed == true do
145,7 → 158,7
for slot = 1, GetContainerNumSlots(bag) do
while true do
local locked = select( 3, GetContainerItemInfo(bag, slot))
 
 
if locked then
coroutine.yield()
else
156,11 → 169,11
local item = GetContainerItemLink(bag, slot)
 
if not item then
local locked, ok, sb, ss
local locked, ok, sbag, sslot
 
while true do
ok, sb, ss = RestackFindSpecial(bt, loc)
locked = ok and select(3, GetContainerItemInfo(sb, ss)) or false
ok, sbag, sslot = RestackFindSpecial(bt, loc)
locked = ok and select(3, GetContainerItemInfo(sbag, sslot)) or false
 
if locked then
coroutine.yield()
171,7 → 184,7
 
if ok then
ClearCursor()
PickupContainerItem(sb, ss)
PickupContainerItem(sbag, sslot)
PickupContainerItem(bag, slot)
ClearCursor()
end
181,12 → 194,9
end
frame:SetScript("OnUpdate", function() end)
end)
frame:SetScript("OnUpdate", function()
if type(restacker) == "thread" then coroutine.resume(restacker) end
end)
else
if not nowarn then
print("|cff33A1DEk|cffFFFFFFRestack |cffFF5555Restacking is already in progress, please wait.")
end
end
end
\ No newline at end of file +end
kRestack/kRestack.toc
1,8 → 1,8
## Interface: 30100
## Title: kRestack
## Version: 0.9.wowi:revision
## SavedVariablesPerCharacter: AutoRestack
## Author: Katae of Anvilmar
## Notes: Function for restacking inventory items.
## SavedVariablesPerCharacter: AutoRestack
 
kRestack.lua
\ No newline at end of file +kRestack.lua \ No newline at end of file