Housing storage - indexing/displaying complete

AssemblerManiac [02-18-18 - 07:06]
Housing storage - indexing/displaying complete
Filename
IIfA/CharBagSpaceTooltip.lua
IIfA/IIfABackpack.lua
IIfA/IIfADataCollection.lua
IIfA/IIfAEvents.lua
IIfA/IIfATooltip.lua
diff --git a/IIfA/CharBagSpaceTooltip.lua b/IIfA/CharBagSpaceTooltip.lua
index 6b1a73c..2de2388 100644
--- a/IIfA/CharBagSpaceTooltip.lua
+++ b/IIfA/CharBagSpaceTooltip.lua
@@ -100,11 +100,14 @@ function CharBagFrame:FillCharAndBank()

 	self:SetQty(self.totControl, "spaceUsed", spaceUsed)
 	self:SetQty(self.totControl, "spaceMax", spaceMax)
+
+
 end

 -- add iteration for house chests
 -- if GetBagSize == 0, you've run out of chests to iterate (break out of loop)
 -- /script for i=BAG_HOUSE_BANK_ONE,BAG_MAX_VALUE do d(i .. GetCollectibleName(GetCollectibleForHouseBankBag(i))) end
+-- /script for i=BAG_HOUSE_BANK_ONE,BAG_MAX_VALUE do d(IsCollectibleUnlocked(GetCollectibleForHouseBankBag(i))) end

 function CharBagFrame:RepaintSpaceUsed()
 	-- loop through characters
diff --git a/IIfA/IIfABackpack.lua b/IIfA/IIfABackpack.lua
index ee4aaf7..6876add 100644
--- a/IIfA/IIfABackpack.lua
+++ b/IIfA/IIfABackpack.lua
@@ -656,7 +656,7 @@ function IIfA:QueryAccountInventory(itemLink)
 						newLocation = {}
 						newLocation.name = locationName

-						if locationName == location.bagID then -- location is a collectible
+						if location.bagID >= BAG_HOUSE_BANK_ONE and location.bagID <= BAG_HOUSE_BANK_TEN then	-- location is a housing chest
 							newLocation.name = GetCollectibleNickname(locationName)
 							if newLocation.name == "" then newLocation.name = GetCollectibleName(locationName) end
 						end
diff --git a/IIfA/IIfADataCollection.lua b/IIfA/IIfADataCollection.lua
index b45a523..4445144 100644
--- a/IIfA/IIfADataCollection.lua
+++ b/IIfA/IIfADataCollection.lua
@@ -7,6 +7,8 @@ IIfA.task			= task
 local function p(...) IIfA:DebugOut(...) end

 local function grabBagContent(bagId, override)
+	if bagId >= BAG_HOUSE_BANK_ONE and bagId <= BAG_HOUSE_BANK_TEN and not IsOwnerOfCurrentHouse() then return end
+
 	local bagItems = GetBagSize(bagId)
 	IIfA:DebugOut("grabBagContent - bagId = <<1>>", bagId)
 	for slotId=0, bagItems, 1 do
@@ -114,31 +116,26 @@ function IIfA:ScanCurrentCharacter()
 end

 local function tryScanHouseBank()
-	if GetAPIVersion() < 100022 then return end
-	local bagId = GetBankingBag()
-	if not bagId then return end
-	local collectibleId = GetCollectibleForHouseBankBag(bagId)
-
-	if IsCollectibleUnlocked(collectibleId) then
-
-		IIfA:DebugOut(zo_strformat("tryScanHouseBank(<<1>>)", collectibleId))
-
-		local collectibleName = GetCollectibleNickname(collectibleId)
-		if collectibleName == EMPTY_STRING then collectibleName = GetCollectibleName(collectibleId) end
-		-- call with libAsync to avoid lags
-		task:Call(function()
-			IIfA:ClearLocationData(collectibleId)
-		end):Then(function()
-			grabBagContent(bagId, true)
-		end)
+	if not IsOwnerOfCurrentHouse() then return end
+
+	local bagId
+	for bagId = BAG_HOUSE_BANK_ONE, BAG_HOUSE_BANK_TEN do
+		local collectibleId = GetCollectibleForHouseBankBag(bagId)
+		if IsCollectibleUnlocked(collectibleId) then
+			IIfA:DebugOut(zo_strformat("tryScanHouseBank(<<1>>)", collectibleId))
+			-- call with libAsync to avoid lags
+			task:Call(function()
+				local collectibleId = GetCollectibleForHouseBankBag(bagId)		-- this MUST stay here, or collectibleId is 0
+				IIfA:ClearLocationData(collectibleId)
+			end):Then(function()
+				grabBagContent(bagId, true)
+			end)
+		end
 	end
-
-	return true
 end

 function IIfA:ScanBank()

-	if tryScanHouseBank() then return end
 	-- call with libAsync to avoid lags
 	task:Call(function()
 		IIfA:ClearLocationData(GetString(IIFA_BAG_BANK))
@@ -153,9 +150,9 @@ function IIfA:ScanBank()
 			IIfA:EvalBagItem(BAG_VIRTUAL, slotId)
 			slotId = GetNextVirtualBagSlotId(slotId)
 		end
+	end):Then(function()
+		tryScanHouseBank()
 	end)
-
-
 end


@@ -553,14 +550,20 @@ function IIfA:CollectAll()
 		-- call with libAsync to avoid lags
 		task:Call(function()
 			bagItems = GetBagSize(bagId)
-			if(bagId == BAG_WORN) then	--location for BAG_BACKPACK and BAG_WORN is the same so only reset once
+			if bagId == BAG_WORN then	--location for BAG_BACKPACK and BAG_WORN is the same so only reset once
 				IIfA:ClearLocationData(IIfA.currentCharacterId)
-			elseif(bagId == BAG_BANK) then	-- do NOT add BAG_SUBSCRIBER_BANK here, it'll wipe whatever already got put into the bank on first hit
+			elseif bagId == BAG_BANK then	-- do NOT add BAG_SUBSCRIBER_BANK here, it'll wipe whatever already got put into the bank on first hit
 				IIfA:ClearLocationData(GetString(IIFA_BAG_BANK))
-			elseif(bagId == BAG_BACKPACK) then
+			elseif bagId == BAG_BACKPACK then
 				IIfA:ClearLocationData(GetString(IIFA_BAG_BACKPACK))
-			elseif(bagId == BAG_VIRTUAL)then
+			elseif bagId == BAG_VIRTUAL then
 				IIfA:ClearLocationData(GetString(IIFA_BAG_CRAFTBAG))
+			elseif bagId >= BAG_HOUSE_BANK_ONE and bagId <= BAG_HOUSE_BANK_TEN then
+				if IsOwnerOfCurrentHouse() then
+					IIfA:ClearLocationData(GetCollectibleForHouseBankBag(bagId))
+				else
+					tracked = false		-- prevent reading the house bag if we're not in our own home
+				end
 			end
 	--		d("  BagItemCount=" .. bagItems)
 			if bagId ~= BAG_VIRTUAL and tracked then
diff --git a/IIfA/IIfAEvents.lua b/IIfA/IIfAEvents.lua
index ddf50d8..c131822 100644
--- a/IIfA/IIfAEvents.lua
+++ b/IIfA/IIfAEvents.lua
@@ -47,6 +47,7 @@ local function IIfA_InventorySlotUpdate(...)
 end

 local function IIfA_ScanHouse(eventCode, oldMode, newMode)
+	d(newMode)
 	if newMode == "showing" or newMode == "shown" then return end
 	-- are we listening?
 	if not IIfA:GetCollectingHouseData() then return end
@@ -58,7 +59,6 @@ end
 local function IIfA_HouseEntered(eventCode)
 	if not IsOwnerOfCurrentHouse() then return end

-
 	-- is the house registered?
 	local houseCollectibleId = GetCollectibleIdForHouse(GetCurrentZoneHouseId())

@@ -145,7 +145,7 @@ function IIfA:RegisterForEvents()
 	em:RegisterForEvent("IIFA_GUILDBANK_LOADED", EVENT_GUILD_BANK_ITEMS_READY, function() IIfA:GuildBankDelayReady() end)

 --	em:RegisterForEvent("IIFA_gb1", EVENT_GUILD_BANK_OPEN_ERROR, fgb1)
-	em:RegisterForEvent("IIFA_gb2", EVENT_GUILD_BANK_UPDATED_QUANTITY, fgb2)
+--	em:RegisterForEvent("IIFA_gb2", EVENT_GUILD_BANK_UPDATED_QUANTITY, fgb2)
 --	em:RegisterForEvent("IIFA_gb3", EVENT_GUILD_BANK_SELECTED, fgb3)
 --	em:RegisterForEvent("IIFA_gb4", EVENT_GUILD_BANK_DESELECTED, fgb4)
 --	em:RegisterForEvent("IIFA_gb5", EVENT_GUILD_BANK_ITEMS_READY, fgb5)
diff --git a/IIfA/IIfATooltip.lua b/IIfA/IIfATooltip.lua
index 9f4bdfc..a9c4552 100644
--- a/IIfA/IIfATooltip.lua
+++ b/IIfA/IIfATooltip.lua
@@ -414,7 +414,7 @@ function IIfA:getLastLink(tooltip)
 end

 function IIfA:UpdateTooltip(tooltip)
-	local itemLink
+	local itemLink, itemData
 	itemLink = self:getLastLink(tooltip)

 	local queryResults = IIfA:QueryAccountInventory(itemLink)
@@ -455,13 +455,7 @@ function IIfA:UpdateTooltip(tooltip)
 						d(location)
 						textOut = 'Error occurred'
 					else
-						if tonumber(location.name) == location.name then
-							local loc = GetCollectibleNickname(location.name)
-							 if loc == "" then loc = GetCollectibleName(location.name)end
-							textOut = string.format("%s x %s", loc, location.itemsFound)
-						else
-							textOut = string.format("%s x %s", location.name, location.itemsFound)
-						end
+						textOut = string.format("%s x %s", location.name, location.itemsFound)
 					end

 					if location.worn then
@@ -520,7 +514,7 @@ function IIfA:UpdateTooltip(tooltip)
 		if(queryResults) then
 			if #queryResults.locations > 0 then
 				ZO_Tooltip_AddDivider(tooltip)
-				for x, location in pairs(queryResults.locations) do
+				for _, location in pairs(queryResults.locations) do
 					local textOut
 					if location.name == nil or location.itemsFound == nil then
 						d(location)