Quantcast

Moved the player reputation updates into a Player method. Also changed the profession skill-level updates while I was at it.

James D. Callahan III [03-08-11 - 06:19]
Moved the player reputation updates into a Player method. Also changed the profession skill-level updates while I was at it.
Filename
Player.lua
core.lua
diff --git a/Player.lua b/Player.lua
index 4f53788..a807cdd 100644
--- a/Player.lua
+++ b/Player.lua
@@ -38,7 +38,7 @@ local addon	= LibStub("AceAddon-3.0"):GetAddon(MODNAME)
 local BFAC	= LibStub("LibBabble-Faction-3.0"):GetLookupTable()
 local L		= LibStub("AceLocale-3.0"):GetLocale(MODNAME)

-local private	= _G.select(2, ...)
+local FOLDER_NAME, private	= ...

 ------------------------------------------------------------------------------
 -- Data which is stored regarding a players statistics (luadoc copied from Collectinator, needs updating)
@@ -63,8 +63,8 @@ local F = private.filter_flags
 -- Player methods.
 -------------------------------------------------------------------------------
 function Player:Initialize()
-	self.faction = UnitFactionGroup("player")
-	self.Class = select(2, UnitClass("player"))
+	self.faction = _G.UnitFactionGroup("player")
+	self.Class = _G.select(2, _G.UnitClass("player"))
 	self:SetProfessions()

 	-------------------------------------------------------------------------------
@@ -77,6 +77,52 @@ function Player:Initialize()
 	end
 end

+do
+	local headers = {}
+
+	function Player:UpdateReputations()
+		self["Reputation"] = self["Reputation"] or {}
+
+		table.wipe(headers)
+
+		-- Number of factions before expansion
+		local num_factions = _G.GetNumFactions()
+
+		-- Expand all the headers, storing those which were collapsed.
+		for i = num_factions, 1, -1 do
+			local name, _, _, _, _, _, _, _, _, isCollapsed = _G.GetFactionInfo(i)
+
+			if isCollapsed then
+				_G.ExpandFactionHeader(i)
+				headers[name] = true
+			end
+		end
+
+		-- Number of factions with everything expanded
+		num_factions = _G.GetNumFactions()
+
+		-- Get the rep levels
+		for i = 1, num_factions, 1 do
+			local name, _, replevel = _G.GetFactionInfo(i)
+
+			-- If the rep is greater than neutral
+			if replevel > 4 then
+				-- We use levels of 0, 1, 2, 3, 4 internally for reputation levels, make it correspond here
+				self["Reputation"][name] = replevel - 4
+			end
+		end
+
+		-- Collapse the headers again
+		for i = num_factions, 1, -1 do
+			local name = _G.GetFactionInfo(i)
+
+			if headers[name] then
+				_G.CollapseFactionHeader(i)
+			end
+		end
+	end
+end	-- do-block
+
 function Player:HasProperRepLevel(rep_data)
 	if not rep_data then
 		return true
@@ -132,24 +178,23 @@ do
 	function Player:SetProfessions()
 		if not self.professions then
 			self.professions = {
-				[_G.GetSpellInfo(51304)] = false, -- Alchemy
-				[_G.GetSpellInfo(51300)] = false, -- Blacksmithing
-				[_G.GetSpellInfo(51296)] = false, -- Cooking
-				[_G.GetSpellInfo(51313)] = false, -- Enchanting
-				[_G.GetSpellInfo(51306)] = false, -- Engineering
-				[_G.GetSpellInfo(45542)] = false, -- First Aid
-				[_G.GetSpellInfo(51302)] = false, -- Leatherworking
-				[_G.GetSpellInfo(2656)] = false, -- Smelting
-				[_G.GetSpellInfo(51309)] = false, -- Tailoring
-				[_G.GetSpellInfo(51311)] = false, -- Jewelcrafting
-				[_G.GetSpellInfo(45363)] = false, -- Inscription
-				[private.runeforging_name] = false, -- Runeforging
+				[_G.GetSpellInfo(51304)]	= false, -- Alchemy
+				[_G.GetSpellInfo(51300)]	= false, -- Blacksmithing
+				[_G.GetSpellInfo(51296)]	= false, -- Cooking
+				[_G.GetSpellInfo(51313)]	= false, -- Enchanting
+				[_G.GetSpellInfo(51306)]	= false, -- Engineering
+				[_G.GetSpellInfo(45542)]	= false, -- First Aid
+				[_G.GetSpellInfo(51302)]	= false, -- Leatherworking
+				[_G.GetSpellInfo(2656)]		= false, -- Smelting
+				[_G.GetSpellInfo(51309)]	= false, -- Tailoring
+				[_G.GetSpellInfo(51311)]	= false, -- Jewelcrafting
+				[_G.GetSpellInfo(45363)]	= false, -- Inscription
+				[private.runeforging_name]	= false, -- Runeforging
 			}
 		end
-		local profession_list = self.professions

-		for i in pairs(profession_list) do
-			profession_list[i] = false
+		for i in pairs(self.professions) do
+			self.professions[i] = nil
 		end
 		local known = known_professions

@@ -162,7 +207,7 @@ do
 				if name == private.mining_name then
 					name = private.professions["Smelting"]
 				end
-				profession_list[name] = true
+				self.professions[name] = rank
 			end
 		end
 	end
diff --git a/core.lua b/core.lua
index b61ce53..8f38901 100644
--- a/core.lua
+++ b/core.lua
@@ -1031,8 +1031,7 @@ do
 		-- Make sure we're only updating a profession the character actually knows - this could be a scan from a tradeskill link.
 		local is_linked = _G.IsTradeSkillLinked() or _G.IsTradeSkillGuild()

-		if not is_linked and player.professions[current_prof] then
-			player.professions[current_prof] = prof_level
+		if not is_linked then
 			player.has_scanned[current_prof] = true
 		end

@@ -1167,45 +1166,7 @@ do
 		-------------------------------------------------------------------------------
 		-- Update the player's reputation levels.
 		-------------------------------------------------------------------------------
-		player["Reputation"] = player["Reputation"] or {}
-
-		table.wipe(header_list)
-
-		-- Number of factions before expansion
-		local num_factions = _G.GetNumFactions()
-
-		-- Expand all the headers, storing those which were collapsed.
-		for i = num_factions, 1, -1 do
-			local name, _, _, _, _, _, _, _, _, isCollapsed = _G.GetFactionInfo(i)
-
-			if isCollapsed then
-				_G.ExpandFactionHeader(i)
-				header_list[name] = true
-			end
-		end
-
-		-- Number of factions with everything expanded
-		num_factions = _G.GetNumFactions()
-
-		-- Get the rep levels
-		for i = 1, num_factions, 1 do
-			local name, _, replevel = _G.GetFactionInfo(i)
-
-			-- If the rep is greater than neutral
-			if replevel > 4 then
-				-- We use levels of 0, 1, 2, 3, 4 internally for reputation levels, make it correspond here
-				player["Reputation"][name] = replevel - 4
-			end
-		end
-
-		-- Collapse the headers again
-		for i = num_factions, 1, -1 do
-			local name = _G.GetFactionInfo(i)
-
-			if header_list[name] then
-				_G.CollapseFactionHeader(i)
-			end
-		end
+		player:UpdateReputations()

 		-------------------------------------------------------------------------------
 		-- Everything is ready - display the GUI or dump the list to text.