Quantcast

Moved player initialization code from core.lua to Player.lua

James D. Callahan III [03-06-11 - 02:39]
Moved player initialization code from core.lua to Player.lua
Filename
Player.lua
core.lua
diff --git a/Player.lua b/Player.lua
index ecfcb57..6906f58 100644
--- a/Player.lua
+++ b/Player.lua
@@ -60,8 +60,23 @@ local A = private.acquire_types
 local F = private.filter_flags

 -------------------------------------------------------------------------------
--- Functions
+-- Player methods.
 -------------------------------------------------------------------------------
+function Player:Initialize()
+	self.faction = UnitFactionGroup("player")
+	self.Class = select(2, UnitClass("player"))
+	self:SetProfessions()
+
+	-------------------------------------------------------------------------------
+	-- Set the scanned state for all professions to false.
+	-------------------------------------------------------------------------------
+	self.has_scanned = {}
+
+	for profession in pairs(self.professions) do
+		self.has_scanned[profession] = false
+	end
+end
+
 function Player:HasProperRepLevel(rep_data)
 	if not rep_data then
 		return true
@@ -115,6 +130,22 @@ do

 	-- Sets the player's professions. Used when the AddOn initializes and when a profession has been learned or unlearned.
 	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
+			}
+		end
 		local profession_list = self.professions

 		for i in pairs(profession_list) do
diff --git a/core.lua b/core.lua
index de30d44..6e3fd45 100644
--- a/core.lua
+++ b/core.lua
@@ -685,43 +685,7 @@ function addon:OnEnable()
 			order = 550,
 		}
 	end
-
-	-------------------------------------------------------------------------------
-	-- Initialize the player's data.
-	-------------------------------------------------------------------------------
-	do
-		Player.faction = UnitFactionGroup("player")
-		Player["Class"] = select(2, UnitClass("player"))
-
-		-------------------------------------------------------------------------------
-		-- Get the player's professions.
-		-------------------------------------------------------------------------------
-		Player.professions = {
-			[GetSpellInfo(51304)]	= false, -- Alchemy
-			[GetSpellInfo(51300)]	= false, -- Blacksmithing
-			[GetSpellInfo(51296)]	= false, -- Cooking
-			[GetSpellInfo(51313)]	= false, -- Enchanting
-			[GetSpellInfo(51306)]	= false, -- Engineering
-			[GetSpellInfo(45542)]	= false, -- First Aid
-			[GetSpellInfo(51302)]	= false, -- Leatherworking
-			[GetSpellInfo(2656)]	= false, -- Smelting
-			[GetSpellInfo(51309)]	= false, -- Tailoring
-			[GetSpellInfo(51311)]	= false, -- Jewelcrafting
-			[GetSpellInfo(45363)]	= false, -- Inscription
-			[private.runeforging_name]	= false, -- Runeforging
-		}
-		Player:SetProfessions()
-
-		-------------------------------------------------------------------------------
-		-- Set the scanned state for all professions to false.
-		-------------------------------------------------------------------------------
-		Player.has_scanned = {}
-
-		for profession in pairs(Player.professions) do
-			Player.has_scanned[profession] = false
-		end
-
-	end	-- do
+	private.Player:Initialize()

 	-------------------------------------------------------------------------------
 	-- Initialize the SpecialtyTable and AllSpecialtiesTable.