Quantcast

Perform table creation on declaration of RecipeList, CustomList, MobList, QuestList, ReputationList, TrainerList, SeasonalList, VendorList, and RepFilters.

torhal [09-22-09 - 23:02]
Perform table creation on declaration of RecipeList, CustomList, MobList, QuestList, ReputationList, TrainerList, SeasonalList, VendorList, and RepFilters.
Changed the local function InitDatabases() to be a member of the addon object, as well as removing existence checks for and creation of tables as they will already exist.
In addon:OnEnable(): Call addon:InitDatabases() here, then nil it out.
Renamed addon:AckisRecipeList_Command() to addon:Scan(), and removed the check for existence of RecipeList and subsequent call to InitDatabases().
In addon:InitRecipeData(): Removed the check for existence of RecipeList. I'm not sure if this function is even useful for anything.
In addon:ToggleFrame(): Removed the check to see if the frame exists, because it always will now at this point.
Filename
ARLConfig.lua
ARLFrame.lua
AckisRecipeList.lua
diff --git a/ARLConfig.lua b/ARLConfig.lua
index 216a463..48efa1f 100644
--- a/ARLConfig.lua
+++ b/ARLConfig.lua
@@ -1071,14 +1071,14 @@ local function fullOptions()
 							type	= "execute",
 							name	= L["Scan"],
 							desc	= L["SCAN_RECIPES_DESC"],
-							func	= function(info) addon:AckisRecipeList_Command(false) end,
+							func	= function(info) addon:Scan(false) end,
 						},
 						textdump = {
 							order	= 13,
 							type	= "execute",
 							name	= L["Text Dump"],
 							desc	= L["TEXT_DUMP_DESC"],
-							func	= function(info) addon:AckisRecipeList_Command(true) end,
+							func	= function(info) addon:Scan(true) end,
 						},
 						exclusionlist = {
 							order	= 14,
diff --git a/ARLFrame.lua b/ARLFrame.lua
index 2f59b1f..0fb9d0c 100644
--- a/ARLFrame.lua
+++ b/ARLFrame.lua
@@ -1973,45 +1973,41 @@ do
 	-- Output: Frame is toggled, etc depending on state.

 	function addon:ToggleFrame()
-
 		-- What profession is opened?
 		local cprof = GetTradeSkillLine()

 		-- The frame is visible
-		if (MainPanel and MainPanel:IsVisible()) then
+		if MainPanel:IsVisible() then
 			-- Shift only (Text dump)
-			if (IsShiftKeyDown() and not IsAltKeyDown() and not IsControlKeyDown()) then
-				self:AckisRecipeList_Command(true)
+			if IsShiftKeyDown() and not IsAltKeyDown() and not IsControlKeyDown() then
+				self:Scan(true)
 			-- Alt only (Wipe icons from map)
-			elseif (not IsShiftKeyDown() and IsAltKeyDown() and not IsControlKeyDown()) then
+			elseif not IsShiftKeyDown() and IsAltKeyDown() and not IsControlKeyDown() then
 				self:ClearMap()
 			-- If we have the same profession open, then we close the scanned window
-			elseif (not IsShiftKeyDown() and not IsAltKeyDown() and not IsControlKeyDown()) and (currentProfession == cprof) then
+			elseif not IsShiftKeyDown() and not IsAltKeyDown() and not IsControlKeyDown() and currentProfession == cprof then
 				MainPanel:Hide()
 			-- If we have a different profession open we do a scan
-			elseif (not IsShiftKeyDown() and not IsAltKeyDown() and not IsControlKeyDown()) then
-				self:AckisRecipeList_Command(false)
+			elseif not IsShiftKeyDown() and not IsAltKeyDown() and not IsControlKeyDown() then
+				self:Scan(false)
 				self:SetupMap()
 				currentProfession = cprof
 			end
-		-- Frame is hidden
 		else
 			currentProfession = cprof
 			-- Shift only (Text dump)
-			if (IsShiftKeyDown() and not IsAltKeyDown() and not IsControlKeyDown()) then
-				self:AckisRecipeList_Command(true)
+			if IsShiftKeyDown() and not IsAltKeyDown() and not IsControlKeyDown() then
+				self:Scan(true)
 			-- Alt only (Wipe icons from map)
-			elseif (not IsShiftKeyDown() and IsAltKeyDown() and not IsControlKeyDown()) then
+			elseif not IsShiftKeyDown() and IsAltKeyDown() and not IsControlKeyDown() then
 				self:ClearMap()
 			-- No modification
-			elseif (not IsShiftKeyDown() and not IsAltKeyDown() and not IsControlKeyDown()) then
-				self:AckisRecipeList_Command(false)
+			elseif not IsShiftKeyDown() and not IsAltKeyDown() and not IsControlKeyDown() then
+				self:Scan(false)
 				self:SetupMap()
 			end
 		end
-
 	end
-
 end

 -- Description: Set the texture on the switcher button.
@@ -3401,22 +3397,21 @@ function addon:InitializeFrame()
 						     25, 90, "TOPRIGHT", MainPanel, "TOPRIGHT", -8, -40, "GameFontNormalSmall",
 						     "GameFontHighlightSmall", L["FILTER_OPEN"], "CENTER", L["FILTER_OPEN_DESC"], 1)
 	ARL_FilterButton:SetScript("OnClick", function()
-						      local frame = MainPanel
 						      local xPos = frame:GetLeft()
 						      local yPos = frame:GetBottom()

-						      if frame._is_expanded then
+						      if MainPanel._is_expanded then
 							      -- Adjust the frame size and texture
-							      frame:ClearAllPoints()
-							      frame:SetWidth(293)
-							      frame:SetHeight(447)
+							      MainPanel:ClearAllPoints()
+							      MainPanel:SetWidth(293)
+							      MainPanel:SetHeight(447)

 							      addon.bgTexture:SetTexture([[Interface\Addons\AckisRecipeList\img\main]])
 							      addon.bgTexture:SetAllPoints(MainPanel)
 							      addon.bgTexture:SetTexCoord(0, (293/512), 0, (447/512))

-							      frame._is_expanded = false
-							      frame:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", xPos, yPos)
+							      MainPanel._is_expanded = false
+							      MainPanel:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", xPos, yPos)
 							      ARL_ProgressBar:SetWidth(195)

 							      -- Change the text and tooltip for the filter button
@@ -3440,16 +3435,16 @@ function addon:InitializeFrame()
 							      ARL_ResetButton:Hide()
 						      else
 							      -- Adjust the frame size and texture
-							      frame:ClearAllPoints()
-							      frame:SetWidth(444)
-							      frame:SetHeight(447)
+							      MainPanel:ClearAllPoints()
+							      MainPanel:SetWidth(444)
+							      MainPanel:SetHeight(447)

 							      addon.bgTexture:SetTexture([[Interface\Addons\AckisRecipeList\img\expanded]])
 							      addon.bgTexture:SetAllPoints(MainPanel)
 							      addon.bgTexture:SetTexCoord(0, (444/512), 0, (447/512))

-							      frame._is_expanded = true
-							      frame:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", xPos, yPos)
+							      MainPanel._is_expanded = true
+							      MainPanel:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", xPos, yPos)
 							      ARL_ProgressBar:SetWidth(345)

 							      -- Change the text and tooltip for the filter button
@@ -3467,7 +3462,7 @@ function addon:InitializeFrame()

 							      ARL_ResetButton:Show()
 						      end
-						      frame:ResetTitle()
+						      MainPanel:ResetTitle()
 					      end)

 	-------------------------------------------------------------------------------
diff --git a/AckisRecipeList.lua b/AckisRecipeList.lua
index 902203d..05675e7 100644
--- a/AckisRecipeList.lua
+++ b/AckisRecipeList.lua
@@ -314,7 +314,7 @@ function addon:OnEnable()
 			type = 'execute',
 			name = L["Scan"],
 			desc = L["SCAN_RECIPES_DESC"],
-			func = function() addon:AckisRecipeList_Command(false) end,
+			func = function() addon:Scan(false) end,
 			order = 550,
 		}
 	end
@@ -339,6 +339,9 @@ function addon:OnEnable()
 	self:CreateScanButton()
 	self:InitializeFrame()
 	self.InitializeFrame = nil
+
+	self:InitDatabases()
+	self.InitDatabases = nil
 end

 ---Run when the addon is disabled. Ace3 takes care of unregistering events, etc.
@@ -1449,7 +1452,7 @@ function addon:ChatCommand(input)
 	elseif (input == strlower(L["Documentation"])) then
 		InterfaceOptionsFrame_OpenToCategory(self.optionsFrame["Documentation"])
 	elseif (input == strlower(L["Scan"])) then
-		self:AckisRecipeList_Command(false)
+		self:Scan(false)
 	elseif (input == strlower("scandata")) then
 		self:ScanSkillLevelData()
 	elseif (input == strlower("scanprof")) then
@@ -1469,21 +1472,21 @@ local function ResetKnown(RecipeDB)
 end

 do
-
 	local UnitClass = UnitClass
 	local UnitFactionGroup = UnitFactionGroup
 	local tsort = table.sort

-	local RecipeList = nil
-
-	local CustomList = nil
-	local MobList = nil
-	local QuestList = nil
-	local ReputationList = nil
-	local TrainerList = nil
-	local SeasonalList = nil
-	local VendorList = nil
-	local RepFilters = nil
+	local RecipeList = {}
+
+	-- Database tables.
+	local CustomList = {}
+	local MobList = {}
+	local QuestList = {}
+	local ReputationList = {}
+	local TrainerList = {}
+	local SeasonalList = {}
+	local VendorList = {}
+	local RepFilters = {}		-- These are assigned during a scan, not in InitDatabases()
 	local AllSpecialtiesTable = nil
 	local SpecialtyTable = nil

@@ -1752,100 +1755,52 @@ do
 	end

 	---Initializes all the recipe databases to their initial
-	local function InitDatabases()
-		-- Initializes the custom list
-		if not CustomList then
-			CustomList = {}
-			addon:InitCustom(CustomList)
-		end
-
-		-- Initializes the mob list
-		if not MobList then
-			MobList = {}
-			addon:InitMob(MobList)
-		end
-
-		-- Initializes the quest list
-		if not QuestList then
-			QuestList = {}
-			addon:InitQuest(QuestList)
-		end
-
-		-- Initializes the reputation list
-		if not ReputationList then
-			ReputationList = {}
-			addon:InitReputation(ReputationList)
-		end
-
-		-- Initializes the trainer list
-		if not TrainerList then
-			TrainerList = {}
-			addon:InitTrainer(TrainerList)
-		end
-
-		-- Initializes the season list
-		if not SeasonalList then
-			SeasonalList = {}
-			addon:InitSeasons(SeasonalList)
-		end
-
-		-- Initializes the vendor list
-		if not VendorList then
-			VendorList = {}
-			addon:InitVendor(VendorList)
-		end
-
-		-- Initializes the reputation filters
-		-- Don't assign values no because we do a scan later on
-		if not RepFilters then
-			RepFilters = {}
-		end
-
-		-- Initializes the recipe list
-		if not RecipeList then
-			RecipeList = {}
-			addon.recipe_list = RecipeList
-		end
+	function addon:InitDatabases()
+		addon:InitCustom(CustomList)
+		addon:InitMob(MobList)
+		addon:InitQuest(QuestList)
+		addon:InitReputation(ReputationList)
+		addon:InitTrainer(TrainerList)
+		addon:InitSeasons(SeasonalList)
+		addon:InitVendor(VendorList)
+
+		addon.recipe_list = RecipeList
 	end

 	--- Causes a scan of the tradeskill to be conducted. Function called when the scan button is clicked.   Parses recipes and displays output
-	-- @name AckisRecipeList:AckisRecipeList_Command
-	-- @usage AckisRecipeList:AckisRecipeList_Command(true)
+	-- @name AckisRecipeList:Scan
+	-- @usage AckisRecipeList:Scan(true)
 	-- @param textdump Boolean indicating if we want the output to be a text dump, or if we want to use the ARL GUI.
 	-- @return A frame with either the text dump, or the ARL frame.
-	function addon:AckisRecipeList_Command(textdump)
+	function addon:Scan(textdump)
 		-- If we don't have a trade skill window open, lets return out of here
 		if not TRADE_WINDOW_OPENED then
 			self:Print(L["OpenTradeSkillWindow"])
 			return
-		-- Trade type skills
-		else
-			-- First time a scan has been run, we need to get the player specific data, specifically faction information, profession information and other pertinent data.
-			if not playerData.playerClass then
-				InitPlayerData()
-			end
-			-- Lets create all the databases needed if this is the first time everything has been run.
-			if not RecipeList then
-				InitDatabases()
-			end
-			-- Get the name of the current trade skill opened, along with the current level of the skill.
-			playerData.playerProfession, playerData.playerProfessionLevel = GetTradeSkillLine()
-			-- Get the current profession Specialty
-			playerData.playerSpecialty = GetTradeSpecialty(SpecialtyTable, playerData)
-			-- Add the recipes to the database
-			playerData.totalRecipes = InitializeRecipes(RecipeList, playerData.playerProfession)
-			-- Reset all the known flags
-			ResetKnown(RecipeList)
-			-- Scan all recipes and mark the ones which ones we know
-			self:ScanForKnownRecipes(RecipeList, playerData)
-			-- Update the table containing which reps to display
-			PopulateRepFilters(RepFilters)
-			-- Add filtering flags to the recipes
-			self:UpdateFilters(RecipeList, AllSpecialtiesTable, playerData)
-			-- Mark excluded recipes
-			playerData.excluded_recipes_known, playerData.excluded_recipes_unknown = self:GetExclusions(RecipeList, playerData.playerProfession)
 		end

+		-- First time a scan has been run, we need to get the player specific data, specifically faction information, profession information and other pertinent data.
+		if not playerData.playerClass then
+			InitPlayerData()
+		end
+
+		-- Get the name of the current trade skill opened, along with the current level of the skill.
+		playerData.playerProfession, playerData.playerProfessionLevel = GetTradeSkillLine()
+		-- Get the current profession Specialty
+		playerData.playerSpecialty = GetTradeSpecialty(SpecialtyTable, playerData)
+		-- Add the recipes to the database
+		playerData.totalRecipes = InitializeRecipes(RecipeList, playerData.playerProfession)
+		-- Reset all the known flags
+		ResetKnown(RecipeList)
+		-- Scan all recipes and mark the ones which ones we know
+		self:ScanForKnownRecipes(RecipeList, playerData)
+		-- Update the table containing which reps to display
+		PopulateRepFilters(RepFilters)
+		-- Add filtering flags to the recipes
+		self:UpdateFilters(RecipeList, AllSpecialtiesTable, playerData)
+		-- Mark excluded recipes
+		playerData.excluded_recipes_known, playerData.excluded_recipes_unknown = self:GetExclusions(RecipeList, playerData.playerProfession)
+
 		if textdump then
 			self:DisplayTextDump(RecipeList, playerData.playerProfession)
 		else
@@ -1874,12 +1829,7 @@ do
 	-- @return Boolean indicating if the operation was successful.  The recipe database will be populated with appropriate data.
 	-- @return Arrays containing the RecipeList, MobList, TrainerList, VendorList, QuestList, ReputationList, SeasonalList.
 	function addon:InitRecipeData()
-		if RecipeList then
-			return false, RecipeList, MobList, TrainerList, VendorList, QuestList, ReputationList, SeasonalList
-		else
-			InitDatabases()
-			return true, RecipeList, MobList, TrainerList, VendorList, QuestList, ReputationList, SeasonalList
-		end
+		return false, RecipeList, MobList, TrainerList, VendorList, QuestList, ReputationList, SeasonalList
 	end

 	--- API for external addons to get recipe information from ARL