Quantcast

Don't use an unnessisary table

Adrian L Lange [06-27-10 - 04:27]
Don't use an unnessisary table
Filename
oUF_P3lim.lua
diff --git a/oUF_P3lim.lua b/oUF_P3lim.lua
index 052b2e8..878a037 100644
--- a/oUF_P3lim.lua
+++ b/oUF_P3lim.lua
@@ -21,63 +21,62 @@ local function ShortenValue(value)
 	end
 end

-for name, func in pairs({
-	['threat'] = function(unit)
-		local tanking, status, percent = UnitDetailedThreatSituation('player', 'target')
-		if(percent and percent > 0) then
-			return ('%s%d%%|r'):format(Hex(GetThreatStatusColor(status)), percent)
-		end
-	end,
-	['health'] = function(unit)
-		local min, max = UnitHealth(unit), UnitHealthMax(unit)
-		local status = not UnitIsConnected(unit) and 'Offline' or UnitIsGhost(unit) and 'Ghost' or UnitIsDead(unit) and 'Dead'
-
-		if(status) then
-			return status
-		elseif(unit == 'target' and UnitCanAttack('player', unit)) then
-			return ('%s (%d|cff0090ff%%|r)'):format(ShortenValue(min), min / max * 100)
-		elseif(unit == 'player' and min ~= max) then
-			return ('|cffff8080%d|r %d|cff0090ff%%|r'):format(min - max, min / max * 100)
-		elseif(min ~= max) then
-			return ('%s |cff0090ff/|r %s'):format(ShortenValue(min), ShortenValue(max))
-		else
-			return max
-		end
-	end,
-	['power'] = function(unit)
-		local power = UnitPower(unit)
-		if(power > 0 and not UnitIsDeadOrGhost(unit)) then
-			local _, type = UnitPowerType(unit)
-			local colors = _COLORS.power
-			return ('%s%d|r'):format(Hex(colors[type] or colors['RUNES']), power)
-		end
-	end,
-	['druid'] = function(unit)
-		local min, max = UnitPower(unit, 0), UnitPowerMax(unit, 0)
-		if(UnitPowerType(unit) ~= 0 and min ~= max) then
-			return ('|cff0090ff%d%%|r'):format(min / max * 100)
-		end
-	end,
-	['name'] = function(unit)
-		local reaction = UnitReaction(unit, 'player')
-
-		local r, g, b = 1, 1, 1
-		if((UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit)) or not UnitIsConnected(unit)) then
-			r, g, b = 3/5, 3/5, 3/5
-		elseif(not UnitIsPlayer(unit) and reaction) then
-			r, g, b = unpack(_COLORS.reaction[reaction])
-		elseif(UnitFactionGroup(unit) and UnitIsEnemy(unit, 'player') and UnitIsPVP(unit)) then
-			r, g, b = 1, 0, 0
-		end
+oUF.TagEvents['p3lim:threat'] = 'UNIT_THREAT_LIST_UPDATE'
+oUF.Tags['p3lim:threat'] = function(unit)
+	local tanking, status, percent = UnitDetailedThreatSituation('player', 'target')
+	if(percent and percent > 0) then
+		return ('%s%d%%|r'):format(Hex(GetThreatStatusColor(status)), percent)
+	end
+end
+
+oUF.Tags['p3lim:health'] = function(unit)
+	local min, max = UnitHealth(unit), UnitHealthMax(unit)
+	local status = not UnitIsConnected(unit) and 'Offline' or UnitIsGhost(unit) and 'Ghost' or UnitIsDead(unit) and 'Dead'
+
+	if(status) then
+		return status
+	elseif(unit == 'target' and UnitCanAttack('player', unit)) then
+		return ('%s (%d|cff0090ff%%|r)'):format(ShortenValue(min), min / max * 100)
+	elseif(unit == 'player' and min ~= max) then
+		return ('|cffff8080%d|r %d|cff0090ff%%|r'):format(min - max, min / max * 100)
+	elseif(min ~= max) then
+		return ('%s |cff0090ff/|r %s'):format(ShortenValue(min), ShortenValue(max))
+	else
+		return max
+	end
+end
+
+oUF.Tags['p3lim:power'] = function(unit)
+	local power = UnitPower(unit)
+	if(power > 0 and not UnitIsDeadOrGhost(unit)) then
+		local _, type = UnitPowerType(unit)
+		local colors = _COLORS.power
+		return ('%s%d|r'):format(Hex(colors[type] or colors['RUNES']), power)
+	end
+end

-		return ('%s%s|r'):format(Hex(r, g, b), UnitName(unit))
+oUF.Tags['p3lim:druid'] = function(unit)
+	local min, max = UnitPower(unit, 0), UnitPowerMax(unit, 0)
+	if(UnitPowerType(unit) ~= 0 and min ~= max) then
+		return ('|cff0090ff%d%%|r'):format(min / max * 100)
 	end
-}) do
-	oUF.Tags['p3lim:'..name] = func
 end

 oUF.TagEvents['p3lim:name'] = 'UNIT_NAME_UPDATE UNIT_REACTION UNIT_FACTION'
-oUF.TagEvents['p3lim:threat'] = 'UNIT_THREAT_LIST_UPDATE'
+oUF.Tags['p3lim:name'] = function(unit)
+	local reaction = UnitReaction(unit, 'player')
+
+	local r, g, b = 1, 1, 1
+	if((UnitIsTapped(unit) and not UnitIsTappedByPlayer(unit)) or not UnitIsConnected(unit)) then
+		r, g, b = 3/5, 3/5, 3/5
+	elseif(not UnitIsPlayer(unit) and reaction) then
+		r, g, b = unpack(_COLORS.reaction[reaction])
+	elseif(UnitFactionGroup(unit) and UnitIsEnemy(unit, 'player') and UnitIsPVP(unit)) then
+		r, g, b = 1, 0, 0
+	end
+
+	return ('%s%s|r'):format(Hex(r, g, b), UnitName(unit))
+end

 local function SpawnMenu(self)
 	ToggleDropDownMenu(1, nil, _G[string.gsub(self.unit, '^.', string.upper)..'FrameDropDown'], 'cursor')