Skip to content

Commit

Permalink
MultipleDragCube fix
Browse files Browse the repository at this point in the history
  • Loading branch information
SofieBrink committed Nov 2, 2024
1 parent 0a8135b commit c93e089
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,11 @@ PART
CoPOffset = 0.0, 0.6, 0.0

tags = Centauri Capsule ?BCS Boring Starliner Pod
DRAG_CUBE
{
//cube = A, 4.343,0.681,1.906, 4.343,0.6805,2.326, 6.719,0.6164,1.776, 6.719,0.8342,1.004, 4.409,0.659,1.91, 4.409,0.6564,1.978, -2.384E-07,-0.02612,0, 3.627,1.697,3.303
//cube = B, 3.004,0.6734,2.47, 3.004,0.6739,2.47, 5.872,0.6304,1.377, 5.872,0.6638,0.8111, 3.065,0.6651,2.501, 3.065,0.6605,2.501, -1.192E-07,0.13,0, 3.115,1.5,2.851
cube = A, 2.409,0.6824,1.469, 2.385,0.6831,1.897, 5.483,0.624,1.38, 5.872,0.9908,0.09855, 2.453,0.6805,1.631, 2.4,0.6817,1.805, 0,0.3289,0, 2.75,1.278,2.75
cube = B, 2.409,0.6824,1.469, 2.385,0.6831,1.897, 5.483,0.624,1.38, 5.872,0.9908,0.09855, 2.453,0.6805,1.631, 2.4,0.6817,1.805, 0,0.3289,0, 2.75,1.278,2.75
}
DRAG_CUBE
{
cube = A, 4.343,0.681,1.906, 4.343,0.6805,2.326, 6.719,0.6164,1.776, 6.719,0.8342,1.004, 4.409,0.659,1.91, 4.409,0.6564,1.978, -2.384E-07,-0.02612,0, 3.627,1.697,3.303
cube = B, 3.004,0.6734,2.47, 3.004,0.6739,2.47, 5.872,0.6304,1.377, 5.872,0.6638,0.8111, 3.065,0.6651,2.501, 3.065,0.6605,2.501, -1.192E-07,0.13,0, 3.115,1.5,2.851
}

EFFECTS
{
Expand Down
81 changes: 62 additions & 19 deletions Source/Modules/ModuleBCSAirbags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace BoringCrewServices.Modules
{
public class ModuleBCSAirbags : PartModule
public class ModuleBCSAirbags : PartModule, IMultipleDragCube
{
// Fields
[KSPField]
Expand Down Expand Up @@ -47,9 +47,11 @@ public class ModuleBCSAirbags : PartModule

private AttachNode referenceNode;

private Animation deployAnimation;
[SerializeField]
public Animation deployAnimation;

private Animation deflateAnimation;
[SerializeField]
public Animation deflateAnimation;

private string deflateAnimationNameGet => string.IsNullOrEmpty(deflateAnimationName) ? deployAnimationName : deflateAnimationName;

Expand Down Expand Up @@ -130,7 +132,6 @@ public void Deflate()
Events["Deflate"].active = false;

PlayAnimation(deflateAnimation, deflateAnimationNameGet, reverseDeflateAnimation ? 1 : 0, deflateAnimationEnd);

}
}

Expand All @@ -142,21 +143,6 @@ public override void OnStart(StartState state)

GameEvents.onVesselSituationChange.Add(OnStatus);

if (string.IsNullOrEmpty(deployAnimationName)) Debug.LogError($"[{nameof(ModuleBCSAirbags)}] deployAnimationName was not set!");
else deployAnimation = part.FindModelAnimator(deployAnimationName);
if (deployAnimation == null) Debug.LogError($"[{nameof(ModuleBCSAirbags)}] Part: {part.partInfo?.name} does not have an animation named: {deployAnimationName}");

if (string.IsNullOrEmpty(deflateAnimationName))
{
#if DEBUG
Debug.Log($"[{nameof(ModuleBCSAirbags)}] deflateAnimationName was not set, using deploy animation");
#endif
deflateAnimation = deployAnimation;
}
else deflateAnimation = part.FindModelAnimator(deflateAnimationName);
// this will print something empty in the case that its supposed to use the deploy animation and that doesn't exist, but there will already be a correct error above.
if (deflateAnimation == null) Debug.LogError($"[{nameof(ModuleBCSAirbags)}] Part: {part.partInfo?.name} does not have an animation named: {deflateAnimationName}");

// possibly needs to be a KSPField if there's ever multiple anims playing simultaneously?
deployAnimation[deployAnimationName].layer = 0;
deflateAnimation[deflateAnimationNameGet].layer = 0;
Expand All @@ -167,9 +153,15 @@ public override void OnStart(StartState state)
if (airbagState == AirbagState.Deployed)
{
deployAnimation[deployAnimationName].normalizedTime = deployAnimationEnd;
SetDragState(1f);
}
else if (airbagState == AirbagState.Deflated) {
deflateAnimation[deflateAnimationNameGet].normalizedTime = deflateAnimationEnd;
SetDragState(1f);
}
else
{
SetDragState(0f);
}
}

Expand All @@ -195,6 +187,56 @@ public void OnStatus(GameEvents.HostedFromToAction<Vessel, Vessel.Situations> da
}
}

public override void OnLoad(ConfigNode node)
{
base.OnLoad(node);
if (HighLogic.LoadedScene == GameScenes.LOADING) {
if (string.IsNullOrEmpty(deployAnimationName)) Debug.LogError($"[{nameof(ModuleBCSAirbags)}] deployAnimationName was not set!");
else deployAnimation = part.FindModelAnimator(deployAnimationName);
if (deployAnimation == null) Debug.LogError($"[{nameof(ModuleBCSAirbags)}] Part: {part.partInfo?.name} does not have an animation named: {deployAnimationName}");

if (string.IsNullOrEmpty(deflateAnimationName))
{
#if DEBUG
Debug.Log($"[{nameof(ModuleBCSAirbags)}] deflateAnimationName was not set, using deploy animation");
#endif
deflateAnimation = deployAnimation;
}
else deflateAnimation = part.FindModelAnimator(deflateAnimationName);
// this will print something empty in the case that its supposed to use the deploy animation and that doesn't exist, but there will already be a correct error above.
if (deflateAnimation == null) Debug.LogError($"[{nameof(ModuleBCSAirbags)}] Part: {part.partInfo?.name} does not have an animation named: {deflateAnimationName}");
}
}

public string[] GetDragCubeNames()
{
return new string[2] { "A", "B" };
}

public bool UsesProceduralDragCubes() => false;
public bool IsMultipleCubesActive => true;

public void AssumeDragCubePosition(string name)
{
if (!(name == "A"))
{
if (name == "B")
{
deployAnimation[deployAnimationName].normalizedTime = reverseDeployAnimation ? 1 : 0;
}
}
else
{
deployAnimation[deployAnimationName].normalizedTime = deployAnimationEnd;
}
}

private void SetDragState(float b)
{
part.DragCubes.SetCubeWeight("A", b);
part.DragCubes.SetCubeWeight("B", 1f - b);
}

// Module Methods
private void SetupPartIcon()
{
Expand Down Expand Up @@ -302,6 +344,7 @@ public IEnumerator AnimationCoroutine(Animation anim, string animationName, floa

while (((isForward && anim[animationName].normalizedTime < end) || (!isForward && anim[animationName].normalizedTime > end)) && anim.isPlaying)
{
if (animationName == deployAnimationName && deflateAnimationName != null) SetDragState(anim[animationName].normalizedTime);
yield return null;
}

Expand Down

0 comments on commit c93e089

Please sign in to comment.