View Single Post
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