Quantcast

Make some more unnecessarily public variables private.

Johnny C. Lam [03-16-13 - 08:03]
Make some more unnecessarily public variables private.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@774 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
OvaleActionBar.lua
OvaleCompile.lua
OvaleEnemies.lua
OvaleSkada.lua
diff --git a/OvaleActionBar.lua b/OvaleActionBar.lua
index 6e262f7..13d658f 100644
--- a/OvaleActionBar.lua
+++ b/OvaleActionBar.lua
@@ -12,18 +12,18 @@ local _, Ovale = ...
 OvaleActionBar = Ovale:NewModule("OvaleActionBar", "AceEvent-3.0")

 --<private-static-properties>
+local tonumber = tonumber
+local wipe = wipe
+
 local GetActionInfo = GetActionInfo
 local GetActionText = GetActionText
-local tonumber = tonumber
---</private-static-properties>

---<public-static-properties>
 --key: spell name / value: action icon id
-OvaleActionBar.actionSort = {}
-OvaleActionBar.actionMacro = {}
-OvaleActionBar.actionObjet = {}
-OvaleActionBar.shortCut = {}
---</public-static-properties>
+actionSpell = {}
+actionMacro = {}
+actionItem = {}
+keybind = {}
+--</private-static-properties>

 --<public-static-methods>
 function OvaleActionBar:OnEnable()
@@ -54,26 +54,26 @@ end

 function OvaleActionBar:FillActionIndexes(event)
 	Ovale:debugPrint("action_bar", "Mapping buttons to spells/macros for " ..event)
-	self.actionSort = {}
-	self.actionMacro = {}
-	self.actionObjet = {}
-	self.shortCut = {}
+	wipe(actionSpell)
+	wipe(actionMacro)
+	wipe(actionItem)
+	wipe(keybind)
 	for i=1,120 do
 		self:FillActionIndex(i)
 	end
 end

 function OvaleActionBar:FillActionIndex(i)
-	self.shortCut[i] = self:FindKeyBinding(i)
+	keybind[i] = self:FindKeyBinding(i)
 	local actionText = GetActionText(i)
 	if actionText then
-		self.actionMacro[actionText] = i
+		actionMacro[actionText] = i
 	else
 		local type, spellId = GetActionInfo(i);
 		if (type=="spell") then
-			self.actionSort[spellId] = i
+			actionSpell[spellId] = i
 		elseif (type =="item") then
-			self.actionObjet[spellId] = i
+			actionItem[spellId] = i
 		end
 	end
 end
@@ -107,20 +107,20 @@ end

 -- Get the action id that match a spell id
 function OvaleActionBar:GetForSpell(spellId)
-	return self.actionSort[spellId]
+	return actionSpell[spellId]
 end

 -- Get the action id that match a macro id
 function OvaleActionBar:GetForMacro(macroId)
-	return self.actionMacro[macroId]
+	return actionMacro[macroId]
 end

 -- Get the action id that match an item id
 function OvaleActionBar:GetForItem(itemId)
-	return self.actionObjet[itemId]
+	return actionItem[itemId]
 end

 function OvaleActionBar:GetBinding(actionId)
-	return self.shortCut[actionId]
+	return keybind[actionId]
 end
 --</public-static-methods>
diff --git a/OvaleCompile.lua b/OvaleCompile.lua
index db8b39b..2d35cdb 100644
--- a/OvaleCompile.lua
+++ b/OvaleCompile.lua
@@ -19,6 +19,10 @@ local customFunctions = {}
 local unknownSpellNodes = {}
 local missingSpellList = {}

+-- Whether to trigger a script compilation if items or stances change.
+local compileOnItems = false
+local compileOnStances = false
+
 local ipairs, pairs, tonumber = ipairs, pairs, tonumber
 local strfind, strgmatch, strgsub = string.find, string.gmatch, string.gsub
 local strlen, strlower, strmatch, strsub = string.len, string.lower, string.match, string.sub
@@ -28,8 +32,6 @@ local tinsert = table.insert
 --<public-static-properties>
 --master nodes of the current script (one node for each icon)
 OvaleCompile.masterNodes = {}
-OvaleCompile.compileOnItems = false
-OvaleCompile.compileOnStances = false
 --</public-static-properties>

 --<private-static-methods>
@@ -89,7 +91,7 @@ local function TestConditions(paramList)
 		return false
 	end
 	if paramList.if_stance then
-		OvaleCompile.compileOnStances = true
+		compileOnStances = true
 		if not OvaleStance:IsStance(paramList.if_stance) then
 			return false
 		end
@@ -133,7 +135,7 @@ local function TestConditions(paramList)
 	end
 	if paramList.itemset and paramList.itemcount then
 		local equippedCount = OvaleEquipement:GetArmorSetCount(paramList.itemset)
-		OvaleCompile.compileOnItems = true
+		compileOnItems = true
 		if equippedCount < paramList.itemcount then
 			return false
 		end
@@ -593,8 +595,8 @@ local function CompileDeclarations(text)
 end

 local function CompileScript(text)
-	OvaleCompile.compileOnItems = false
-	OvaleCompile.compileOnStances = false
+	compileOnItems = false
+	compileOnStances = false
 	Ovale.bug = false

 	wipe(node)
@@ -667,14 +669,14 @@ function OvaleCompile:EventHandler(event)
 end

 function OvaleCompile:Ovale_EquipmentChanged(event)
-	if OvaleCompile.compileOnItems then
+	if compileOnItems then
 		self:EventHandler(event)
 	end
 	Ovale.refreshNeeded.player = true
 end

 function OvaleCompile:Ovale_StanceChanged(event)
-	if OvaleCompile.compileOnStances then
+	if compileOnStances then
 		self:EventHandler(event)
 	end
 	Ovale.refreshNeeded.player = true
diff --git a/OvaleEnemies.lua b/OvaleEnemies.lua
index fbf0f00..8ac6eca 100644
--- a/OvaleEnemies.lua
+++ b/OvaleEnemies.lua
@@ -14,17 +14,16 @@ OvaleEnemies = Ovale:NewModule("OvaleEnemies", "AceEvent-3.0")

 --<private-static-properties>
 local bit_band, pairs, select, tostring = bit.band, pairs, select, tostring
+local wipe = wipe
+
 local COMBATLOG_OBJECT_AFFILIATION_OUTSIDER = COMBATLOG_OBJECT_AFFILIATION_OUTSIDER
 local COMBATLOG_OBJECT_REACTION_HOSTILE = COMBATLOG_OBJECT_REACTION_HOSTILE
---</private-static-properties>

---<public-static-properties>
-OvaleEnemies.numberOfEnemies = 0
-OvaleEnemies.enemies = {}
---</public-static-properties>
+numberOfEnemies = 0
+enemies = {}
+--</private-static-properties>

 --<public-static-methods>
--- Events
 function OvaleEnemies:OnEnable()
 	self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
 	self:RegisterEvent("PLAYER_REGEN_DISABLED")
@@ -39,43 +38,43 @@ function OvaleEnemies:COMBAT_LOG_EVENT_UNFILTERED(event, ...)
 	local time, event, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags = select(1, ...)

 	if event == "UNIT_DIED" then
-		for k,v in pairs(self.enemies) do
+		for k,v in pairs(enemies) do
 			if k==destGUID then
-				self.enemies[v] = nil
-				self.numberOfEnemies = self.numberOfEnemies - 1
+				enemies[v] = nil
+				numberOfEnemies = numberOfEnemies - 1
 				Ovale.refreshNeeded["player"] = true
 				Ovale:debugPrint("enemy", "enemy die")
 			end
 		end
-	elseif sourceFlags and not self.enemies[sourceGUID] and bit_band(sourceFlags, COMBATLOG_OBJECT_REACTION_HOSTILE)>0
+	elseif sourceFlags and not enemies[sourceGUID] and bit_band(sourceFlags, COMBATLOG_OBJECT_REACTION_HOSTILE)>0
 				and bit_band(sourceFlags, COMBATLOG_OBJECT_AFFILIATION_OUTSIDER) > 0 and
 			destFlags and bit_band(destFlags, COMBATLOG_OBJECT_AFFILIATION_OUTSIDER) == 0 then
-		self.enemies[sourceGUID] = true
+		enemies[sourceGUID] = true
 		Ovale:debugPrint("enemy", "new enemy source=" .. tostring(sourceName))
-		self.numberOfEnemies = self.numberOfEnemies + 1
+		numberOfEnemies = numberOfEnemies + 1
 		Ovale.refreshNeeded["player"] = true
-	elseif destGUID and not self.enemies[destGUID] and bit_band(destFlags, COMBATLOG_OBJECT_REACTION_HOSTILE)>0
+	elseif destGUID and not enemies[destGUID] and bit_band(destFlags, COMBATLOG_OBJECT_REACTION_HOSTILE)>0
 				and bit_band(destFlags, COMBATLOG_OBJECT_AFFILIATION_OUTSIDER) > 0 and
 			sourceFlags and bit_band(sourceFlags, COMBATLOG_OBJECT_AFFILIATION_OUTSIDER) == 0 then
-		self.enemies[destGUID] = true
+		enemies[destGUID] = true
 		Ovale:debugPrint("enemy", "new enemy dest=".. tostring(destName))
-		self.numberOfEnemies = self.numberOfEnemies + 1
+		numberOfEnemies = numberOfEnemies + 1
 		Ovale.refreshNeeded["player"] = true
 	end
 end

 function OvaleEnemies:PLAYER_REGEN_DISABLED()
-	if self.numberOfEnemies then
-		self.numberOfEnemies = 0
-		self.enemies = {}
+	if numberOfEnemies then
+		numberOfEnemies = 0
+		wipe(enemies)
 	end
 end

 function OvaleEnemies:GetNumberOfEnemies()
-	if not self.numberOfEnemies then
-		self.numberOfEnemies = 0
+	if not numberOfEnemies then
+		numberOfEnemies = 0
 	end
-	return self.numberOfEnemies
+	return numberOfEnemies
 end
 --</public-static-methods>

diff --git a/OvaleSkada.lua b/OvaleSkada.lua
index 72fa339..9a309f0 100644
--- a/OvaleSkada.lua
+++ b/OvaleSkada.lua
@@ -12,17 +12,13 @@ OvaleSkada = Ovale:NewModule("OvaleSkada")

 --<private-static-properties>
 local Skada	= LibStub("AceAddon-3.0"):GetAddon("Skada", true)
-local SkadaModule = {}
+local SkadaModule = Skada and Skada:NewModule("Ovale Spell Priority", SkadaModule) or { noSkada = true }

 local ipairs = ipairs
 local math = math
 local tostring = tostring
 --</private-static-properties>

---<public-static-properties>
-OvaleSkada.module = nil
---</public-static-properties>
-
 --<private-static-methods>
 local function getValue(set)
 	if set.ovaleMax and set.ovaleMax > 0 then
@@ -31,7 +27,9 @@ local function getValue(set)
 		return nil
 	end
 end
+--</private-static-methods>

+--<public-static-methods>
 function SkadaModule:OnEnable()
 	self.metadata = { showspots = true }
 	Skada:AddMode(self)
@@ -92,35 +90,30 @@ function SkadaModule:GetSetSummary(set)
 	return getValue(set)
 end

--- Initialize OvaleSkada.module after SkadaModule prototype has been fully defined.
-OvaleSkada.module = Skada and Skada:NewModule("Ovale Spell Priority", SkadaModule) or nil
---</private-static-methods>
-
---<public-static-methods>
 function OvaleSkada:OnEnable()
-	if not Skada then return end
+	if SkadaModule.noSkada then return end
 	Ovale:AddDamageMeter("OvaleSkada", self)
-	if not self.module:IsEnabled() then
-		self.module:Enable()
+	if not SkadaModule:IsEnabled() then
+		SkadaModule:Enable()
 	end
 end

 function OvaleSkada:OnDisable()
-	if not Skada then return end
+	if SkadaModule.noSkada then return end
 	Ovale:RemoveDamageMeter("OvaleSkada")
-	if self.module:IsEnabled() then
-		self.module:Disable()
+	if SkadaModule:IsEnabled() then
+		SkadaModule:Disable()
 	end
 end

 function OvaleSkada:SendScoreToDamageMeter(name, guid, scored, scoreMax)
-	if not Skada then return end
+	if SkadaModule.noSkada then return end
 	if not guid or not Skada.current or not Skada.total then return end

 	local player = Skada:get_player(Skada.current, guid, nil)
 	if not player then return end

-	self.module:AddPlayerAttributes(player)
+	SkadaModule:AddPlayerAttributes(player)
 	player.ovale = player.ovale + scored
 	player.ovaleMax = player.ovaleMax + scoreMax
 	player = Skada:get_player(Skada.total, guid, nil)