Quantcast

Use standard AceAddon methods instead of deferring with FirstInit().

Johnny C. Lam [03-02-13 - 17:57]
Use standard AceAddon methods instead of deferring with FirstInit().

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@707 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
Ovale.lua
OvaleData.lua
OvaleOptions.lua
diff --git a/Ovale.lua b/Ovale.lua
index f8354d9..eac3bcf 100644
--- a/Ovale.lua
+++ b/Ovale.lua
@@ -26,8 +26,6 @@ Ovale.L = L
 Ovale.defaut = {}
 --The table of check boxes definition
 Ovale.casesACocher = {}
---allows to do some initialization the first time the addon is enabled
-Ovale.firstInit = false
 --the frame with the icons
 Ovale.frame = nil
 --check boxes GUI items
@@ -106,27 +104,7 @@ function Ovale:CompileAll()
 	end
 end

-function Ovale:FirstInit()
-	self.firstInit = true
-
-	OvaleData:FirstInit()
-
-	self.frame = LibStub("AceGUI-3.0"):Create("OvaleFrame")
-
-	local profile = OvaleOptions:GetProfile()
-
-	self.frame:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", profile.left, profile.top)
-	self:UpdateFrame()
-	if not profile.display then
-		self.frame:Hide()
-	end
-end
-
 function Ovale:OnEnable()
-	if not self.firstInit then
-		self:FirstInit()
-	end
-
     -- Called when the addon is enabled
 	RegisterAddonMessagePrefix("Ovale")
 	self:RegisterEvent("PLAYER_EQUIPMENT_CHANGED")
@@ -136,7 +114,10 @@ function Ovale:OnEnable()
 	self:RegisterEvent("CHAT_MSG_ADDON")
 	self:RegisterMessage("Ovale_UpdateShapeshiftForm")

-	self:UpdateVisibility()
+	local profile = OvaleOptions:GetProfile()
+	self.frame = LibStub("AceGUI-3.0"):Create("OvaleFrame")
+	self.frame:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", profile.left, profile.top)
+	self:UpdateFrame()
 end

 function Ovale:OnDisable()
@@ -252,26 +233,27 @@ function Ovale:ToggleOptions()
 end

 function Ovale:UpdateVisibility()
-	if not OvaleOptions:GetProfile().display then
+	local profile = OvaleOptions:GetProfile()
+
+	if not profile.display then
 		self.frame:Hide()
 		return
 	end

 	self.frame:Show()
-
-	if OvaleOptions:GetApparence().hideVehicule and UnitHasVehicleUI("player") then
+	if profile.apparence.hideVehicule and UnitHasVehicleUI("player") then
 		self.frame:Hide()
 	end

-	if OvaleOptions:GetApparence().avecCible and not UnitExists("target") then
+	if profile.apparence.avecCible and not UnitExists("target") then
 		self.frame:Hide()
 	end

-	if OvaleOptions:GetApparence().enCombat and not Ovale.enCombat then
+	if profile.apparence.enCombat and not Ovale.enCombat then
 		self.frame:Hide()
 	end

-	if OvaleOptions:GetApparence().targetHostileOnly and (UnitIsDead("target") or not UnitCanAttack("player", "target")) then
+	if profile.apparence.targetHostileOnly and (UnitIsDead("target") or not UnitCanAttack("player", "target")) then
 		self.frame:Hide()
 	end
 end
diff --git a/OvaleData.lua b/OvaleData.lua
index e1f6e15..5710a23 100644
--- a/OvaleData.lua
+++ b/OvaleData.lua
@@ -22,7 +22,6 @@ local BOOKTYPE_SPELL, BOOKTYPE_PET = BOOKTYPE_SPELL, BOOKTYPE_PET

 --<public-static-properties>
 OvaleData.spellList = {}
-OvaleData.firstInit = false
 OvaleData.className = nil
 OvaleData.level = nil
 --allows to fill the player talent tables on first use
@@ -277,12 +276,19 @@ local rootSpellList = nil
 --</private-static-properties>

 --<public-static-methods>
-function OvaleData:OnEnable()
+function OvaleData:OnInitialize()
 	for k,v in pairs(self.power) do
 		self.powerType[v.id] = k
 	end
+end
+
+function OvaleData:OnEnable()
+	self.className = select(2, UnitClass("player"))
+	self.level = UnitLevel("player")

-	self:FirstInit()
+	self:RemplirListeTalents()
+	self:FillSpellList()
+
 	self:RegisterEvent("CHARACTER_POINTS_CHANGED")
 	self:RegisterEvent("GLYPH_ADDED")
 	self:RegisterEvent("GLYPH_DISABLED")
@@ -475,21 +481,6 @@ function OvaleData:RemplirListeTalents()
 	end
 end

-function OvaleData:FirstInit()
-	if self.firstInit then
-		return
-	end
-
-	self.firstInit = true
-
-	local playerClass, englishClass = UnitClass("player")
-	self.className = englishClass
-	self.level = UnitLevel("player")
-
-	self:RemplirListeTalents()
-	self:FillSpellList()
-end
-
 function OvaleData:GetTalentPoints(talentId)
 	if not self.listeTalentsRemplie then
 		self:RemplirListeTalents()
diff --git a/OvaleOptions.lua b/OvaleOptions.lua
index 6a38025..478517d 100644
--- a/OvaleOptions.lua
+++ b/OvaleOptions.lua
@@ -17,13 +17,12 @@ local strgmatch, strgsub, tostring = string.gmatch, string.gsub, tostring
 --</private-static-properties>

 --<public-static-properties>
-OvaleOptions.firstInit = false
 OvaleOptions.db = nil
 --</public-static-properties>

 --<private-static-properties>
-local AceConfig = LibStub("AceConfig-3.0");
-local AceConfigDialog = LibStub("AceConfigDialog-3.0");
+local AceConfig = LibStub("AceConfig-3.0")
+local AceConfigDialog = LibStub("AceConfigDialog-3.0")
 local L = LibStub("AceLocale-3.0"):GetLocale("Ovale")

 --GUI option
@@ -483,16 +482,6 @@ local options =

 --<public-static-methods>
 function OvaleOptions:OnInitialize()
-
-end
-
-function OvaleOptions:FirstInit()
-	if self.firstInit then
-		return
-	end
-
-	self.firstInit = true
-
 	local localizedClass, englishClass = UnitClass("player")
 	self.db = LibStub("AceDB-3.0"):New("OvaleDB",
 	{
@@ -537,26 +526,17 @@ function OvaleOptions:FirstInit()
 end

 function OvaleOptions:HandleProfileChanges()
-	if self.firstInit then
-		if (self.db.profile.code) then
-			Ovale:debugPrint("compile", "changing profiles")
-			Ovale.needCompile = true
-		end
+	if (self.db.profile.code) then
+		Ovale:debugPrint("compile", "changing profiles")
+		Ovale.needCompile = true
 	end
 end

-function OvaleOptions:OnEnable()
-	self:FirstInit()
-
-end
-
 function OvaleOptions:GetApparence()
-	self:FirstInit()
 	return self.db.profile.apparence
 end

 function OvaleOptions:GetProfile()
-	self:FirstInit()
 	return self.db.profile
 end