Quantcast
WoWInterface - View Single Post - gsub'ing |t and stuff
View Single Post
11-25-10, 04:29 AM   #2
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
Without knowing what you're trying to extract, and not wanting to reverse-engineer it from the gsub() mess, the only thing I can offer is a simplification of your if-nesting mess:

Code:
local lastricon = 1

function addon:AddRaidIcon(self)
	if not addon.settings.showRaidIcon then
		return
	end
	local name, unit = self:GetUnit()

	if not unit then
		return
	end
	local text = GameTooltipTextLeft1:GetText()

	if not text then
		return
	end
	local ricon = GetRaidTargetIndex(unit)

	if not ricon then
		return
	end

	if lastricon ~= 1 then
		text = gsub(text, "|T", "")
		text = gsub(text, lastricon.."::", "")
		text = gsub(text, addon.settings.tooltipIconSize / 10, "")
		text = gsub(text, "Interface", "")
		text = gsub(text, "TargetingFrame", "")
		text = gsub(text, "\\", "")
		text = gsub(text, "UI", "")
		text = gsub(text, "RaidTargetingIcon", "")
		text = gsub(text, "-", "")
		text = gsub(text, "_", "")
		text = gsub(text, " ", "", 1)
	end
	lastricon = ricon

	if not text:find(ricon) then
		GameTooltipTextLeft1:SetText(("|t%s:%s|t %s"):format(ICON_LIST[ricon], addon.settings.tooltipIconSize / 10, text))
		GameTooltip:Show()
	end

	if not ricon then
		if lastricon ~= 1 then 
			text = gsub(text, "|T", "")
			text = gsub(text, lastricon.."::", "")
			text = gsub(text, addon.settings.tooltipIconSize / 10, "")
			text = gsub(text, "Interface", "")
			text = gsub(text, "TargetingFrame", "")
			text = gsub(text, "\\", "")
			text = gsub(text, "UI", "")
			text = gsub(text, "RaidTargetingIcon", "")
			text = gsub(text, "-", "")
			text = gsub(text, "_", "")
			text = gsub(text, " ", "", 1)
			GameTooltipTextLeft1:SetText(("%s"):format(text))
			lastricon = 1
			GameTooltip:Show()
		end
	end
end
The only other change I made was getting rid of "or ricon == nil", since "not ricon" already achieves this. I'm also unsure of the overall logic, since you check for something, show the GameTooltip, then check for something else and show GameTooltip again.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote