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

Fix density default value #358

Merged
merged 1 commit into from
Aug 31, 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
9 changes: 5 additions & 4 deletions Source/ProceduralPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class ProceduralPart : PartModule, IPartCostModifier, IPartMassModifier

[KSPField(isPersistant = true, guiActiveEditor = false, guiName = "Stringer Mass", groupName = PAWGroupName, groupDisplayName = PAWGroupDisplayName)]
[UI_FloatRange(minValue = 0f, maxValue = 1.0f, stepIncrement = 0.01f)]
public float density = 0;
public float density = -1;
public const float NominalDensity = 0.15f;
[KSPField] public float minDensity = 0f;
[KSPField] public float maxDensity = 0f;
Expand Down Expand Up @@ -78,8 +78,6 @@ public override void OnLoad(ConfigNode node)
// An existing vessel part or .craft file that has never set this value before, but not the availablePart
if (HighLogic.LoadedScene != GameScenes.LOADING && !node.HasValue(nameof(forceLegacyTextures)))
forceLegacyTextures = true;

SetPFFields();
}

public override string GetInfo()
Expand Down Expand Up @@ -159,11 +157,11 @@ public override void OnStart(StartState state)
opt.onFieldChanged = OnShapeSelectionChanged;

Fields[nameof(costDisplay)].guiActiveEditor = displayCost;
SetPFFields();

GameEvents.onVariantApplied.Add(OnVariantApplied);
GameEvents.onGameSceneSwitchRequested.Add(OnEditorExit);
}
SetPFFields();

// Done here and done in OnStartFinished in TankContentSwitcher to get ordering right
// since these get fired in reverse-add order
Expand Down Expand Up @@ -665,6 +663,9 @@ private void SetPFFields()
{
fieldDensity.guiActiveEditor = false;
}

if (density < 0f)
density = Math.Max(minDensity, 0f);
}

private void OnShipModified(ShipConstruct _)
Expand Down
Loading