Mercurial > wow > inventory
diff Modules/Mover.lua @ 109:3bbad0429d87
Now only giving the ?bags are full? message once per item rather then for every queued move.
Neater coding for the container functions and prepared mailbox support (although this is not currently planned to be further developed for the moment).
Updated todo list to include mailbox support.
author | Zerotorescue |
---|---|
date | Wed, 12 Jan 2011 22:48:25 +0100 |
parents | 6ae44d372360 |
children | 67bd5057ecb7 |
line wrap: on
line diff
--- a/Modules/Mover.lua Wed Jan 12 20:09:11 2011 +0100 +++ b/Modules/Mover.lua Wed Jan 12 22:48:25 2011 +0100 @@ -145,6 +145,13 @@ addon:Print(("Bags are full. Skipping %s."):format(IdToItemLink(outgoingMove.itemId)), addon.Colors.Orange); outgoingMove.itemId = nil; -- remove this record from the outgoingMoves-table + + -- Not a single item with this item id can be moved, since we only want the bags are full announcement once, we remove all other moves with this item id + for _, otherMove in pairs(outgoingMoves) do + if otherMove.itemId and otherMove.itemId == outgoingMove.itemId then + otherMove.itemId = nil; + end + end else table.insert(combinedMoves, { itemId = outgoingMove.itemId, @@ -266,6 +273,41 @@ onFinish(); end +local ContainerFunctions = { + [addon.Locations.Bag] = { + GetItemId = GetContainerItemID, + PickupItem = SplitContainerItem, + IsLocked = function(sourceContainer, sourceSlot) + return select(3, GetContainerItemInfo(sourceContainer, sourceSlot); + end, + }, + [addon.Locations.Bank] = { + GetItemId = GetContainerItemID, + PickupItem = SplitContainerItem, + IsLocked = function(sourceContainer, sourceSlot) + return select(3, GetContainerItemInfo(sourceContainer, sourceSlot); + end, + }, + [addon.Locations.Guild] = { + GetItemId = function(tabId, slotId) + return addon:GetItemId(GetGuildBankItemLink(tabId, slotId)); + end, + PickupItem = SplitGuildBankItem, + IsLocked = function(sourceContainer, sourceSlot) + return select(3, GetGuildBankItemInfo(sourceContainer, sourceSlot); + end, + }, + --[[ Even though support is possible, it will require a little more work than just this and there are currently higher priorities + [addon.Locations.Mailbox] = { + GetItemId = function(mailIndex, attachmentId) + return addon:GetItemId(GetInboxItemLink(mailIndex, attachmentId)); + end, + PickupItem = TakeInboxItem, + IsLocked = function() return false; end, + DoNotDrop = true, + },]] +}; + function mod:ProcessMove() addon:Debug("ProcessMove"); @@ -291,40 +333,27 @@ local sourceLocationsLocked = {}; local targetLocationsLocked = {}; - local _GetContainerItemId = GetContainerItemID; - if movesSource == addon.Locations.Guild then - _GetContainerItemId = function(tabId, slotId) return addon:GetItemId(GetGuildBankItemLink(tabId, slotId)); end; - end - local _GetContainerItemInfo = GetContainerItemInfo; - if movesSource == addon.Locations.Guild then - _GetContainerItemInfo = GetGuildBankItemInfo; - end - local combinedMovesOriginalLength = #combinedMoves; local numCurrentMove = combinedMovesOriginalLength; while numCurrentMove ~= 0 do local move = combinedMoves[numCurrentMove]; - local isSourceLocked = ((sourceLocationsLocked[move.sourceContainer] and sourceLocationsLocked[move.sourceContainer][move.sourceSlot]) or select(3, _GetContainerItemInfo(move.sourceContainer, move.sourceSlot))); - local isTargetLocked = ((targetLocationsLocked[move.targetContainer] and targetLocationsLocked[move.targetContainer][move.targetSlot]) or select(3, GetContainerItemInfo(move.targetContainer, move.targetSlot))); + local isSourceLocked = ((sourceLocationsLocked[move.sourceContainer] and sourceLocationsLocked[move.sourceContainer][move.sourceSlot]) or ContainerFunctions[movesSource].IsLocked(move.sourceContainer, move.sourceSlot)); + -- Target are always the local bags + local isTargetLocked = ((targetLocationsLocked[move.targetContainer] and targetLocationsLocked[move.targetContainer][move.targetSlot]) or ContainerFunctions[addon.Locations.Bag].IsLocked(move.targetContainer, move.targetSlot)); if move and not isSourceLocked and not isTargetLocked then - addon:Print(("Moving %dx%s."):format(move.num, IdToItemLink(move.itemId))); addon:Debug("Moving %dx%s from (%d,%d) to (%d,%d)", move.num, IdToItemLink(move.itemId), move.sourceContainer, move.sourceSlot, move.targetContainer, move.targetSlot); - if _GetContainerItemId(move.sourceContainer, move.sourceSlot) ~= move.itemId then + if ContainerFunctions[movesSource].GetItemId(move.sourceContainer, move.sourceSlot) ~= move.itemId then self:Abort("source changed", "Source (" .. move.sourceContainer .. "," .. move.sourceSlot .. ") is not " .. IdToItemLink(move.itemId)); return; end -- Pickup stack - if movesSource == addon.Locations.Bank then - SplitContainerItem(move.sourceContainer, move.sourceSlot, move.num); - elseif movesSource == addon.Locations.Guild then - SplitGuildBankItem(move.sourceContainer, move.sourceSlot, move.num); - end + ContainerFunctions[movesSource].PickupItem(move.sourceContainer, move.sourceSlot, move.num); -- Remember we picked this item up and thus it is now locked if not sourceLocationsLocked[move.sourceContainer] then @@ -332,9 +361,9 @@ end sourceLocationsLocked[move.sourceContainer][move.sourceSlot] = true; - if movesSource == addon.Locations.Guild or CursorHasItem() then -- CursorHasItem is always false if source is a guild tab + if movesSource ~= addon.Locations.Bank or CursorHasItem() then -- CursorHasItem only works when moving outside of the bank -- We are moving into our local bags, so the below must check normal - local targetItemId = GetContainerItemID(move.targetContainer, move.targetSlot); + local targetItemId = ContainerFunctions[movesSource].get(move.targetContainer, move.targetSlot); if targetItemId and targetItemId ~= move.itemId then self:Abort("target changed", "Target (" .. move.targetContainer .. "," .. move.targetSlot .. ") is not " .. IdToItemLink(move.itemId) .. " nor empty"); return;