Thread Tools Display Modes
01-15-18, 04:02 PM   #1
JDoubleU00
A Firelord
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 463
Reusing Blizzard Code

I'm curious how one reuses Blizzard's code in their addon. Is it through hooksecure or simply using the code as a base and they add their own code?
__________________
Author of JWExpBar and JWRepBar.
  Reply With Quote
01-15-18, 05:36 PM   #2
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
Can you be more specific? It entirely depends on what code, what it does, where it is, and what it affects. For example, I wouldn't "reuse" dropdown menu code because part of it causes taints when addons use it directly.
  Reply With Quote
01-16-18, 05:28 PM   #3
JDoubleU00
A Firelord
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 463
Originally Posted by Kanegasi View Post
Can you be more specific? It entirely depends on what code, what it does, where it is, and what it affects. For example, I wouldn't "reuse" dropdown menu code because part of it causes taints when addons use it directly.
Sorry, I should have given an example. Dominoes, AFAIK, reuses action bar code,

Reuse as much standard blizzard action button code as possible.
I wanted to see how much I could do while maintaining compatibility with the standard action button code.
My memory is failing me, but I thought some nameplates, tool tips and unit frame addons try to do the same.

I hope this helps.
__________________
Author of JWExpBar and JWRepBar.
  Reply With Quote
01-16-18, 05:56 PM   #4
Ammako
A Frostmaul Preserver
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 256
Ultimately, people do both ways. A better question would be, what are the advantages and disadvantages of each method?

(This is more of a rhetorical question on my part, btw)
  Reply With Quote
01-16-18, 05:58 PM   #5
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
In that case, it's more of a "don't reinvent the wheel" kind of thing. If an addon wants to replicate something Blizzard did, completely copying it is the best thing to do, as long as you change any globals in the reused code so it doesn't interfere with Blizzard's original code.

My second addon, Decliner, started almost three years ago by plopping in parts of code from addons I knew did what I wanted and I went from there. Barely any of the code is recognizable from what I started with.

My original reply was directed more at using active code ingame, especially code that has even one part protected.
  Reply With Quote
01-17-18, 04:15 AM   #6
Kakjens
A Cliff Giant
Join Date: Apr 2017
Posts: 75
As mentioned above, reuse of code is the fastest way to get things done. Is Blizzard's code good - maybe. Is Blizzard's code the best - definitely not. See, for example, how they implemented PaperDollFrame_SetVersatility:
Lua Code:
  1. function PaperDollFrame_SetVersatility(statFrame, unit)
  2.     if ( unit ~= "player" ) then
  3.         statFrame:Hide();
  4.         return;
  5.     end
  6.  
  7.     local versatility = GetCombatRating(CR_VERSATILITY_DAMAGE_DONE);
  8.     local versatilityDamageBonus = GetCombatRatingBonus(CR_VERSATILITY_DAMAGE_DONE) + GetVersatilityBonus(CR_VERSATILITY_DAMAGE_DONE);
  9.     local versatilityDamageTakenReduction = GetCombatRatingBonus(CR_VERSATILITY_DAMAGE_TAKEN) + GetVersatilityBonus(CR_VERSATILITY_DAMAGE_TAKEN);
  10.     PaperDollFrame_SetLabelAndText(statFrame, STAT_VERSATILITY, versatilityDamageBonus, true, versatilityDamageBonus);
  11.     statFrame.tooltip = HIGHLIGHT_FONT_COLOR_CODE .. format(VERSATILITY_TOOLTIP_FORMAT, STAT_VERSATILITY, versatilityDamageBonus, versatilityDamageTakenReduction) .. FONT_COLOR_CODE_CLOSE;
  12.  
  13.     statFrame.tooltip2 = format(CR_VERSATILITY_TOOLTIP, versatilityDamageBonus, versatilityDamageTakenReduction, BreakUpLargeNumbers(versatility), versatilityDamageBonus, versatilityDamageTakenReduction);
  14.  
  15.     statFrame:Show();
  16. end
A global CR_VERSATILITY_DAMAGE_DONE is used 3 times without being localized, CR_VERSATILITY_DAMAGE_TAKEN, STAT_VERSATILITY - 2 times. Global functions GetCombatRatingBonus and GetVersatilityBonus are used twice. Variable versatility is used only once, so instead of it the formula of it's calculation needs to be plugged in tooltip2.
Also, sometimes modifications needed for the code to behave the way you want are so great that one can start to wonder whether complete rewrite would be faster.
So can the Blizzard's code be reused - of course it can. But whether it should be reused depends by case.
  Reply With Quote
01-17-18, 09:52 AM   #7
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Whether the code is good or not is closely tied to its age. A lot of the older code base is mostly unchanged and doesn't use things that came with Lua 5.1. There's also a lot of global lookup going on. I replicated the entire code for displaying the contents of quest reward frames and managed to cut the line count in half due to how inefficient it is. As features get added, it's not uncommon that they're spaghetti coded on top of old code, which makes things worse.

There's also a ton of weird stuff that's floating about because different developers have come and gone. For example, there's an entire OOP class abstraction layer which only seems to be used for tutorials.

Reusing code with side effects (affecting things outside the scope of the function) also has the consequence of spreading taint, so you should be careful anytime you want to reuse code.
__________________

Last edited by MunkDev : 01-17-18 at 09:58 AM.
  Reply With Quote
01-17-18, 10:20 AM   #8
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
This is what I like to do in many of my addons.

rButtonTemplate allows you to hook default aura, item and action buttons.
rActionBar allows customization of the default Blizzard actionbar.
Some goes for the minimap and many other things. The Blizzard code is just fine most of the time if you "bend" it a little.

The only thing that I cannot stand are unitframes/nameplates. I like to scrape them completly and use oUF.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
  Reply With Quote
01-17-18, 11:42 AM   #9
Ammako
A Frostmaul Preserver
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 256
I'd like to scrap the personal resource display and separate it from the nameplate system. It's such a clusterfuck.
  Reply With Quote
01-17-18, 05:07 PM   #10
JDoubleU00
A Firelord
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 463
Thanks for all the replies, it makes a lot more sense now. I thought in the past that Blizzard had looked at addons and sort of implemented their functionality in game. Have they ever hired an addon author? It seems that they could fix some of the code issues by working with authors and adopting their code. Of course that could mean one less addon, but I'd be thrilled if they ever used an addon that I wrote.
__________________
Author of JWExpBar and JWRepBar.
  Reply With Quote
01-18-18, 05:02 PM   #11
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
There is an IRC where wow devs and addon developers hang out. If there is a real bug with addon support / WoW API it gets fixed pretty quickly most of the time.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Reusing Blizzard Code

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off