Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Class ModuleROPayload #24

Merged
merged 1 commit into from
Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions Source/ROLib/Modules/ModuelROPayload.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace ROLib
{
public class ModuleROPayload : ModuleDeployableSolarPanel
{
protected PartModule pmROTank;

public override void OnStart(StartState state)
{
base.OnStart(state);
pmROTank = part.Modules.GetModule<ModuleROTank>();
if (state == StartState.Editor && pmROTank is ModuleROTank moduleROTank)
{
if (moduleROTank?.Fields["currentCore"] is BaseField cCbf)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need the ? here since you just nullchecked it above with the is

{
cCbf.uiControlEditor.onFieldChanged += OnCoreChanged;
}
moduleROTank.enableVScale = false;
moduleROTank.Fields[nameof(moduleROTank.currentVScale)].guiActiveEditor = false;
}
}

internal void OnCoreChanged(BaseField bf, object obj)
{
UpdateAnimationAndTracking(bf);
startFSM();
}

private void UpdateAnimationAndTracking(BaseField bf)
{
FindAnimations();
panelRotationTransform = part.FindModelTransform(pivotName);
hasPivot = panelRotationTransform is Transform;
originalRotation = currentRotation = panelRotationTransform?.localRotation ?? Quaternion.identity;
}

private void FindAnimations()
{
anim = null;
if (!string.IsNullOrEmpty(animationName))
{
Animation[] animations = part.transform.ROLFindRecursive("model").GetComponentsInChildren<Animation>();
anim = animations.FirstOrDefault(x => x.GetClip(animationName) is AnimationClip);
anim ??= animations.FirstOrDefault();
}
useAnimation = anim != null;
}
}
}
1 change: 1 addition & 0 deletions Source/ROLib/ROLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<Compile Include="DebugTools\DebugDrawer.cs" />
<Compile Include="DebugTools\DrawTools.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="Modules\ModuelROPayload.cs" />
<Compile Include="Modules\ModuleROSolar.cs" />
<Compile Include="Modules\ModuleROTank_KorolevCross.cs" />
<Compile Include="Modules\ROLAnimateEngineHeat.cs" />
Expand Down