Quantcast
WoWInterface - View Single Post - Code optimization and issue with hyperlinks in chat
View Single Post
11-06-18, 06:11 PM   #12
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 507
Lua Code:
  1. local function hexColorNames(chatMessage, modChatColor)
  2.     local words,coloredMessage,s,p,class = {strsplit(' ', chatMessage)},''
  3.     local combinedName = UnitName('player')..'-'..GetRealmName()
  4.     local _, playerClass = UnitClass('player')
  5.     for k, w in ipairs(words) do
  6.         s,p = false,false
  7.         if w ~= 'player' and w ~= 'target' and UnitIsPlayer(w) then
  8.             _, class = UnitClass(w)
  9.             s = true
  10.         elseif combinedName:lower() == w:lower() then
  11.             p = true
  12.         end
  13.         w = (s or p) and '|c'..RAID_CLASS_COLORS[p and playerClass or class].colorStr..w..modChatColor or w
  14.         coloredMessage = coloredMessage == '' and w or coloredMessage..' '..w
  15.     end
  16.     return coloredMessage
  17. end


Since you're iterating through the message word-for-word, just rebuild it word-for-word instead of using gsub. I also went with boolean switches and dropped some other stuff like UnitName being redundant since UnitIsPlayer is fine by itself.

I did not test this.
  Reply With Quote