Update for FAF unitview.lua to allow for custom shield types

Post here if you want to help developing something for FAF.

Update for FAF unitview.lua to allow for custom shield types

Postby Resin_Smoker » 13 Mar 2015, 01:03

Old unitview lines 451-469
Spoiler: show
Code: Select all
            if info.shieldRatio > 0 and info.userUnit:GetBlueprint().Defense.Shield.ShieldMaxHealth then
                local ShieldMaxHealth = info.userUnit:GetBlueprint().Defense.Shield.ShieldMaxHealth
                controls.shieldText:Show()
                if info.userUnit:GetBlueprint().Defense.Shield.ShieldRegenRate then
                    controls.shieldText:SetText(string.format("%d / %d +%d/s", math.floor(ShieldMaxHealth*info.shieldRatio), info.userUnit:GetBlueprint().Defense.Shield.ShieldMaxHealth , info.userUnit:GetBlueprint().Defense.Shield.ShieldRegenRate))
                else
                    controls.shieldText:SetText(string.format("%d / %d", math.floor(ShieldMaxHealth*info.shieldRatio), info.userUnit:GetBlueprint().Defense.Shield.ShieldMaxHealth ))
                end
            end

            if info.shieldRatio > 0 and info.userUnit:GetBlueprint().Defense.Shield.ShieldMaxHealth == nil then
                local ShieldMaxHealth = info.userUnit:GetBlueprint().Enhancements[getEnh.GetEnhancements(info.entityId).Back].ShieldMaxHealth
                controls.shieldText:Show()
                if info.userUnit:GetBlueprint().Enhancements[getEnh.GetEnhancements(info.entityId).Back].ShieldRegenRate then
                    controls.shieldText:SetText(string.format("%d / %d +%d/s", math.floor(ShieldMaxHealth*info.shieldRatio), ShieldMaxHealth , info.userUnit:GetBlueprint().Enhancements[getEnh.GetEnhancements(info.entityId).Back].ShieldRegenRate))
                else
                    controls.shieldText:SetText(string.format("%d / %d", math.floor(ShieldMaxHealth*info.shieldRatio), ShieldMaxHealth ))
                end
            end


Replacement script
Spoiler: show
Code: Select all
if info.shieldRatio > 0 then
   local unitBp = info.userUnit:GetBlueprint()
   local ShieldMaxHealth, ShieldRegenRate
   if unitBp.Defense.Shield.ShieldMaxHealth > 0 then
      ShieldMaxHealth = unitBp.Defense.Shield.ShieldMaxHealth
      ShieldRegenRate = unitBp.Defense.Shield.ShieldRegenRate or 0
   elseif unitBp.Enhancements[getEnh.GetEnhancements(info.entityId).Back].ShieldMaxHealth > 0 then
      ShieldMaxHealth = unitBp.Enhancements[getEnh.GetEnhancements(info.entityId).Back].ShieldMaxHealth
      ShieldRegenRate = unitBp.Enhancements[getEnh.GetEnhancements(info.entityId).Back].ShieldRegenRate or 0
   elseif GetShieldParams(info.userUnit, 'MyShield') then
      local CustomShield = GetShieldParams(info.userUnit, 'MyShield')
      ShieldMaxHealth = CustomShield.ShieldMaxHealth or 0
      ShieldRegenRate = CustomShield.ShieldRegenRate or 0
   end
   if ShieldMaxHealth > 0 then
      controls.shieldText:Show()
      if ShieldRegenRate > 0 then
         controls.shieldText:SetText(string.format("%d / %d +%d/s", math.floor(ShieldMaxHealth*info.shieldRatio), ShieldMaxHealth, ShieldRegenRate))
      else
         controls.shieldText:SetText(string.format("%d / %d", math.floor(ShieldMaxHealth*info.shieldRatio), ShieldMaxHealth))
      end
   end
end


This is proposed to allow 4DC custom shield types to display without triggering a lua / ui error.

Resin
Resin_Smoker
Evaluator
 
Posts: 858
Joined: 14 Mar 2012, 17:58
Has liked: 54 times
Been liked: 106 times

Re: Update for FAF unitview.lua to allow for custom shield t

Postby ckitching » 13 Mar 2015, 01:53

Please file a pull request:
https://github.com/FAForever/fa
User avatar
ckitching
Avatar-of-War
 
Posts: 229
Joined: 03 Jan 2015, 12:51
Has liked: 2 times
Been liked: 69 times
FAF User Name: ckitching

Re: Update for FAF unitview.lua to allow for custom shield t

Postby Resin_Smoker » 13 Mar 2015, 02:12

ckitching wrote:Please file a pull request:
https://github.com/FAForever/fa


My prior attempts all met with either disapproval or someone got pissy with the formatting. Not going to bother with that gain so either take it or leave it... after all i not only fixed my problem but a divide by zero error in faf as well.

Resin
Resin_Smoker
Evaluator
 
Posts: 858
Joined: 14 Mar 2012, 17:58
Has liked: 54 times
Been liked: 106 times

Re: Update for FAF unitview.lua to allow for custom shield t

Postby Sheeo » 13 Mar 2015, 13:30

Resin_Smoker wrote:
ckitching wrote:Please file a pull request:
https://github.com/FAForever/fa


My prior attempts all met with either disapproval or someone got pissy with the formatting. Not going to bother with that gain so either take it or leave it... after all i not only fixed my problem but a divide by zero error in faf as well.

Resin


Which PR's have you submitted that you feel were badly reviewed?
Support FAF on patreon: https://www.patreon.com/faf?ty=h

Peek at our continued development on github: https://github.com/FAForever
Sheeo
Councillor - Administrative
 
Posts: 1038
Joined: 17 Dec 2013, 18:57
Has liked: 109 times
Been liked: 233 times
FAF User Name: Sheeo

Re: Update for FAF unitview.lua to allow for custom shield t

Postby Resin_Smoker » 13 Mar 2015, 17:21

Sheeo wrote:
Resin_Smoker wrote:
ckitching wrote:Please file a pull request:
https://github.com/FAForever/fa


My prior attempts all met with either disapproval or someone got pissy with the formatting. Not going to bother with that gain so either take it or leave it... after all i not only fixed my problem but a divide by zero error in faf as well.

Resin


Which PR's have you submitted that you feel were badly reviewed?


Wasnt talking about PR's but modding in general.
Resin_Smoker
Evaluator
 
Posts: 858
Joined: 14 Mar 2012, 17:58
Has liked: 54 times
Been liked: 106 times

Re: Update for FAF unitview.lua to allow for custom shield t

Postby Sheeo » 13 Mar 2015, 18:31

Resin_Smoker wrote:Wasnt talking about PR's but modding in general.


Okay well, let me know if there's any particular place where you feel we did something wrong.
Support FAF on patreon: https://www.patreon.com/faf?ty=h

Peek at our continued development on github: https://github.com/FAForever
Sheeo
Councillor - Administrative
 
Posts: 1038
Joined: 17 Dec 2013, 18:57
Has liked: 109 times
Been liked: 233 times
FAF User Name: Sheeo

Re: Update for FAF unitview.lua to allow for custom shield t

Postby Resin_Smoker » 14 Mar 2015, 11:15

I think I have come up with a way of doing what is necessary I should be able to send you the associated files Monday or Tuesday of next week.
Resin_Smoker
Evaluator
 
Posts: 858
Joined: 14 Mar 2012, 17:58
Has liked: 54 times
Been liked: 106 times


Return to Contributors

Who is online

Users browsing this forum: No registered users and 1 guest