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 issues with density persistence #57

Merged
merged 1 commit into from
Aug 11, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ PART
usePreset = true
shapePreset = Egg

density = 0.1
decouplerCostMult = 1
costPerTonne = 5000
specificBreakingForce = 2000
Expand Down
11 changes: 9 additions & 2 deletions Source/ProceduralFairings/FairingSide.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ namespace Keramzit
{
public class ProceduralFairingSide : PartModule, IPartCostModifier, IPartMassModifier
{
private static readonly Dictionary<string, FairingSideShapePreset> AllPresets = new Dictionary<string, FairingSideShapePreset>();
internal ColliderPool colliderPool;

[KSPField] public float minBaseConeAngle = 20;
[KSPField] public float colliderShaveAngle = 5;
[KSPField] public Vector4 baseConeShape = new Vector4(0, 0, 0, 0);
Expand Down Expand Up @@ -52,7 +54,7 @@ public class ProceduralFairingSide : PartModule, IPartCostModifier, IPartMassMod

[KSPField(isPersistant = true, guiActiveEditor = true, guiName = "Density", groupName = PFUtils.PAWGroup, groupDisplayName = PFUtils.PAWName)]
[UI_FloatRange(minValue = 0.01f, maxValue = 1.0f, stepIncrement = 0.01f)]
public float density = 0.2f;
public float density = -1f;

[KSPField] public float minDensity = 0.01f;
[KSPField] public float maxDensity = 1.0f;
Expand Down Expand Up @@ -136,6 +138,7 @@ public class ProceduralFairingSide : PartModule, IPartCostModifier, IPartMassMod
[KSPField] public float hingeCostBase = 0; // Flat additional cost when hinge is enabled
[KSPField] public float hingeMassMult = 1; // Mass multiplier
[KSPField] public float hingeMassBase = 0.0001f; // Flat additional mass (0.001 = 1kg)

public ModifierChangeWhen GetModuleCostChangeWhen() => ModifierChangeWhen.FIXED;
public ModifierChangeWhen GetModuleMassChangeWhen() => ModifierChangeWhen.FIXED;
public float GetModuleCost(float defcost, ModifierStagingSituation sit) => ApplyModuleCostModifier(fairingMass * costPerTonne) - defcost;
Expand All @@ -148,7 +151,6 @@ public class ProceduralFairingSide : PartModule, IPartCostModifier, IPartMassMod
private float totalCostBase => (DecouplerEnabled ? decouplerCostBase : 0) + (hingeEnabled ? hingeCostBase : 0);
private float totalMassMult => (DecouplerEnabled ? decouplerMassMult : 1) * (hingeEnabled ? hingeMassMult : 1);
private float totalMassBase => (DecouplerEnabled ? decouplerMassBase : 0) + (hingeEnabled ? hingeMassBase : 0);
private static readonly Dictionary<string, FairingSideShapePreset> AllPresets = new Dictionary<string, FairingSideShapePreset>();

[KSPEvent(active = true, guiActiveEditor = true, groupName = PFUtils.PAWGroup, guiName = "Toggle Open/Closed")]
public void ToggleOpenClosed()
Expand Down Expand Up @@ -199,6 +201,11 @@ public override void OnLoad(ConfigNode node)

public override void OnStart(StartState state)
{
if (HighLogic.LoadedSceneIsEditor && density == -1f)
{
density = minDensity;
}

HingeAnimation = part.FindModuleImplementing<ModuleAnimateGeneric>();

colliderPool = new ColliderPool(part.FindModelComponent<MeshFilter>("model"));
Expand Down
Loading