08-31-16, 08:07 AM | #1 |
Pandemic mechanic util
Here I present util how to handle with Pandemic mechanic, since I was unable to find any solution.
With a help of #WoWUIDev, this is the Pandemic util I made for my indev Warlock addon (note that the following util uses global Tooltip, but it's just for clarity): Lua Code:
The idea behind this method is to read the spell duration directly from tooltip, using Tooltip.GetSpellDuration, ex.: Lua Code:
Lua Code:
Finally, I've added a handy Tooltip.GetUnitAuraPandemic that takes same arguments like UnitAura, and returns if Spell duration already benefits from Pandemic or not. Example: Before casting Siphon Life on target: Lua Code:
Lua Code:
Lua Code:
|
|
08-31-16, 08:22 AM | #2 |
Even setting aside the conceptual flaws (your code is way more complicated than it needs to be to do what it does) there are several basic issues with your code that make it pretty unsuitable as an example of how anything should be done.
Lua Code:
This creates a global variable named "Tooltip". You say you know this, yet you did it anyway. This is 100% bad and you should never do it for any reason. Doing it in something you're calling an example for others to use is even worse than doing it in code for yourself. Lua Code:
This creates a global variable named "Tooltip._tooltip" which, though slightly less bad than a global "Tooltip", is still not good. Global variables should always follow two simple rules: 1. It should be unique, so there is no chance of it colliding with another badly named or accidentally leaked global. At best, global variable collision will make an addon break. At worst, it will break the entire UI and make the game unplayable. 2. It should clearly identify the origin (ie. what addon created it) and purpose of the value it contains, so if it shows up in an error message, stack trace, /framestack tooltip, or other debugging context, there is some hope of the user figuring out where it's coming from. Lua Code:
Since this code is running in the main chunk of your addon, it's only ever executed once. There will never already be a "GetTooltip" method on your "Tooltip" object, so there's no point in checking for one before defining it. Lua Code:
Lua Code:
Same as above. No reason to check for things that you already know don't exist. Lua Code:
While this won't break anything in the context of scanning an aura tooltip, it's also not necessary in that context -- if tooltip:NumLines() is 3, then the tooltip has 3 lines with text; you don't need to verify that there's text -- and will break scanning in other types of tooltips, since item tooltips, for example, can have empty lines in the middle of them. Lua Code:
Writing this at the end of a function does absolutely nothing, and there's no reason to write it. It just takes up space for no reason.
__________________
Retired author of too many addons. Message me if you're interested in taking over one of my addons. Don’t message me about addon bugs or programming questions. Last edited by Phanx : 08-31-16 at 08:26 AM. |
|
08-31-16, 09:09 AM | #3 | ||||
It's just for clarity:
This means, that it is highly propable that a few addons will use sam utility. Then we can just use already existing one.
Clarity. Some people likes to see what function returns. However you're absolutelly free to remove it, if you only wish. |
|||||
08-31-16, 06:12 PM | #4 | ||
If you intend for the code to be copied and pasted into addon files, it should be entirely local, and not create any globals at all. There's not nearly enough overhead to justify putting this in the global namespace, especially with some of the worst global names possible. Again, this doesn't provide "clarity". It just adds clutter and confusion. When you post "example code" as a snippet in a forum post, you should be aware that 99.9999999999% of the people who are going to use it will not have a good understanding of the language or the API, and will just use the code as-is, probably without even reading it. Using bad coding paradigms and redundant/unnecessary/inefficient code is the opposite of helpful.
__________________
Retired author of too many addons. Message me if you're interested in taking over one of my addons. Don’t message me about addon bugs or programming questions. |
|||
08-31-16, 06:57 PM | #5 |
Oh ok then… move it to proper place then please. Even if it's a trash. Sorry for inconvenience. Just wanted to help.
Last edited by Benio : 08-31-16 at 07:26 PM. |
|
08-31-16, 08:32 PM | #6 |
WoWInterface » Developer Discussions » Tutorials & Other Helpful Info. » Pandemic mechanic util |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|