From c93e0897277dcc20244bf11400051b4b1ff2fb1e Mon Sep 17 00:00:00 2001 From: Sofie <63377159+SofieBrink@users.noreply.github.com> Date: Sat, 2 Nov 2024 23:12:59 +0100 Subject: [PATCH] MultipleDragCube fix --- .../Starliner/BCS_Centauri_CrewCapsule.cfg | 12 ++- Source/Modules/ModuleBCSAirbags.cs | 81 ++++++++++++++----- 2 files changed, 67 insertions(+), 26 deletions(-) diff --git a/GameData/BoringCrewServices/Parts/Starliner/BCS_Centauri_CrewCapsule.cfg b/GameData/BoringCrewServices/Parts/Starliner/BCS_Centauri_CrewCapsule.cfg index 9694f14..7461d10 100644 --- a/GameData/BoringCrewServices/Parts/Starliner/BCS_Centauri_CrewCapsule.cfg +++ b/GameData/BoringCrewServices/Parts/Starliner/BCS_Centauri_CrewCapsule.cfg @@ -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 { diff --git a/Source/Modules/ModuleBCSAirbags.cs b/Source/Modules/ModuleBCSAirbags.cs index 00702bb..0762959 100644 --- a/Source/Modules/ModuleBCSAirbags.cs +++ b/Source/Modules/ModuleBCSAirbags.cs @@ -3,7 +3,7 @@ namespace BoringCrewServices.Modules { - public class ModuleBCSAirbags : PartModule + public class ModuleBCSAirbags : PartModule, IMultipleDragCube { // Fields [KSPField] @@ -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; @@ -130,7 +132,6 @@ public void Deflate() Events["Deflate"].active = false; PlayAnimation(deflateAnimation, deflateAnimationNameGet, reverseDeflateAnimation ? 1 : 0, deflateAnimationEnd); - } } @@ -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; @@ -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); } } @@ -195,6 +187,56 @@ public void OnStatus(GameEvents.HostedFromToAction 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() { @@ -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; }