mirror of
https://github.com/PorktoberRevolution/ReStocked
synced 2024-09-01 17:34:42 +00:00
Fix NREs in ISRU code
* check if renderer list is null on HeatEffects plugin before lateupdate * correctly use reversed deploy animation for retracting ISRUs when retract animation is not present
This commit is contained in:
parent
d9f1454524
commit
8467b4fcae
Binary file not shown.
@ -121,6 +121,9 @@ namespace Restock
|
|||||||
public void LateUpdate()
|
public void LateUpdate()
|
||||||
{
|
{
|
||||||
if (!HighLogic.LoadedSceneIsFlight) return;
|
if (!HighLogic.LoadedSceneIsFlight) return;
|
||||||
|
if (renderers == null) return;
|
||||||
|
//when switching to the flight scene LateUpdate gets called AFTER OnLoad for some reason
|
||||||
|
// so renderers should hopefully only be null for one frame
|
||||||
|
|
||||||
if (enableHeatEmissive)
|
if (enableHeatEmissive)
|
||||||
{
|
{
|
||||||
@ -148,7 +151,6 @@ namespace Restock
|
|||||||
if (disableBlackbody)
|
if (disableBlackbody)
|
||||||
{
|
{
|
||||||
_propertyBlock.SetColor(_shaderBlackbodyID, Color.black);
|
_propertyBlock.SetColor(_shaderBlackbodyID, Color.black);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < renderers.Count; i++)
|
for (var i = 0; i < renderers.Count; i++)
|
||||||
|
@ -31,7 +31,7 @@ namespace Restock
|
|||||||
// should the module wait until a current looping animation completes before changing state?
|
// should the module wait until a current looping animation completes before changing state?
|
||||||
[KSPField] public bool waitForComplete = false;
|
[KSPField] public bool waitForComplete = false;
|
||||||
|
|
||||||
public bool IsDeployed => (CurrentState == State.InactiveWaiting ||
|
public bool IsDeployed => (CurrentState == State.InactiveWaiting ||
|
||||||
CurrentState == State.Active ||
|
CurrentState == State.Active ||
|
||||||
CurrentState == State.Deploying);
|
CurrentState == State.Deploying);
|
||||||
|
|
||||||
@ -68,14 +68,49 @@ namespace Restock
|
|||||||
_activeAnimationPresent = (activeAnimationName != string.Empty);
|
_activeAnimationPresent = (activeAnimationName != string.Empty);
|
||||||
_inactiveAnimationPresent = (inactiveAnimationName != string.Empty);
|
_inactiveAnimationPresent = (inactiveAnimationName != string.Empty);
|
||||||
|
|
||||||
DeployAnimation = ((_deployAnimationPresent) ?
|
if (_deployAnimationPresent)
|
||||||
base.part.FindModelAnimators(deployAnimationName)[0] : null);
|
{
|
||||||
RetractAnimation = ((_retractAnimationPresent) ?
|
DeployAnimation = base.part.FindModelAnimators(deployAnimationName)[0];
|
||||||
base.part.FindModelAnimators(retractAnimationName)[0] : null);
|
if (DeployAnimation == null)
|
||||||
ActiveAnimation = ((_activeAnimationPresent) ?
|
{
|
||||||
base.part.FindModelAnimators(activeAnimationName)[0] : null);
|
_deployAnimationPresent = false;
|
||||||
InactiveAnimation = ((_inactiveAnimationPresent)?
|
this.LogError($"Can't find deploy animation named {deployAnimationName}");
|
||||||
base.part.FindModelAnimators(inactiveAnimationName)[0] : null);
|
}
|
||||||
|
}
|
||||||
|
else DeployAnimation = null;
|
||||||
|
|
||||||
|
if (_retractAnimationPresent)
|
||||||
|
{
|
||||||
|
RetractAnimation = base.part.FindModelAnimators(retractAnimationName)[0];
|
||||||
|
if (RetractAnimation == null)
|
||||||
|
{
|
||||||
|
_retractAnimationPresent = false;
|
||||||
|
this.LogError($"Can't find retract animation named {retractAnimationName}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else RetractAnimation = null;
|
||||||
|
|
||||||
|
if (_activeAnimationPresent)
|
||||||
|
{
|
||||||
|
ActiveAnimation = base.part.FindModelAnimators(activeAnimationName)[0];
|
||||||
|
if (ActiveAnimation == null)
|
||||||
|
{
|
||||||
|
_activeAnimationPresent = false;
|
||||||
|
this.LogError($"Can't find active animation named {activeAnimationName}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else ActiveAnimation = null;
|
||||||
|
|
||||||
|
if (_inactiveAnimationPresent)
|
||||||
|
{
|
||||||
|
InactiveAnimation = base.part.FindModelAnimators(inactiveAnimationName)[0];
|
||||||
|
if (InactiveAnimation == null)
|
||||||
|
{
|
||||||
|
_inactiveAnimationPresent = false;
|
||||||
|
this.LogError($"Can't find inactive animation named {inactiveAnimationName}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else InactiveAnimation = null;
|
||||||
|
|
||||||
foreach (var a in base.part.FindModelAnimators()) a.Stop();
|
foreach (var a in base.part.FindModelAnimators()) a.Stop();
|
||||||
|
|
||||||
@ -116,7 +151,7 @@ namespace Restock
|
|||||||
DeployStart();
|
DeployStart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// System is inactive, but waiting for the animation to end before deploying
|
// System is inactive, but waiting for the animation to end before deploying
|
||||||
@ -176,7 +211,8 @@ namespace Restock
|
|||||||
case State.ActiveWaiting:
|
case State.ActiveWaiting:
|
||||||
if (!waitForComplete || !_activeAnimationPresent)
|
if (!waitForComplete || !_activeAnimationPresent)
|
||||||
{
|
{
|
||||||
this.LogError("Invalid state! waitForComplete not enabled or active animation not present.");
|
this.LogError(
|
||||||
|
"Invalid state! waitForComplete not enabled or active animation not present.");
|
||||||
CurrentState = State.Active;
|
CurrentState = State.Active;
|
||||||
}
|
}
|
||||||
else if (ConvertersEnabled())
|
else if (ConvertersEnabled())
|
||||||
@ -201,9 +237,19 @@ namespace Restock
|
|||||||
{
|
{
|
||||||
DeployStart();
|
DeployStart();
|
||||||
}
|
}
|
||||||
else if (!RetractAnimation.IsPlaying(retractAnimationName))
|
else if (_retractAnimationPresent)
|
||||||
{
|
{
|
||||||
RetractEnd();
|
if (!RetractAnimation.IsPlaying(retractAnimationName))
|
||||||
|
{
|
||||||
|
RetractEnd();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (_deployAnimationPresent)
|
||||||
|
{
|
||||||
|
if (!DeployAnimation.IsPlaying(deployAnimationName))
|
||||||
|
{
|
||||||
|
RetractEnd();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -220,7 +266,8 @@ namespace Restock
|
|||||||
|
|
||||||
private void DeployWait()
|
private void DeployWait()
|
||||||
{
|
{
|
||||||
if (_inactiveAnimationPresent){
|
if (_inactiveAnimationPresent)
|
||||||
|
{
|
||||||
CurrentState = State.InactiveWaiting;
|
CurrentState = State.InactiveWaiting;
|
||||||
PlayAnimation(InactiveAnimation, inactiveAnimationName, loop: false);
|
PlayAnimation(InactiveAnimation, inactiveAnimationName, loop: false);
|
||||||
}
|
}
|
||||||
@ -237,7 +284,8 @@ namespace Restock
|
|||||||
if (_retractAnimationPresent && RetractAnimation.IsPlaying(retractAnimationName))
|
if (_retractAnimationPresent && RetractAnimation.IsPlaying(retractAnimationName))
|
||||||
{
|
{
|
||||||
RetractAnimation.Stop(retractAnimationName);
|
RetractAnimation.Stop(retractAnimationName);
|
||||||
}
|
}
|
||||||
|
|
||||||
CurrentState = State.Deploying;
|
CurrentState = State.Deploying;
|
||||||
PlayAnimation(DeployAnimation, deployAnimationName, speed * deploySpeed);
|
PlayAnimation(DeployAnimation, deployAnimationName, speed * deploySpeed);
|
||||||
}
|
}
|
||||||
@ -250,7 +298,7 @@ namespace Restock
|
|||||||
private void DeployEnd()
|
private void DeployEnd()
|
||||||
{
|
{
|
||||||
CurrentState = State.Active;
|
CurrentState = State.Active;
|
||||||
|
|
||||||
if (_activeAnimationPresent)
|
if (_activeAnimationPresent)
|
||||||
{
|
{
|
||||||
PlayAnimation(ActiveAnimation, activeAnimationName, loop: true);
|
PlayAnimation(ActiveAnimation, activeAnimationName, loop: true);
|
||||||
@ -269,7 +317,7 @@ namespace Restock
|
|||||||
RetractStart();
|
RetractStart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RetractStart(float speed = 1f)
|
private void RetractStart(float speed = 1f)
|
||||||
{
|
{
|
||||||
if (_retractAnimationPresent)
|
if (_retractAnimationPresent)
|
||||||
@ -277,7 +325,8 @@ namespace Restock
|
|||||||
if (_deployAnimationPresent && DeployAnimation.IsPlaying(deployAnimationName))
|
if (_deployAnimationPresent && DeployAnimation.IsPlaying(deployAnimationName))
|
||||||
{
|
{
|
||||||
DeployAnimation.Stop(deployAnimationName);
|
DeployAnimation.Stop(deployAnimationName);
|
||||||
}
|
}
|
||||||
|
|
||||||
CurrentState = State.Retracting;
|
CurrentState = State.Retracting;
|
||||||
PlayAnimation(RetractAnimation, retractAnimationName, speed * retractSpeed);
|
PlayAnimation(RetractAnimation, retractAnimationName, speed * retractSpeed);
|
||||||
}
|
}
|
||||||
@ -295,7 +344,7 @@ namespace Restock
|
|||||||
private void RetractEnd()
|
private void RetractEnd()
|
||||||
{
|
{
|
||||||
CurrentState = State.Inactive;
|
CurrentState = State.Inactive;
|
||||||
|
|
||||||
if (_inactiveAnimationPresent)
|
if (_inactiveAnimationPresent)
|
||||||
{
|
{
|
||||||
PlayAnimation(InactiveAnimation, inactiveAnimationName, loop: true);
|
PlayAnimation(InactiveAnimation, inactiveAnimationName, loop: true);
|
||||||
@ -345,7 +394,7 @@ namespace Restock
|
|||||||
animState.wrapMode = loop ? WrapMode.Loop : WrapMode.Once;
|
animState.wrapMode = loop ? WrapMode.Loop : WrapMode.Once;
|
||||||
|
|
||||||
//if (!anim.IsPlaying(name))
|
//if (!anim.IsPlaying(name))
|
||||||
anim.Play(name);
|
anim.Play(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user