cleaned up exposed globals after votan's input. Needs to be verified if it runs, am at work.

manavortex [02-22-18 - 08:21]
cleaned up exposed globals after votan's input. Needs to be verified if it runs, am at work.
Filename
IIfA/CharBagSpaceTooltip.lua
IIfA/IIfA.lua
IIfA/IIfABackpack.lua
IIfA/IIfADataCollection.lua
IIfA/IIfAMenu.lua
IIfA/IIfA_xml_adapter.lua
diff --git a/IIfA/CharBagSpaceTooltip.lua b/IIfA/CharBagSpaceTooltip.lua
index 757b142..6773267 100644
--- a/IIfA/CharBagSpaceTooltip.lua
+++ b/IIfA/CharBagSpaceTooltip.lua
@@ -99,13 +99,13 @@ function CharBagFrame:FillCharAndBank()
 	spaceMax = spaceMax + bankMax + self.totSpaceMax

 	-- housing chests
-	local bInHouse, ctr, tempUsed
+	local bInHouse, ctr, tempUsed, bFoundData
 	local cName
 	local iChestCount = 0
-	bInOwnedHouse = IsOwnerOfCurrentHouse()
+	local bInOwnedHouse = IsOwnerOfCurrentHouse()

 	for ctr = BAG_HOUSE_BANK_ONE,BAG_HOUSE_BANK_TEN do
-		tControl = self.houseChestControls[ctr]
+		local tControl = self.houseChestControls[ctr]
 		if IsCollectibleUnlocked(GetCollectibleForHouseBankBag(ctr)) then
 			if bInOwnedHouse then
 				tempUsed = GetNumBagUsedSlots(ctr)
@@ -138,7 +138,7 @@ function CharBagFrame:FillCharAndBank()
 		end
 	end

-	local iFrameHeight
+	local iFrameHeight, tControl
 	local iDivCount = 2

 	if iChestCount > 0 then
@@ -170,7 +170,7 @@ function CharBagFrame:RepaintSpaceUsed()
 	local assets = self.parent.assets
 	for i=1, GetNumCharacters() do
 		local _, _, _, _, _, _, charId, _ = GetCharacterInfo(i)
-		tControl = GetControl("IIFA_GUI_Bag_Grid_Row_" .. i)
+		local tControl = GetControl("IIFA_GUI_Bag_Grid_Row_" .. i)
 		if charId ~= currId then
 			if assets[charId] ~= nil then
 				if assets[charId].spaceUsed ~= nil then
diff --git a/IIfA/IIfA.lua b/IIfA/IIfA.lua
index 37d62b4..ac05e64 100644
--- a/IIfA/IIfA.lua
+++ b/IIfA/IIfA.lua
@@ -281,6 +281,14 @@ function IIfA_onLoad(eventCode, addOnName)

 	IIfA:RebuildHouseMenuDropdowns()

+	local function setIfNil(value, defaultValue)
+		if nil ~= value then return end
+		value = defaultValue
+	end
+	local function setNil(value)
+		if nil ~= value then value = nil end
+	end
+
 	--  nuke non-global positioning settings
 	local ObjSettings = IIfA:GetSettings()
 	local function nukePositioning()
@@ -303,9 +311,21 @@ function IIfA_onLoad(eventCode, addOnName)
 	end
 	nukePositioning()

-	if IIfA.settings.in2ToggleGuildBankDataCollection ~= nil then
-		IIfA.settings.in2ToggleGuildBankDataCollection = nil
+	local function considerWorldData()
+		-- keep EU and US items apart
+		local worldName = GetWorldName():gsub(" Megaserver", "")
+		IIfA.data[worldName] = IIfA.data[worldName] or {}
+		if IIfA.data[worldName].DBv3 == nil then
+			 IIfA.data[worldName].DBv3 = IIfA.data.DBv3
+		end
+		IIfA.data.DBv3 = nil
+		IIfA.database = IIfA.data[worldName].DBv3
 	end
+
+
+
+	setNil(IIfA.settings.in2ToggleGuildBankDataCollection ~= nil)
+
 	if IIfA.data.in2ToggleGuildBankDataCollection ~= nil then
 		IIfA.data.bCollectGuildBankData = IIfA.data.in2ToggleGuildBankDataCollection
 		IIfA.data.in2ToggleGuildBankDataCollection = nil
@@ -340,13 +360,8 @@ function IIfA_onLoad(eventCode, addOnName)
 		end
 	end

-	if IIfA.data.showStyleInfo == nil then
-		IIfA.data.showStyleInfo = true
-	end
-	if ObjSettings.showStyleInfo == nil then
-		ObjSettings.showStyleInfo = IIfA.data.showStyleInfo
-	end
-
+	setIfNil(IIfA.data.showStyleInfo, true)
+	setIfNil(ObjSettings.showStyleInfo, IIfA.data.showStyleInfo)

 	-- 2-9-17 AM - convert saved data names into proper language for this session
     local lang = GetCVar("language.2")
@@ -416,83 +431,10 @@ function IIfA_onLoad(eventCode, addOnName)
 	IIfA:SetupBackpack()	-- setup the inventory frame
 	IIfA:CreateTooltips()	-- setup the tooltip frames

-	if (IIfA.data.bConvertedGlyphs == nil or IIfA.data.bConvertedLocType == nil) and IIfA.data.DBv3 == nil then
-		-- glyphs are currently stored by itemid, remove them so it can store them properly by item link
-		for itemLink, DBItem in pairs(IIfA.data.DBv2) do
-			if IIfA.data.bConvertedGlyphs == nil then
-				if DBItem.attributes.itemName:lower():find("glyph") ~= nil and itemLink:find("|") == nil then
-					IIfA.data.DBv2[itemLink] = nil
-				end
-			end
-			for locationName, locData in pairs(DBItem) do
-				if locData.locationType ~= nil then
-					locData.bagID = locData.locationType
-					locData.locationType = nil
-				end
-			end
-		end
-		IIfA.data.bConvertedGlyphs = true
-		IIfA.data.bConvertedLocType = true
-	end
-	if IIfA.data.bConvertedMotifs == nil and IIfA.data.DBv2 ~= nil then			-- 9-12-16 AM - added whole if to convert motifs to item ids
-		for itemLink, DBItem in pairs(IIfA.data.DBv2) do
-			if itemLink:find("|") ~= nil then			-- not a numeric itemid, it's a link
-				local itemType = GetItemLinkItemType(itemLink)
-				if itemType == ITEMTYPE_RACIAL_STYLE_MOTIF then		-- 9-12-16 AM - added because motifs now appear to have level info in them
-					itemKey = IIfA:GetItemID(itemLink)
-					if IIfA.data.DBv2[itemKey] == nil then
-						IIfA.data.DBv2[itemKey] = DBItem
-						IIfA.data.DBv2[itemLink] = nil
-						IIfA.data.DBv2[itemKey].itemLink = itemLink
-					else
-						for attrib, data in pairs(DBItem) do
-							if data.itemCount ~= nil then
-								if IIfA.data.DBv2[itemKey][attrib].itemCount ~= nil then
-									IIfA.data.DBv2[itemKey][attrib].itemCount = IIfA.data.DBv2[itemKey][attrib].itemCount + data.itemCount
-								else
-									IIfA.data.DBv2[itemKey][attrib] = data
-								end
-							end
-						end
-						IIfA.data.DBv2[itemKey].attributes.itemLink = itemLink
-						IIfA.data.DBv2[itemLink] = nil
-					end
-				end
-			end
-		end
-		IIfA.data.bConvertedMotifs = true
-	end
-
-	if IIfA.data.DBv2 ~= nil then
-		dbv3 = {}
-		for itemLink, DBItem in pairs(IIfA.data.DBv2) do
-			dbv3[itemLink] = {}
-			dbv3[itemLink].locations = {}
-			dbv3[itemLink].itemQuality = DBItem.attributes.itemQuality
-			dbv3[itemLink].itemName    = DBItem.attributes.itemName
-			dbv3[itemLink].filterType  = DBItem.attributes.filterType
-			if DBItem.attributes.itemLink ~= nil then
-				dbv3[itemLink].itemLink = DBItem.attributes.itemLink
-			end
+	-- manavortex, Feb. 22 2018: drop dbv2 support
+	if nil ~= IIfA.data.DBv2 then IIfA.data.DBv2 = nil end

-			for locname, locdata in pairs(DBItem) do
-				if locname ~= "attributes" then
-					dbv3[itemLink].locations[locname] = locdata
-				end
-			end
-		end
-		IIfA.data.DBv3 = dbv3
-		IIfA.data.DBv2 = nil
-	end
-
-	-- keep EU and US items apart
-	local worldName = GetWorldName():gsub(" Megaserver", "")
-	IIfA.data[worldName] = IIfA.data[worldName] or {}
-	if IIfA.data[worldName].DBv3 == nil then
-		 IIfA.data[worldName].DBv3 = IIfA.data.DBv3
-	end
-	IIfA.data.DBv3 = nil
-	IIfA.database = IIfA.data[worldName].DBv3
+	considerWorldData()

 	IIfA:ActionLayerInventoryUpdate()

@@ -503,8 +445,8 @@ function IIfA_onLoad(eventCode, addOnName)
 	IIfA:RegisterForEvents()
 	IIfA:RegisterForSceneChanges() -- register for callbacks on scene statechanges using user preferences or defaults

-	IIfA.ignoredCharEquipment = IIfA.ignoredCharEquipment or {}
-	IIfA.ignoredCharInventories = IIfA.ignoredCharInventories or {}
+	IIfA.ignoredCharEquipment 		= IIfA.ignoredCharEquipment or {}
+	IIfA.ignoredCharInventories 	= IIfA.ignoredCharInventories or {}

 	IIfA.trackedBags[BAG_WORN] 		= not IIfA:IsCharacterEquipIgnored()
 	IIfA.trackedBags[BAG_BACKPACK] 	= not IIfA:IsCharacterInventoryIgnored()
diff --git a/IIfA/IIfABackpack.lua b/IIfA/IIfABackpack.lua
index bb6c4d3..f6acc3c 100644
--- a/IIfA/IIfABackpack.lua
+++ b/IIfA/IIfABackpack.lua
@@ -1,6 +1,7 @@
 local IIfA = IIfA

 local LMP = LibStub("LibMediaProvider-1.0")
+local _

 IIfA.ScrollSortUp = true
 IIfA.ActiveFilter = 0
@@ -406,6 +407,7 @@ end


 local function fillLine(curLine, curItem)
+	local color
 	if curItem == nil then
 		curLine.itemLink = ""
 		curLine.icon:SetTexture(nil)
@@ -478,7 +480,7 @@ end

 function IIfA:SetItemCountPosition()
 	for i=1, IIFA_GUI_ListHolder.maxLines do
-		line = IIFA_GUI_ListHolder.lines[i]
+		local line = IIFA_GUI_ListHolder.lines[i]
 		line.text:ClearAnchors()
 		line.qty:ClearAnchors()
 		if IIfA:GetSettings().showItemCountOnRight then
@@ -587,8 +589,8 @@ function IIfA:GetAccountInventoryList()
 -- banks are same as toons, same order as player normally sees them
 	if IIfA.data.bCollectGuildBankData then
 		for i = 1, GetNumGuilds() do
-			id = GetGuildId(i)
-			guildName = GetGuildName(id)
+			local id = GetGuildId(i)
+			local guildName = GetGuildName(id)

 			-- on the off chance that this doesn't exist already, create it
 			if IIfA.data.guildBanks == nil then
@@ -616,6 +618,7 @@ function IIfA:QueryAccountInventory(itemLink)
 		itemLink = string.gsub(itemLink, '|H0', '|H1')
 	end

+
 	local queryItem = {
 		link = itemLink,
 		locations = {},
@@ -625,7 +628,7 @@ function IIfA:QueryAccountInventory(itemLink)
 	local AlreadySavedLoc = false
 	local newLocation = {}

-	itemType = GetItemLinkItemType(itemLink)
+	local itemType = GetItemLinkItemType(itemLink)
 	if CanItemLinkBeVirtual(itemLink) or
 		itemType == ITEMTYPE_LOCKPICK or
 		itemType == ITEMTYPE_RECIPE or
@@ -700,7 +703,7 @@ function IIfA:SetupBackpack()
 			IIFA_GUI_Header_Dropdown.comboBox = comboBox
 		end

-		function OnItemSelect(_, choiceText, choice)
+		local function OnItemSelect(_, choiceText, choice)
 	--		d("OnItemSelect", choiceText, choice)
 			IIfA:SetInventoryListFilter(choiceText)
 			PlaySound(SOUNDS.POSITIVE_CLICK)
@@ -746,7 +749,7 @@ function IIfA:SetupBackpack()
 		comboBox:SetSortsItems(false)

 		for i = 1, #validChoices do
-			entry = comboBox:CreateItemEntry(validChoices[i], OnItemSelect)
+			local entry = comboBox:CreateItemEntry(validChoices[i], OnItemSelect)
 			comboBox:AddItem(entry)
 			if qualityDict[validChoices[i]] == IIfA:GetInventoryListFilterQuality() then
 				comboBox:SetSelectedItem(validChoices[i])
diff --git a/IIfA/IIfADataCollection.lua b/IIfA/IIfADataCollection.lua
index e1962d1..1c4d4d5 100644
--- a/IIfA/IIfADataCollection.lua
+++ b/IIfA/IIfADataCollection.lua
@@ -1,5 +1,6 @@
 local IIfA 			= IIfA
 local EMPTY_STRING 	= ""
+local _

 local task 			= IIfA.task or LibStub("LibAsync"):Create("IIfA_DataCollection")
 IIfA.task			= task
@@ -12,7 +13,7 @@ local function grabBagContent(bagId, override)
 	local bagItems = GetBagSize(bagId)
 	IIfA:DebugOut("grabBagContent - bagId = <<1>>", bagId)
 	for slotId=0, bagItems, 1 do
-		dbItem, itemKey = IIfA:EvalBagItem(bagId, slotId, false, nil, nil, nil, nil, override)
+		local dbItem, itemKey = IIfA:EvalBagItem(bagId, slotId, false, nil, nil, nil, nil, override)
 	end
 end

@@ -150,7 +151,7 @@ function IIfA:ScanBank()
 		grabBagContent(BAG_SUBSCRIBER_BANK)
 	end):Then(function()
 		IIfA:ClearLocationData(GetString(IIFA_BAG_CRAFTBAG))
-		slotId = GetNextVirtualBagSlotId(slotId)
+		local slotId = GetNextVirtualBagSlotId(slotId)
 		while slotId ~= nil do
 			IIfA:EvalBagItem(BAG_VIRTUAL, slotId)
 			slotId = GetNextVirtualBagSlotId(slotId)
@@ -464,12 +465,12 @@ function IIfA:EvalBagItem(bagId, slotId, fromXfer, itemCount, itemLink, itemName

 	if nil == itemKey then return end

-	itemFilterType = GetItemFilterTypeInfo(bagId, slotId) or 0
-	DBitem = DBv3[itemKey]
-	location = locationID or getLocation(location, bagId) or EMPTY_STRING
+	local itemFilterType = GetItemFilterTypeInfo(bagId, slotId) or 0
+	local DBitem = DBv3[itemKey]
+	local location = locationID or getLocation(location, bagId) or EMPTY_STRING

 	if(DBitem) then
-		DBitemlocation = DBitem.locations[location]
+		local DBitemlocation = DBitem.locations[location]
 		if DBitemlocation then
 			DBitemlocation.itemCount = DBitemlocation.itemCount + itemCount
 			DBitemlocation.bagSlot = DBitemlocation.bagSlot or slotId
@@ -579,7 +580,7 @@ function IIfA:CollectAll()
 						end
 					end
 				else -- it's bag virtual
-					slotId = GetNextVirtualBagSlotId(nil)
+					local slotId = GetNextVirtualBagSlotId(nil)
 					while slotId ~= nil do
 						IIfA:EvalBagItem(bagId, slotId)
 						slotId = GetNextVirtualBagSlotId(slotId)
diff --git a/IIfA/IIfAMenu.lua b/IIfA/IIfAMenu.lua
index 3fe49ab..6149bb9 100644
--- a/IIfA/IIfAMenu.lua
+++ b/IIfA/IIfAMenu.lua
@@ -4,6 +4,8 @@ IIfA = IIfA
 local LAM = LibStub("LibAddonMenu-2.0")
 local LMP = LibStub("LibMediaProvider-1.0")

+local id, guildName, deleteHouse, restoreHouse, name
+
 local function getCharacterInventories()

 	local accountInventories = {}
diff --git a/IIfA/IIfA_xml_adapter.lua b/IIfA/IIfA_xml_adapter.lua
index bb53224..e76d28a 100644
--- a/IIfA/IIfA_xml_adapter.lua
+++ b/IIfA/IIfA_xml_adapter.lua
@@ -40,7 +40,7 @@ end
  --]]

 function IIfA:GuiDock(bDock)
-	sceneName = IIfA:GetCurrentSceneName()
+	local sceneName = IIfA:GetCurrentSceneName()
 	-- docking not allowed when hud is active (it has no clue what it's docking to)
 	if bDock and sceneName == "hud" then
 		return
@@ -227,7 +227,7 @@ function IIfA:GuiOnFilterButton(control, mouseButton, filterGroup, filterTypes,
 	IIfA.filterGroup = filterGroup
 	IIfA.filterTypes = filterTypes

-	function SetSubSubFilters(_, subFiltName, choice)
+	local function SetSubSubFilters(_, subFiltName, choice)
 		IIfA.filterTypes = choice.subFiltTypes
 		IIfA:RefreshInventoryScroll()
 	end
@@ -242,7 +242,7 @@ function IIfA:GuiOnFilterButton(control, mouseButton, filterGroup, filterTypes,
 		end
 		comboBox:ClearItems()
 		comboBox:SetSortsItems(false)
-		entry = comboBox:CreateItemEntry("All", SetSubSubFilters)
+		local entry = comboBox:CreateItemEntry("All", SetSubSubFilters)
 		entry.subFiltTypes = IIfA.filterTypes
 		comboBox:AddItem(entry)
 		if IIfA.filterGroup == "Body" or		--:find("Body") ~= nil or
@@ -414,6 +414,8 @@ function IIfA:GuiReloadDimensions(settings, sceneName)
 end

 function IIfA:GuiResizeLines()
+	local lines
+
 	if not IIFA_GUI_ListHolder.lines then
 		lines = IIfA:CreateInventoryScroll()
 	end