Quantcast

Moved addon:ResetGUI() fron ARLFrame.lua to ARLConfig.lua as a file-local function, since it is only used there from the config options.

torhal [11-19-09 - 06:36]
Moved addon:ResetGUI() fron ARLFrame.lua to ARLConfig.lua as a file-local function, since it is only used there from the config options.
Moved the player profession-setting code from addon:OnEnable() to Player.lua as Player:SetProfessions() with a slight re-write - at some point this should be used when a player learns/unlearns professions.
Added some TODO comments throughout the code for variables set on the Player table which have no current use, and for functions which should be used for more than their current context.
Filename
ARLConfig.lua
ARLFrame.lua
AckisRecipeList.lua
Player.lua
diff --git a/ARLConfig.lua b/ARLConfig.lua
index 4395552..07652ae 100644
--- a/ARLConfig.lua
+++ b/ARLConfig.lua
@@ -24,31 +24,37 @@ This source code is released under All Rights Reserved.

 ]]--

-local MODNAME			= "Ackis Recipe List"
-local addon				= LibStub("AceAddon-3.0"):GetAddon(MODNAME)
+local MODNAME		= "Ackis Recipe List"
+local addon		= LibStub("AceAddon-3.0"):GetAddon(MODNAME)

-local BFAC				= LibStub("LibBabble-Faction-3.0"):GetLookupTable()
-local LC				= LOCALIZED_CLASS_NAMES_MALE
-local L					= LibStub("AceLocale-3.0"):GetLocale(MODNAME)
+local BFAC		= LibStub("LibBabble-Faction-3.0"):GetLookupTable()
+local LC		= LOCALIZED_CLASS_NAMES_MALE
+local L			= LibStub("AceLocale-3.0"):GetLocale(MODNAME)

-local AceConfig 		= LibStub("AceConfig-3.0")
-local AceConfigReg 		= LibStub("AceConfigRegistry-3.0")
+local AceConfig 	= LibStub("AceConfig-3.0")
+local AceConfigReg 	= LibStub("AceConfigRegistry-3.0")
 local AceConfigDialog 	= LibStub("AceConfigDialog-3.0")

 local modularOptions = {}

 local function giveProfiles()
-
 	return LibStub("AceDBOptions-3.0"):GetOptionsTable(addon.db)
+end

+local function ResetGUI()
+	addon.db.profile.frameopts.offsetx = 0
+	addon.db.profile.frameopts.offsety = 0
+	addon.db.profile.frameopts.anchorTo = ""
+	addon.db.profile.frameopts.anchorFrom = ""
+	addon.db.profile.frameopts.uiscale = 1
+	addon.db.profile.frameopts.tooltipscale = .9
+	addon.db.profile.frameopts.fontsize = 11
 end

-local options = nil
+local options

 local function fullOptions()
-
-	if (not options) then
-
+	if not options then
 		options = {
 			type = "group",
 			name = MODNAME,
@@ -109,7 +115,7 @@ local function fullOptions()
 							type	= "execute",
 							name	= L["Reset Window Position"],
 							desc	= L["RESET_WINDOW_DESC"],
-							func	= function(info) addon:ResetGUI() end,
+							func	= function(info) ResetGUI() end,
 						},
 						spacer1 = {
 							order	= 19,
diff --git a/ARLFrame.lua b/ARLFrame.lua
index ce30d10..3670828 100644
--- a/ARLFrame.lua
+++ b/ARLFrame.lua
@@ -271,7 +271,7 @@ end
 -- skill level or faction to learn it.
 -------------------------------------------------------------------------------
 local function ColourSkillLevel(recipeEntry, hasFaction, recStr)
-	local playerSkill = Player.ProfessionLevel
+	local playerSkill = Player["ProfessionLevel"]
 	local recipeSkill = recipeEntry["Level"]
 	local recipeOrange = recipeEntry["Orange"]
 	local recipeYellow = recipeEntry["Yellow"]
@@ -892,7 +892,7 @@ local function GenerateTooltipContent(owner, rIndex)
 	clr1 = addon:hexcolor("NORMAL")

 	local recipeSkill = recipeDB[rIndex]["Level"]
-	local playerSkill = Player.ProfessionLevel
+	local playerSkill = Player["ProfessionLevel"]

 	if recipeSkill > playerSkill then
 		clr2 = addon:hexcolor("RED")
@@ -1443,18 +1443,6 @@ local function SetProgressBar()

 end

-function addon:ResetGUI()
-
-	addon.db.profile.frameopts.offsetx = 0
-	addon.db.profile.frameopts.offsety = 0
-	addon.db.profile.frameopts.anchorTo = ""
-	addon.db.profile.frameopts.anchorFrom = ""
-	addon.db.profile.frameopts.uiscale = 1
-	addon.db.profile.frameopts.tooltipscale = .9
-	addon.db.profile.frameopts.fontsize = 11
-
-end
-
 -------------------------------------------------------------------------------
 -- Sorts the recipe Database depending on the settings defined in the database.
 -------------------------------------------------------------------------------
@@ -1462,8 +1450,8 @@ local SortMissingRecipes
 do
 	local tsort = table.sort

-	local sortFuncs = nil		-- Sorting functions
-	local SortedRecipeIndex = {}	-- Create a new array for the sorted index
+	local sortFuncs
+	local SortedRecipeIndex = {}

 	function SortMissingRecipes(RecipeDB)
 		if not sortFuncs then
@@ -1517,7 +1505,6 @@ do
 							  end
 						  end,

-				-- Will only sort based off of the first acquire type
 				["Location"]	= function(a, b)
 							  -- We do the or "" because of nil's, I think this would be better if I just left it as a table which was returned
 							  local reca = RecipeDB[a]["Locations"] or ""
@@ -1528,7 +1515,6 @@ do

 							  if reca == recb then
 								  return sortFuncs["Acquisition"](a, b)
---								  return RecipeDB[a]["Name"] < RecipeDB[b]["Name"]
 							  else
 								  return reca < recb
 							  end
@@ -1795,7 +1781,7 @@ do
 	function addon:ToggleFrame()
 		-- What profession is opened?
 		local cprof = GetTradeSkillLine()
-		local current_prof = Player.Profession
+		local current_prof = Player["Profession"]

 		-- The frame is visible
 		if MainPanel:IsVisible() then
@@ -2871,7 +2857,7 @@ function addon:InitializeFrame()
 	-- Check to see if we're Horde or Alliance, and change the displayed
 	-- reputation strings to be faction-correct.
 	-------------------------------------------------------------------------------
-	local isAlliance = (Player.Faction == "Alliance")
+	local isAlliance = (Player["Faction"] == "Alliance")

 	local HonorHold_Thrallmar_FactionText = isAlliance and BFAC["Honor Hold"] or BFAC["Thrallmar"]
 	local Kurenai_Maghar_FactionText = isAlliance and BFAC["Kurenai"] or BFAC["The Mag'har"]
@@ -3036,7 +3022,7 @@ function addon:InitializeFrame()
 					     Player["Profession"] = SortedProfessions[currentProfIndex].name

 					     local is_shown = TradeSkillFrame:IsVisible()
-					     CastSpellByName(Player.Profession)
+					     CastSpellByName(Player["Profession"])
 					     addon:Scan()

 					     if not is_shown then
@@ -3063,7 +3049,7 @@ function addon:InitializeFrame()
 					     for i = 1, NumSkillLines, 1 do
 						     local skillName, _, _, skillRank = GetSkillLineInfo(i)

-						     if skillName == Player.Profession then
+						     if skillName == Player["Profession"] then
 							     Player["ProfessionLevel"] = skillRank
 							     break
 						     end
@@ -4607,7 +4593,7 @@ function addon:DisplayFrame(asTable)	-- AllSpecialtiesTable

 	-- get our current profession's index
 	for k, v in pairs(SortedProfessions) do
-		if v.name == Player.Profession then
+		if v.name == Player["Profession"] then
 			currentProfIndex = k
 			break
 		end
diff --git a/AckisRecipeList.lua b/AckisRecipeList.lua
index e950786..c69fac4 100644
--- a/AckisRecipeList.lua
+++ b/AckisRecipeList.lua
@@ -560,8 +560,8 @@ function addon:OnEnable()
 	-- Initialize the player's data.
 	-------------------------------------------------------------------------------
 	do
-		Player.Faction = UnitFactionGroup("player")
-		Player.Class = select(2, UnitClass("player"))
+		Player["Faction"] = UnitFactionGroup("player")
+		Player["Class"] = select(2, UnitClass("player"))

 		-------------------------------------------------------------------------------
 		-- Get the player's reputation levels.
@@ -570,7 +570,7 @@ function addon:OnEnable()
 		Player:SetReputationLevels()

 		-------------------------------------------------------------------------------
-		---Scan first 25 spellbook slots to identify all applicable professions
+		-- Get the player's professions.
 		-------------------------------------------------------------------------------
 		Player["Professions"] = {
 			[GetSpellInfo(51304)] = false, -- Alchemy
@@ -586,30 +586,13 @@ function addon:OnEnable()
 			[GetSpellInfo(45363)] = false, -- Inscription
 			[GetSpellInfo(53428)] = false, -- Runeforging
 		}
-		local profession_list = Player["Professions"]
-
-		-- Reset the table, they may have unlearnt a profession
-		for i in pairs(profession_list) do
-			profession_list[i] = false
-		end
-
-		-- Scan through the spell book getting the spell names
-		for index = 1, 25, 1 do
-			local spellName = GetSpellName(index, BOOKTYPE_SPELL)
-
-			if not spellName or index == 25 then
-				break
-			end
-
-			if not profession_list[spellName] or spellName == GetSpellInfo(2656) then
-				if spellName == GetSpellInfo(2656) then
-					profession_list[GetSpellInfo(32606)] = true
-				else
-					profession_list[spellName] = true
-				end
-			end
-		end
+		Player:SetProfessions()
+	end	-- do

+	-------------------------------------------------------------------------------
+	-- Initialize the SpecialtyTable and AllSpecialtiesTable.
+	-------------------------------------------------------------------------------
+	do
 		local AlchemySpec = {
 			[GetSpellInfo(28674)] = 28674,
 			[GetSpellInfo(28678)] = 28678,
@@ -617,11 +600,11 @@ function addon:OnEnable()
 		}

 		local BlacksmithSpec = {
-			[GetSpellInfo(9788)] = 9788, -- Armorsmith
-			[GetSpellInfo(17041)] = 17041, -- Master Axesmith
-			[GetSpellInfo(17040)] = 17040, -- Master Hammersmith
-			[GetSpellInfo(17039)] = 17039, -- Master Swordsmith
-			[GetSpellInfo(9787)] = 9787, -- Weaponsmith
+			[GetSpellInfo(9788)] = 9788,	-- Armorsmith
+			[GetSpellInfo(17041)] = 17041,	-- Master Axesmith
+			[GetSpellInfo(17040)] = 17040,	-- Master Hammersmith
+			[GetSpellInfo(17039)] = 17039,	-- Master Swordsmith
+			[GetSpellInfo(9787)] = 9787,	-- Weaponsmith
 		}

 		local EngineeringSpec = {
@@ -1417,9 +1400,6 @@ end
 -- Recipe Scanning Functions
 -------------------------------------------------------------------------------
 do
-	local UnitClass = UnitClass
-	local UnitFactionGroup = UnitFactionGroup
-
 	-- List of tradeskill headers, used in addon:Scan()
 	local header_list = {}

@@ -1452,6 +1432,7 @@ do
 		end

 		-- Add the recipes to the database
+		-- TODO: Figure out what this variable was supposed to be for - it isn't used anywhere. -Torhal
 		Player.totalRecipes = InitializeRecipe(Player["Profession"])

 		--- Set the known flag to false for every recipe in the database.
@@ -1526,13 +1507,14 @@ do
 				end
 			end
 		end
+		-- TODO: Figure out what this variable was supposed to be for - it isn't used anywhere. -Torhal
 		Player.foundRecipes = recipes_found

 		self:UpdateFilters()
 		Player:MarkExclusions()

 		if textdump then
-			self:DisplayTextDump(RecipeList, Player.Profession)
+			self:DisplayTextDump(RecipeList, Player["Profession"])
 		else
 			self:DisplayFrame(AllSpecialtiesTable)
 		end
diff --git a/Player.lua b/Player.lua
index 0550a17..52fddf3 100644
--- a/Player.lua
+++ b/Player.lua
@@ -140,6 +140,34 @@ function Player:IsCorrectFaction(recipe_flags)
 	return true
 end

+-- Sets the player's professions. Used when the AddOn initializes and when a profession has been learned or unlearned.
+-- TODO: Make the AddOn actually detect when a profession is learned/unlearned, then call this function. -Torhal
+function Player:SetProfessions()
+	local profession_list = self["Professions"]
+
+	for i in pairs(profession_list) do
+		profession_list[i] = false
+	end
+	local smelting_spell = GetSpellInfo(2656)
+	local mining_spell = GetSpellInfo(32606)
+
+	for index = 1, 25, 1 do
+		local spell_name = GetSpellName(index, BOOKTYPE_SPELL)
+
+		if not spell_name or index == 25 then
+			break
+		end
+
+		if not profession_list[spell_name] or spell_name == smelting_spell then
+			-- If the player has smelting, then mining is also known.
+			if spell_name == smelting_spell then
+				profession_list[mining_spell] = true
+			else
+				profession_list[spell_name] = true
+			end
+		end
+	end
+end

 do
 	local GetNumFactions = GetNumFactions