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

Simplify fairing side tooling/size calculations #2377

Merged
merged 1 commit into from
Jun 6, 2024
Merged
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
52 changes: 33 additions & 19 deletions Source/RP0/Tooling/ModuleToolingPFSide.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,28 @@
protected PartModule pmFairing;
protected PartModule pmDecoupler;

protected BaseField baseRad, maxRad, cylEnd, sideThickness, inlineHeight, noseHeightRatio, hingeEnabled, fairingStaged;
protected BaseField diameterFld, heightFld, hingeEnabledFld, fairingStagedFld;
[Obsolete]
protected BaseField baseRad, maxRad, cylEnd, sideThickness, inlineHeight, noseHeightRatio;

protected bool EnsureFields()
{
if (baseRad == null)
if (fairingStagedFld == null)
{
diameterFld = pmFairing.Fields["diameter"];
heightFld = pmFairing.Fields["height"];
hingeEnabledFld = pmFairing.Fields["hingeEnabled"];
fairingStagedFld = pmDecoupler.Fields["fairingStaged"];

//TODO: legacy code, remove all those at a later date
baseRad = pmFairing.Fields["baseRad"];

Check warning on line 43 in Source/RP0/Tooling/ModuleToolingPFSide.cs

View workflow job for this annotation

GitHub Actions / build

'ModuleToolingPFSide.baseRad' is obsolete
maxRad = pmFairing.Fields["maxRad"];

Check warning on line 44 in Source/RP0/Tooling/ModuleToolingPFSide.cs

View workflow job for this annotation

GitHub Actions / build

'ModuleToolingPFSide.maxRad' is obsolete
cylEnd = pmFairing.Fields["cylEnd"];

Check warning on line 45 in Source/RP0/Tooling/ModuleToolingPFSide.cs

View workflow job for this annotation

GitHub Actions / build

'ModuleToolingPFSide.cylEnd' is obsolete
sideThickness = pmFairing.Fields["sideThickness"];

Check warning on line 46 in Source/RP0/Tooling/ModuleToolingPFSide.cs

View workflow job for this annotation

GitHub Actions / build

'ModuleToolingPFSide.sideThickness' is obsolete
inlineHeight = pmFairing.Fields["inlineHeight"];

Check warning on line 47 in Source/RP0/Tooling/ModuleToolingPFSide.cs

View workflow job for this annotation

GitHub Actions / build

'ModuleToolingPFSide.inlineHeight' is obsolete
noseHeightRatio = pmFairing.Fields["noseHeightRatio"];

Check warning on line 48 in Source/RP0/Tooling/ModuleToolingPFSide.cs

View workflow job for this annotation

GitHub Actions / build

'ModuleToolingPFSide.noseHeightRatio' is obsolete
hingeEnabled = pmFairing.Fields["hingeEnabled"];
fairingStaged = pmDecoupler.Fields["fairingStaged"];

if (baseRad == null)
if (baseRad == null && diameterFld == null)

Check warning on line 50 in Source/RP0/Tooling/ModuleToolingPFSide.cs

View workflow job for this annotation

GitHub Actions / build

'ModuleToolingPFSide.baseRad' is obsolete
{
RP0Debug.LogError($"[ModuleTooling] Could not bind to ProceduralFairingSide fields on {part}");
return false;
Expand All @@ -66,8 +72,8 @@

if (state == StartState.Editor)
{
fairingStaged.uiControlEditor.onFieldChanged += OnStateUpdated;
hingeEnabled.uiControlEditor.onFieldChanged += OnStateUpdated;
fairingStagedFld.uiControlEditor.onFieldChanged += OnStateUpdated;
hingeEnabledFld.uiControlEditor.onFieldChanged += OnStateUpdated;
UpdateToolingAndCosts();
}
}
Expand All @@ -85,16 +91,24 @@
if (!EnsureFields())
return;

float baseRadF, maxRadF, cylEndF, sideThicknessF, inlineHeightF, noseHeightRatioF;
baseRadF = baseRad.GetValue<float>(pmFairing);
maxRadF = maxRad.GetValue<float>(pmFairing);
cylEndF = cylEnd.GetValue<float>(pmFairing);
sideThicknessF = sideThickness.GetValue<float>(pmFairing);
inlineHeightF = inlineHeight.GetValue<float>(pmFairing);
noseHeightRatioF = noseHeightRatio.GetValue<float>(pmFairing);

diam = (Math.Max(baseRadF, maxRadF) + sideThicknessF) * 2f;
len = (inlineHeightF > 0) ? inlineHeightF : (noseHeightRatioF * diam / 2) + cylEndF;
if (diameterFld != null)
{
diam = diameterFld.GetValue<float>(pmFairing);
len = heightFld.GetValue<float>(pmFairing);
}
else
{
//TODO: legacy code, remove all those at a later date
float baseRadF, maxRadF, cylEndF, sideThicknessF, inlineHeightF, noseHeightRatioF;
baseRadF = baseRad.GetValue<float>(pmFairing);

Check warning on line 103 in Source/RP0/Tooling/ModuleToolingPFSide.cs

View workflow job for this annotation

GitHub Actions / build

'ModuleToolingPFSide.baseRad' is obsolete
maxRadF = maxRad.GetValue<float>(pmFairing);

Check warning on line 104 in Source/RP0/Tooling/ModuleToolingPFSide.cs

View workflow job for this annotation

GitHub Actions / build

'ModuleToolingPFSide.maxRad' is obsolete
cylEndF = cylEnd.GetValue<float>(pmFairing);

Check warning on line 105 in Source/RP0/Tooling/ModuleToolingPFSide.cs

View workflow job for this annotation

GitHub Actions / build

'ModuleToolingPFSide.cylEnd' is obsolete
sideThicknessF = sideThickness.GetValue<float>(pmFairing);
inlineHeightF = inlineHeight.GetValue<float>(pmFairing);
noseHeightRatioF = noseHeightRatio.GetValue<float>(pmFairing);
diam = (Math.Max(baseRadF, maxRadF) + sideThicknessF) * 2f;
len = (inlineHeightF > 0) ? inlineHeightF : (noseHeightRatioF * diam / 2) + cylEndF;
}
}

public void UpdateToolingAndCosts()
Expand All @@ -105,8 +119,8 @@
if (!EnsureFields())
return;

bool isDecoupled = fairingStaged.GetValue<bool>(pmDecoupler);
bool isHinged = hingeEnabled.GetValue<bool>(pmFairing);
bool isDecoupled = fairingStagedFld.GetValue<bool>(pmDecoupler);
bool isHinged = hingeEnabledFld.GetValue<bool>(pmFairing);

var toolingPrefabModule = part.partInfo.partPrefab.FindModuleImplementing<ModuleToolingPFSide>();
if (isDecoupled)
Expand Down
Loading