Quantcast

Let modules flag themselves as ready for other modules to use.

Johnny C. Lam [05-14-14 - 00:37]
Let modules flag themselves as ready for other modules to use.

Check that certain modules are ready before allowing compiling the script.
This fixes ticket 359.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1435 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
Ovale.lua
OvaleCompile.lua
OvaleEquipement.lua
OvaleSpellBook.lua
OvaleStance.lua
diff --git a/Ovale.lua b/Ovale.lua
index 7bd1cb1..9eec4bf 100644
--- a/Ovale.lua
+++ b/Ovale.lua
@@ -117,6 +117,14 @@ function Ovale:PLAYER_REGEN_DISABLED()
 	self:UpdateVisibility()
 end

+function Ovale:IsPreloaded(moduleList)
+	local preloaded = true
+	for _, moduleName in pairs(moduleList) do
+		preloaded = preloaded and self[moduleName].ready
+	end
+	return preloaded
+end
+
 function Ovale:ToggleOptions()
 	self.frame:ToggleOptions()
 end
diff --git a/OvaleCompile.lua b/OvaleCompile.lua
index 6ae59f4..8b721f3 100644
--- a/OvaleCompile.lua
+++ b/OvaleCompile.lua
@@ -56,6 +56,10 @@ local self_functionCalls = {}
 local self_compileOnItems = false
 local self_compileOnStances = false

+-- This module needs the information in other modules to be preloaded and ready for use.
+local self_canCompile = false
+local self_requirePreload = { "OvaleEquipement", "OvaleSpellBook", "OvaleStance" }
+
 -- Current age of compilation state.
 local self_serial = 0
 -- Number of times the script has been compiled.
@@ -929,17 +933,20 @@ function OvaleCompile:EventHandler(event)
 end

 function OvaleCompile:Compile()
-	local profile = OvaleOptions:GetProfile()
-	local source = profile.source
-	local code
-	if source and OvaleScripts.script[source] then
-		code = OvaleScripts.script[source].code
-	else
-		code = ""
+	self_canCompile = self_canCompile or Ovale:IsPreloaded(self_requirePreload)
+	if self_canCompile then
+		local profile = OvaleOptions:GetProfile()
+		local source = profile.source
+		local code
+		if source and OvaleScripts.script[source] then
+			code = OvaleScripts.script[source].code
+		else
+			code = ""
+		end
+		CompileScript(code)
+		self_compileCount = self_compileCount + 1
+		Ovale:UpdateFrame()
 	end
-	CompileScript(code)
-	self_compileCount = self_compileCount + 1
-	Ovale:UpdateFrame()
 end

 function OvaleCompile:GetMasterNodes()
diff --git a/OvaleEquipement.lua b/OvaleEquipement.lua
index 146e7ee..aa4e8bb 100644
--- a/OvaleEquipement.lua
+++ b/OvaleEquipement.lua
@@ -1105,6 +1105,8 @@ local OVALE_NORMALIZED_WEAPON_SPEED = {
 --</private-static-properties>

 --<public-static-properties>
+-- Whether the equipment information is ready for use by other modules.
+OvaleEquipement.ready = false
 -- Item IDs of equipped items, indexed by slot ID.
 OvaleEquipement.equippedItems = {}
 -- Item levels of equipped items, indexed by slot ID.
@@ -1324,6 +1326,7 @@ function OvaleEquipement:UpdateEquippedItems()
 		self:UpdateArmorSetCount()
 		self:SendMessage("Ovale_EquipmentChanged")
 	end
+	self.ready = true
 end

 function OvaleEquipement:UpdateEquippedItemLevels()
diff --git a/OvaleSpellBook.lua b/OvaleSpellBook.lua
index aa5227c..54b99d8 100644
--- a/OvaleSpellBook.lua
+++ b/OvaleSpellBook.lua
@@ -40,6 +40,8 @@ local BOOKTYPE_SPELL = BOOKTYPE_SPELL
 --</private-static-properties>

 --<public-static-properties>
+-- Whether the spellbook information is ready for use by other modules.
+OvaleSpellBook.ready = false
 -- self.spell[spellId] = spellName
 OvaleSpellBook.spell = {}
 -- self.talent[talentId] = talentName
@@ -111,6 +113,7 @@ function OvaleSpellBook:Update()
 	self:UpdateTalents()
 	self:UpdateGlyphs()
 	self:UpdateSpells()
+	self.ready = true
 end

 -- Update the player's talents by scanning the talent tab for the active specialization.
diff --git a/OvaleStance.lua b/OvaleStance.lua
index ac9339f..d27dee2 100644
--- a/OvaleStance.lua
+++ b/OvaleStance.lua
@@ -67,6 +67,8 @@ local OVALE_SPELLID_TO_STANCE = {
 --</private-static-properties>

 --<public-static-properties>
+-- Whether the stance information is ready for use by other modules.
+OvaleStance.ready = false
 -- List of available stances, populated by CreateStanceList()
 OvaleStance.stanceList = {}
 -- Player's current stance.
@@ -167,5 +169,6 @@ end
 function OvaleStance:UpdateStances()
 	self:CreateStanceList()
 	self:ShapeshiftEventHandler()
+	self.ready = true
 end
 --</public-static-methods>