WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Chat Addon Optimization (https://www.wowinterface.com/forums/showthread.php?t=57266)

Terenna 07-07-19 12:06 AM

Chat Addon Optimization
 
Good evening all. I have written a pretty extensively tested chat addon that does a lot of cool things. It adds a lot of convenient hyperlinks, and colors player names in chat, even with punctuation. It works quite well. There are no Lua errors, and everything works as I've written it. Before I begin working on modifying the "appearance" of the chat frame, I wanted to ensure that the "backend" of the chat was reasonably if not fully optimized.

The code is ~600 lines. I have documented it pretty extensively, in some cases line by line. https://pastebin.com/7sm5AnUp

Any suggestions are obviously appreciated.

Seerah 07-07-19 12:28 PM

All these table.inserts are totally unnecessary. Not only is it both a global and table lookup, but it's also a function call. At least this section of code only runs once, but it is much quicker and simpler to read if you just fill in the table when you create it.
Lua Code:
  1. local eventTable = {
  2.      'CHAT_MSG_SAY',
  3.      'CHAT_MSG_YELL',
  4.      --etc.
  5. }

Not a big deal, but why do you have two separate frames? (f and g) You only have one event registered to g, so you could just condense them. This is the whole reason why the event parameter is passed through to the function.
Lua Code:
  1. f:SetScript("OnEvent", function(self, event, ...)
  2.      if event == "UPDATE_CHAT_COLOR" then
  3.           --do this stuff here
  4.      else
  5.           --do the other stuff
  6.      end
  7. end)

Why are you calling ChatFrame_AddMessageEventFilter for all of these events and hiding all of these messages from chat? By doing this and then using your commonChatEventHandler and only adding a message to ChatFrame1, you are overriding any user's preferred location of displaying messages.

Terenna 07-07-19 01:00 PM

Seerah, Thank you for reading and replying! Noted on eventTable and frames.

I am filtering all these events as it seemed to be the only way to modify the chat without tainting. Many chat addons don't use the filter strategy, and instead modify the AddMessage() function, which I've found taints the communities tab. If I wanted to colorize names in chat, or add hyperlinks to certain chat events that don't hyperlink the actor (like looting), I could rewrite the AddMessage() function and cause taint, or I could perform the method (as tedious as it may be) I used. As far as I can figure out, there isn't a third option, but I'm more than willing to get new information and rewrite the code.

As for the downside of always adding to ChatFrame1, yes, this is absolutely a pitfall. I haven't figured out a way to make it so the chat could show up in different tabs as the user wants quite yet, but as I keep all of my chat in the main window, it's worked for now.

sylvanaar 08-28-19 07:15 PM

It is ok to taint the chat frame. But kudos to you for spending extra time trying not to.


All times are GMT -6. The time now is 09:08 AM.

vBulletin © 2019, Jelsoft Enterprises Ltd
© 2004 - 2019 MMOUI