diff Modules/Mover.lua @ 89:a12d22ef3f39

AceSerializer has been enabled again as it?s used when exporting/importing groups. All other unused libraries are now really removed. Adjusted debug function to format only when a debug channel is available. Fixed moving from guild banks, checking if items are locked is different then with banks. Now unregistering the item locking event so it doesn?t continue to try to move every time an item is switched after the automated cycle has finished. (geeezus, this description is a total overkill) Fixed item queueing. Queue all when there?s a group without any items inside no longer crashes. Removing cached container data after closing a container.
author Zerotorescue
date Fri, 07 Jan 2011 22:19:03 +0100
parents f1c035694545
children 31493364b163
line wrap: on
line diff
--- a/Modules/Mover.lua	Fri Jan 07 10:34:38 2011 +0100
+++ b/Modules/Mover.lua	Fri Jan 07 22:19:03 2011 +0100
@@ -44,7 +44,7 @@
 	
 	local outgoingMoves = {};
 
-	addon:Debug(#queuedMoves .. " moves were queued.");
+	addon:Debug("%d moves were queued.", #queuedMoves);
 	
 	for _, singleMove in pairs(queuedMoves) do
 		local sourceItem = sourceContents[singleMove.id];
@@ -77,7 +77,7 @@
 		end
 	end
 
-	addon:Debug(#outgoingMoves .. " outgoing moves are possible.");
+	addon:Debug("%d outgoing moves are possible.", #outgoingMoves);
 	
 	-- No longer needed
 	table.wipe(queuedMoves);
@@ -109,7 +109,7 @@
 		end
 	end
 
-	addon:Debug(#emptySlots .. " empty slots are available.");
+	addon:Debug("%d empty slots are available.", #emptySlots);
 	
 	-- Remember where we're moving from
 	movesSource = location;
@@ -230,7 +230,7 @@
 			numOutgoingMoves = (numOutgoingMoves - 1);
 		end
 
-		addon:Debug(#outgoingMoves .. " moves remaining.");
+		addon:Debug("%d moves remaining.", #outgoingMoves);
 		
 		backup = (backup + 1);
 		if backup > 1000 then
@@ -245,7 +245,7 @@
 	-- Reverse table, we need to go through it from last to first because we'll be removing elements, but we don't want the actions to be executed in a different order
 	combinedMoves = table.reverse(combinedMoves);
 
-	addon:Debug(#combinedMoves .. " moves should be possible.");
+	addon:Debug("%d moves should be possible.", #combinedMoves);
 	
 	-- No longer needed
 	table.wipe(emptySlots);
@@ -283,21 +283,24 @@
 	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] or 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 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)));
 		
-		-- sourceContainer, sourceSlot, targetContainer, targetSlot, itemId, num
-		if move and isSourceLocked and isTargetLocked then
+		if move and not isSourceLocked and not isTargetLocked then
 			
 			print(("Moving %dx%s."):format(move.num, IdToItemLink(move.itemId)));
 			
-			addon:Debug(("Moving %dx%s from (%d,%d) to (%d,%d)"):format(move.num, IdToItemLink(move.itemId), move.sourceContainer, move.sourceSlot, move.targetContainer, move.targetSlot));
+			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
 				self:Abort("source changed", "Source (" .. move.sourceContainer .. "," .. move.sourceSlot .. ") is not " .. IdToItemLink(move.itemId));
@@ -346,7 +349,7 @@
 		numCurrentMove = (numCurrentMove - 1);
 	end
 	
-	addon:Debug((combinedMovesOriginalLength - #combinedMoves) .. " moves processed. " .. #combinedMoves .. " moves remaining.");
+	addon:Debug("%d moves processed. %d moves remaining.", (combinedMovesOriginalLength - #combinedMoves), #combinedMoves);
 	
 	if #combinedMoves == 0 then
 		print("Finished.");
@@ -360,7 +363,7 @@
 local tmrProcessNext;
 function mod:ITEM_LOCK_CHANGED()
 	self:CancelTimer(tmrProcessNext, true); -- silent
-	tmrProcessNext = self:ScheduleTimer("ProcessMove", 0.5);
+	tmrProcessNext = self:ScheduleTimer("ProcessMove", .5);
 end
 
 function IdToItemLink(itemId)
@@ -377,7 +380,7 @@
 
 function mod:Abort(simple, debugMsg)
 	if debugMsg then
-		addon:Debug("Aborting:" .. debugMsg);
+		addon:Debug("Aborting:%s", debugMsg);
 	end
 	if simple then
 		print("|cffff0000Aborting: " .. simple .. ".|r");
@@ -386,7 +389,7 @@
 	movesSource = nil;
 	
 	-- Stop timer
-	self:UnregisterEvent("BAG_UPDATE");
+	self:UnregisterEvent("ITEM_LOCK_CHANGED");
 	self:CancelTimer(tmrProcessNext, true); -- silent
 	
 	self:UnregisterEvent("UI_ERROR_MESSAGE");