Quantcast

Added a placeholder function for bag-scanning.

pschifferer [03-13-09 - 04:45]
Added a placeholder function for bag-scanning.
Changed the callback type of "/cauldron shoppinglist" so it actually works >.<.
Added some checks for shopping list and bag updates.
Filename
CauldronMain.lua
CauldronShoppingList.lua
CauldronUtil.lua
diff --git a/CauldronMain.lua b/CauldronMain.lua
index 7183df0..294707d 100644
--- a/CauldronMain.lua
+++ b/CauldronMain.lua
@@ -54,7 +54,8 @@ function Cauldron:OnInitialize()
 			shoppinglist = {
 				name = L["Shopping list"],
 				desc = L["Open shopping list window"],
-				type = 'toggle',
+				type = 'execute',
+				func = function() Cauldron:ShowShoppingList() end,
 			},
 			version = {
 				name = L["Version"],
@@ -133,6 +134,9 @@ function Cauldron:OnEnable()
 --@end-alpha@

 	self:InitPlayer();
+
+	-- scan bags
+	self:ScanBags();

 	self:RegisterEvent("TRADE_SKILL_SHOW", "OnTradeShow");
 	self:RegisterEvent("TRADE_SKILL_UPDATE", "OnSkillUpdate");
@@ -312,9 +316,14 @@ function Cauldron:OnBagUpdate(event, bagid)
 	self:debug("OnBagUpdate enter");
 --@end-alpha@

---	if (not CauldronFrame) or (not CauldronFrame:IsShown()) then
+--	if (not CauldronFrame) and (not CauldronFrame:IsShown()) then
 --		return;
 --	end
+
+    -- make sure we're not reacting to initial bag update events when the DB isn't initialized yet
+    if (not Cauldron.db) or (not Cauldron.vars) then
+        return;
+    end

 	-- check if the item acquired is in the intermediate list or shopping list
 	local items = Cauldron:GetItemDeltas(bagid);
@@ -328,7 +337,7 @@ function Cauldron:OnBagUpdate(event, bagid)
 --@alpha@
 		self:debug("OnBagUpdate: adjust shopping list");
 --@end-alpha@
-			CauldronShopping:RemoveFromList(self.db.realm.shopping, self.vars.playername, item, itemCount);
+--			CauldronShopping:RemoveFromList(self.db.realm.shopping, self.vars.playername, item, itemCount);

 			-- adjust intermediate list
 --@alpha@
diff --git a/CauldronShoppingList.lua b/CauldronShoppingList.lua
index 89882d1..17f69c9 100644
--- a/CauldronShoppingList.lua
+++ b/CauldronShoppingList.lua
@@ -57,7 +57,7 @@ function CauldronShopping:RemoveFromList(list, requestor, itemName, quantity)
 		-- initialize the list for the requestor
 		list[requestor] = {};
 	end
-
+
 	if list[requestor][itemName] then
 		if quantity then
 			list[requestor][itemName] = list[requestor][itemName] - quantity;
@@ -123,6 +123,17 @@ function CauldronShopping:HasItems(list, requestor)
 end

 function CauldronShopping:GetRequestedItems(list, requestor)
+
+	if not list then
+		Cauldron:warn("CauldronShopping:HasItems: missing list!");
+		return false;
+	end
+
+	if list[requestor] then
+	    return list[requestor];
+	end
+
+	return {};
 end

 function CauldronShopping:EmptyShoppingList(list, requestor)
diff --git a/CauldronUtil.lua b/CauldronUtil.lua
index 9c64304..4b55597 100644
--- a/CauldronUtil.lua
+++ b/CauldronUtil.lua
@@ -129,6 +129,10 @@ function Cauldron:GetNameFromLink(link)
 	return name
 end

+function Cauldron:ScanBags()
+	-- TODO
+end
+
 function Cauldron:GetItemDeltas(bagid)

 	-- sanity checks
@@ -149,6 +153,7 @@ function Cauldron:GetItemDeltas(bagid)
 		if link then
 			local name = select(1, {GetItemInfo(link)});
 			local count = GetItemCount(link);
+			-- local count = select(2, {GetContainerItemInfo(bagid, i)});

 			local delta = count;
 			if inv[name] then